build-passed

dev-backend-tobuy
Amagasu 5 months ago
parent a86180989b
commit c0c025dc40
  1. 4
      backend/src/main/java/com/example/todoapp/controller/ToBuysController.java
  2. 2
      backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java
  3. 8
      backend/src/main/java/com/example/todoapp/dto/ToBuysDTO.java
  4. 8
      backend/src/main/java/com/example/todoapp/model/RecipeStuffs.java
  5. 4
      backend/src/main/java/com/example/todoapp/model/Recipes.java
  6. 14
      backend/src/main/java/com/example/todoapp/model/Stocks.java
  7. 4
      backend/src/main/java/com/example/todoapp/model/Stuffs.java
  8. 10
      backend/src/main/java/com/example/todoapp/model/ToBuys.java
  9. 24
      backend/src/main/java/com/example/todoapp/repository/StocksRepository.java
  10. 2
      backend/src/main/java/com/example/todoapp/repository/StuffsRepository.java
  11. 8
      backend/src/main/java/com/example/todoapp/repository/ToBuysRepository.java
  12. 16
      backend/src/main/java/com/example/todoapp/service/ToBuysService.java

@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.*;
/**
* 購入リストに関するRESTコントローラー
* <p>
* このコントローラーは購入リスト (to_buys) へのアイテム追加機能を提供します
* このコントローラーは購入リスト (toBuys) へのアイテム追加機能を提供します
* リクエストボディには ToBuyDTO 形式のデータが期待されます
* </p>
*/
@ -99,7 +99,7 @@ public class ToBuysController {
Stuffs stuff = toBuy.getStuff();
resp.setTobuyId(toBuy.getTobuyId());
resp.setStuffId(stuff.getStuffId());
resp.setStuff_name(stuff.getStuffName());
resp.setStuffName(stuff.getStuffName());
resp.setAmount(toBuy.getAmount());
resp.setShop(toBuy.getStore());
return resp;

@ -6,7 +6,7 @@ import lombok.Data;
public class ToBuyResponse {
private int tobuyId;
private Long stuffId;
private String stuff_name;
private String stuffName;
private int amount;
private String shop;
}

@ -19,9 +19,9 @@ public class ToBuysDTO {
private int price;
private int amount;
private String shop;
private String stuff_name;
private String stuffName;
private String category;
private LocalDate exp_date;
private LocalDate last_update;
private LocalDate buy_date;
private LocalDate expDate;
private LocalDate lastUpdate;
private LocalDate buyDate;
}

@ -46,8 +46,8 @@ public class RecipeStuffs {
@NotBlank
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "recipe_id",
referencedColumnName = "recipe_id",
name = "recipeId",
referencedColumnName = "recipeId",
nullable = false
)
private Recipes recipes;
@ -59,8 +59,8 @@ public class RecipeStuffs {
@NotBlank
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "stuff_id",
referencedColumnName = "stuff_id",
name = "stuffId",
referencedColumnName = "stuffId",
nullable = false
)
private Stuffs stuff;

@ -35,14 +35,14 @@ public class Recipes {
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="recipe_id")
@Column(name="recipeId")
private int recipeId ;
/**
* カテゴリ名
*/
@NotNull
@Column(name="recipe_name", unique = true, length = 255, nullable = false)
@Column(name="recipeName", unique = true, length = 255, nullable = false)
private String recipieName;
/**

@ -39,7 +39,7 @@ public class Stocks {
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="stock_id")
@Column(name="stockId")
private Long stockId ;
@ -49,8 +49,8 @@ public class Stocks {
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "stuff_id",
referencedColumnName = "stuff_id",
name = "stuffId",
referencedColumnName = "stuffId",
nullable = false
)
private Stuffs stuff;
@ -62,7 +62,7 @@ public class Stocks {
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "user_id",
name = "userId",
referencedColumnName = "id",
nullable = false
)
@ -84,18 +84,18 @@ public class Stocks {
* 購入日
*/
@Column(nullable = false)
private LocalDate buy_date;
private LocalDate buyDate;
/**
* 最後の操作時間
*/
@Column(nullable = false)
private LocalDate last_update;
private LocalDate lastUpdate;
/**
* 賞味期限
*/
@Column(nullable = false)
private LocalDate exp_date;
private LocalDate expDate;
}

@ -35,14 +35,14 @@ import lombok.NoArgsConstructor;
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "stuff_id")
@Column(name = "stuffId")
private Long stuffId;
/**
* カテゴリ名
*/
@NotNull
@Column(name = "stuff_name", unique = true, length = 255, nullable = false)
@Column(name = "stuffName", unique = true, length = 255, nullable = false)
private String stuffName;
/**

@ -28,7 +28,7 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@Entity
@Table(name = "to_buys")
@Table(name = "toBuys")
public class ToBuys {
/**
@ -36,7 +36,7 @@ public class ToBuys {
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "tobuy_id")
@Column(name = "tobuyId")
private int tobuyId ;
/**
@ -45,8 +45,8 @@ public class ToBuys {
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "stuff_id",
referencedColumnName = "stuff_id",
name = "stuffId",
referencedColumnName = "stuffId",
nullable = false
)
private Stuffs stuff;
@ -61,7 +61,7 @@ public class ToBuys {
* 多対一の関係で遅延ロードを使用
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
@JoinColumn(name = "userId", nullable = false)
private User user;
/**

@ -8,7 +8,13 @@
package com.example.todoapp.repository;
import com.example.todoapp.model.Stocks;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -24,12 +30,12 @@ import java.util.List;
@Repository
public interface StocksRepository extends JpaRepository<Stocks, Long> {
/**
* user_idから在庫一覧をstock_id順で取得する
* userIdから在庫一覧をstockId順で取得する
*
* @param user_id 検索するユーザーID
* @param userId 検索するユーザーID
* @return 在庫リスト
*/
List<Stocks> findStocksByUser_id(Long user_id);
List<Stocks> findStocksByUserId(Long userId);
/**
* 在庫情報を更新する
@ -37,14 +43,20 @@ public interface StocksRepository extends JpaRepository<Stocks, Long> {
* @param stock 編集する新たな情報が入ったstockオブジェクト
* @return 編集に成功したらtrue
*/
boolean UpdateStockByStock_id(Stocks stock);
// boolean updateStocksByStockId(Stocks stock);
//updateをクエリ作成にて実装
@Modifying
@Transactional
@Query("UPDATE Stocks s SET s.amount = :#{#stock.amount}, s.price = :#{#stock.price}, s.buyDate = :#{#stock.buyDate}, s.lastUpdate = :#{#stock.lastUpdate}, s.expDate = :#{#stock.expDate} WHERE s.stockId = :#{#stock.stockId}")
int updateStocksById(@Param("stock") Stocks stock);
/**
* 在庫リストから指定した食材を削除する
*
* @param stockId 削除する在庫
* @param userId 削除するユーザー
* @return 削除した場合true
*/
boolean DeleteStockByStock_id(int stockId, Long userId);
void deleteStocksByStockIdAndUserId(Long stockId, Long userId);
}

@ -24,6 +24,6 @@ import org.springframework.stereotype.Repository;
@Repository
public interface StuffsRepository extends JpaRepository<Stuffs, Long> {
// 材料情報を主キーで取得するメソッド(必要に応じて追加)
Stuffs findByStuffId(Long stuff_id);
Stuffs findByStuffId(Long stuffId);
}

@ -18,9 +18,9 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* to_buys テーブルへのアクセスを行うリポジトリ
* toBuys テーブルへのアクセスを行うリポジトリ
* <p>
* このクラスは to_buys テーブルに対する基本的なCRUD操作を提供します
* このクラスは toBuys テーブルに対する基本的なCRUD操作を提供します
* Spring Data JPAによって自動的に実装されます
* </p>
*/
@ -34,7 +34,7 @@ public interface ToBuysRepository extends JpaRepository<ToBuys, Integer> {
* @return 買うものリスト
*/
@Query("SELECT t FROM ToBuys t WHERE t.user.id = ?1")
List<ToBuys> findByUser(Long user_id);
List<ToBuys> findByUser(Long userId);
/**
* 指定されたユーザーIDに基づいて買うものリストを取得する
@ -45,5 +45,5 @@ public interface ToBuysRepository extends JpaRepository<ToBuys, Integer> {
*/
@Modifying
@Query("DELETE FROM ToBuys t WHERE t.user.id = :userId AND t.tobuyId = :tobuyId")
int deleteByUser_IdAndTobuyId(@Param("userId") Long userId, @Param("tobuyId") int tobuyId);
int deleteByUserIdAndTobuyId(@Param("userId") Long userId, @Param("tobuyId") int tobuyId);
}

@ -33,7 +33,7 @@ import java.util.Optional;
/**
* 購入リストのサービスクラス
* <p>
* このクラスは購入リスト (to_buys) の登録処理を提供します
* このクラスは購入リスト (toBuys) の登録処理を提供します
* 材料 (stuffs) の存在確認と新規作成ユーザー情報の取得などを行います
* </p>
*/
@ -73,7 +73,7 @@ public class ToBuysService {
if (toBuyDTO.getStuffId() == null) {
// 新しい材料を作成
stuff = new Stuffs();
stuff.setStuffName(toBuyDTO.getStuff_name());
stuff.setStuffName(toBuyDTO.getStuffName());
stuff.setCategory(toBuyDTO.getCategory());
stuff = stuffsRepository.save(stuff);
} else {
@ -112,7 +112,7 @@ public class ToBuysService {
if (toBuyDTO.getStuffId() == null) {
// 新しい材料を作成
stuffs = new Stuffs();
stuffs.setStuffName(toBuyDTO.getStuff_name());
stuffs.setStuffName(toBuyDTO.getStuffName());
stuffs.setCategory(toBuyDTO.getCategory());
stuffs = stuffsRepository.save(stuffs);
} else {
@ -124,7 +124,7 @@ public class ToBuysService {
stuffs = optionalStuffs.get();
//update
// stuffs.setStuff_name(toBuyDTO.getStuff_name());
// stuffs.setStuffName(toBuyDTO.getStuffName());
// stuffs.setCategory(toBuyDTO.getCategory());
stuffs = stuffsRepository.save(stuffs);
}
@ -160,7 +160,7 @@ public class ToBuysService {
*/
@Transactional
public int deleteToBuyByIds(Long userId, int tobuyId) {
return toBuysRepository.deleteByUser_IdAndTobuyId(userId, tobuyId);
return toBuysRepository.deleteByUserIdAndTobuyId(userId, tobuyId);
}
public Stocks buyToBuys(String username, ToBuysDTO dto) {
@ -174,9 +174,9 @@ public class ToBuysService {
stock.setUser(user);
stock.setAmount(dto.getAmount());
stock.setPrice(dto.getPrice());
stock.setLast_update(dto.getLast_update());
stock.setBuy_date(dto.getBuy_date());
stock.setExp_date(dto.getExp_date());
stock.setLastUpdate(dto.getLastUpdate());
stock.setBuyDate(dto.getBuyDate());
stock.setExpDate(dto.getExpDate());
deleteToBuyByIds(dto.getUserId(), dto.getTobuyId());
// データベースに保存
return stocksRepository.save(stock);

Loading…
Cancel
Save