diff --git a/backend/src/main/java/com/example/todoapp/controller/RecipesController.java b/backend/src/main/java/com/example/todoapp/controller/RecipesController.java index 45702a3..b2f97ab 100644 --- a/backend/src/main/java/com/example/todoapp/controller/RecipesController.java +++ b/backend/src/main/java/com/example/todoapp/controller/RecipesController.java @@ -22,7 +22,13 @@ import com.example.todoapp.service.RecipeService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; - +/** + * 料理レシピ管理のコントローラー + *

+ * このコントローラーはレシピの取得、作成、更新、削除などの + * エンドポイントを提供します。すべてのエンドポイントは認証が必要です。 + *

+ */ @RestController @RequestMapping("/recipes") public class RecipesController { @@ -30,6 +36,12 @@ public class RecipesController { @Autowired private RecipeService recipeService; + /** + * 新しいレシピを作成する + * + * @param dto 作成するレシピの情報 + * @return 作成結果(recipeIdとメッセージを含む) + */ @PostMapping("/add") public ResponseEntity> addRecipe(@RequestBody RecipeRequestDTO dto) { Recipes createAllReipes = recipeService.addRecipe(dto); @@ -42,6 +54,12 @@ public class RecipesController { return ResponseEntity.ok(response); } + /** + * すべてのレシピを取得する + * + * @param authentication 認証情報 + * @return レシピ情報リスト + */ @GetMapping("/getAll") public ResponseEntity> getRecipe(Authentication authentication) { List recipes = recipeService.getAllRecipes(); @@ -73,6 +91,12 @@ public class RecipesController { return ResponseEntity.ok(recipeService.getRecipeDetailsById(recipeId)); } + /** + * レシピ情報を更新する + * + * @param dto 更新するレシピの詳細情報 + * @return 更新結果(成功/失敗メッセージを含む) + */ @PutMapping("/update") public ResponseEntity> updateRecipe(@RequestBody RecipeDetailDTO dto) { Recipes recipes = recipeService.updateRecipe(dto); diff --git a/backend/src/main/java/com/example/todoapp/controller/StocksController.java b/backend/src/main/java/com/example/todoapp/controller/StocksController.java index b2866c5..5c59213 100644 --- a/backend/src/main/java/com/example/todoapp/controller/StocksController.java +++ b/backend/src/main/java/com/example/todoapp/controller/StocksController.java @@ -1,7 +1,7 @@ package com.example.todoapp.controller; -import com.example.todoapp.dto.DeleteStockRequest; -import com.example.todoapp.dto.StockDTOResponse; +import com.example.todoapp.dto.DeleteStockRequestDTO; +import com.example.todoapp.dto.StockResponseDTO; import com.example.todoapp.dto.StockDTO; import com.example.todoapp.model.Stocks; import com.example.todoapp.model.User; @@ -43,11 +43,11 @@ public class StocksController { * @return ユーザーの在庫リスト */ @GetMapping("/get") - public ResponseEntity> getAllStocks(Authentication authentication) { + public ResponseEntity> getAllStocks(Authentication authentication) { List stocks = stockService.getALLStocksByUser(authentication.getName()); // エンティティからDTOへの変換 - List stockDTOs = stocks.stream() - .map(StockDTOResponse::fromEntity) + List stockDTOs = stocks.stream() + .map(StockResponseDTO::fromEntity) .collect(Collectors.toList()); return ResponseEntity.ok(stockDTOs); } @@ -121,7 +121,7 @@ public class StocksController { @DeleteMapping("/delete") public ResponseEntity deleteStock( Authentication authentication, - @RequestBody DeleteStockRequest request + @RequestBody DeleteStockRequestDTO request ) { // 認証されたユーザー名を取得 diff --git a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java index 6c3f84f..1b4b919 100644 --- a/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java +++ b/backend/src/main/java/com/example/todoapp/controller/ToBuysController.java @@ -8,8 +8,8 @@ package com.example.todoapp.controller; import com.example.todoapp.dto.BuyRequestDTO; -import com.example.todoapp.dto.DeleteToBuyRequest; -import com.example.todoapp.dto.ToBuyResponse; +import com.example.todoapp.dto.DeleteToBuyRequestDTO; +import com.example.todoapp.dto.ToBuyResponseDTO; import com.example.todoapp.dto.ToBuysDTO; import com.example.todoapp.model.Stuffs; import com.example.todoapp.model.ToBuys; @@ -112,9 +112,9 @@ public class ToBuysController { List toBuysList = toBuysService.getToBuysByUser(user); // DTO形式に変換して返す - List responseList = toBuysList.stream() + List responseList = toBuysList.stream() .map(toBuy -> { - ToBuyResponse resp = new ToBuyResponse(); + ToBuyResponseDTO resp = new ToBuyResponseDTO(); Stuffs stuff = toBuy.getStuff(); resp.setTobuyId(toBuy.getTobuyId()); resp.setStuffId(stuff.getStuffId()); @@ -139,7 +139,7 @@ public class ToBuysController { */ @DeleteMapping("/delete") public ResponseEntity> deleteToBuy( - @RequestBody DeleteToBuyRequest request, + @RequestBody DeleteToBuyRequestDTO request, Authentication authentication) { int deletedCount = toBuysService.deleteToBuyById(request.getTobuyId()); diff --git a/backend/src/main/java/com/example/todoapp/dto/BuyRequestDTO.java b/backend/src/main/java/com/example/todoapp/dto/BuyRequestDTO.java index 38438f9..f0e2ba5 100644 --- a/backend/src/main/java/com/example/todoapp/dto/BuyRequestDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/BuyRequestDTO.java @@ -4,11 +4,42 @@ import java.time.LocalDate; import lombok.Data; +/** + * 購入情報更新のデータ転送オブジェクト(DTO) + *

+ * このクラスは既存の購入予定情報を更新するために使用されます。 + * 更新に必要な全情報を含みます。 + *

+ */ @Data public class BuyRequestDTO { + /** + * 購入ID + * 更新対象の購入予定を識別します + */ private Long tobuyId; + + /** + * 価格 + * 実際の購入金額を設定します + */ private int price; + + /** + * 消費期限 + * 食材の消費期限を設定します + */ private LocalDate expDate; + + /** + * 最終更新日 + * レコードの最終更新日時を保持します + */ private LocalDate lastUpdate; + + /** + * 購入日 + * 食材の実際の購入日を設定します + */ private LocalDate buyDate; } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/DeleteStockRequest.java b/backend/src/main/java/com/example/todoapp/dto/DeleteStockRequest.java deleted file mode 100644 index 7eee296..0000000 --- a/backend/src/main/java/com/example/todoapp/dto/DeleteStockRequest.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.example.todoapp.dto; - -import lombok.Data; - -@Data -public class DeleteStockRequest { - private Long stockId; -} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/DeleteStockRequestDTO.java b/backend/src/main/java/com/example/todoapp/dto/DeleteStockRequestDTO.java new file mode 100644 index 0000000..cede4a2 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/dto/DeleteStockRequestDTO.java @@ -0,0 +1,19 @@ +package com.example.todoapp.dto; + +import lombok.Data; + +/** + * 在庫削除要求のデータ転送オブジェクト(DTO) + *

+ * このクラスは在庫削除操作をサーバーに送信するために使用されます。 + * 削除対象を特定するための情報を含みます。 + *

+ */ +@Data +public class DeleteStockRequestDTO { + /** + * 在庫ID + * 削除対象の在庫を識別するためのID + */ + private Long stockId; +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java deleted file mode 100644 index 07b2a37..0000000 --- a/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.todoapp.dto; - -import lombok.Data; - -@Data -public class DeleteToBuyRequest { - private Long userId; - private Long tobuyId; -} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequestDTO.java b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequestDTO.java new file mode 100644 index 0000000..8929f08 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/dto/DeleteToBuyRequestDTO.java @@ -0,0 +1,25 @@ +package com.example.todoapp.dto; + +import lombok.Data; + +/** + * 購入予定削除要求のデータ転送オブジェクト(DTO) + *

+ * このクラスは購入予定情報の削除要求をサーバーに送信するために使用されます。 + * 削除対象を特定するための必要情報を含みます。 + *

+ */ +@Data +public class DeleteToBuyRequestDTO { + /** + * ユーザーID + * 操作対象のユーザーを識別するためのID + */ + private Long userId; + + /** + * 購入予定ID + * 削除対象の購入予定情報を識別するためのID + */ + private Long tobuyId; +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/RecipeDetailDTO.java b/backend/src/main/java/com/example/todoapp/dto/RecipeDetailDTO.java index dea793f..9702ebd 100644 --- a/backend/src/main/java/com/example/todoapp/dto/RecipeDetailDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/RecipeDetailDTO.java @@ -4,11 +4,36 @@ import java.util.List; import lombok.Data; +/** + * レシピ詳細情報のデータ転送オブジェクト(DTO) + *

+ * このクラスはレシピの詳細情報を伝送するために使用されます。 + * レシピ基本情報に加えて関連食材情報を含みます。 + *

+ */ @Data public class RecipeDetailDTO { + /** + * レシピID + * ユニークなレシピを識別するためのID + */ private Long recipeId; + + /** + * レシピ名 + * レシピの名称を表します + */ private String recipeName; + + /** + * 概要 + * レシピの簡単な説明文 + */ private String summary; + /** + * 食材リスト + * このレシピに必要な食材とその数量のリスト + */ private List stuffs; } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/RecipeRequestDTO.java b/backend/src/main/java/com/example/todoapp/dto/RecipeRequestDTO.java index 5b26b9b..9cd0a77 100644 --- a/backend/src/main/java/com/example/todoapp/dto/RecipeRequestDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/RecipeRequestDTO.java @@ -4,10 +4,36 @@ import java.util.List; import lombok.Data; +/** + * レシピ操作要求のデータ転送オブジェクト(DTO) + *

+ * このクラスはレシピ操作要求をサーバーに送信するために使用されます。 + * 新規作成および更新時の情報を含みます。 + *

+ */ @Data public class RecipeRequestDTO { + /** + * レシピID + * 新規作成時は未指定、更新時は必須 + */ private Long recipeId; + + /** + * レシピ名 + * レシピの名称を表します + */ private String recipeName; + + /** + * 概要 + * レシピの簡単な説明文 + */ private String summary; + + /** + * 食材と数量リスト + * このレシピに必要な食材とその数量のリスト + */ private List stuffAndAmountArray; } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/RecipeResponseDTO.java b/backend/src/main/java/com/example/todoapp/dto/RecipeResponseDTO.java index 2464cbc..38d69a3 100644 --- a/backend/src/main/java/com/example/todoapp/dto/RecipeResponseDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/RecipeResponseDTO.java @@ -2,10 +2,30 @@ package com.example.todoapp.dto; import lombok.Data; +/** + * レシピ情報のデータ転送オブジェクト(DTO) + *

+ * このクラスはクライアントとサーバー間で基本的なレシピ情報をやり取りするために使用されます。 + * エンティティとは異なり、必要な情報のみを含みます。 + *

+ */ @Data public class RecipeResponseDTO { + /** + * レシピID + * ユニークなレシピを識別するためのID + */ private Long recipeId; + + /** + * レシピ名 + * レシピの名称を表します + */ private String recipeName; - private String summary; + /** + * 概要 + * レシピの簡単な説明文 + */ + private String summary; } diff --git a/backend/src/main/java/com/example/todoapp/dto/StockDTOResponse.java b/backend/src/main/java/com/example/todoapp/dto/StockResponseDTO.java similarity index 91% rename from backend/src/main/java/com/example/todoapp/dto/StockDTOResponse.java rename to backend/src/main/java/com/example/todoapp/dto/StockResponseDTO.java index e2eb002..5098319 100644 --- a/backend/src/main/java/com/example/todoapp/dto/StockDTOResponse.java +++ b/backend/src/main/java/com/example/todoapp/dto/StockResponseDTO.java @@ -16,7 +16,7 @@ import java.time.LocalDate; */ @Data -public class StockDTOResponse { +public class StockResponseDTO { private Long stockId; private Long stuffId; private Long userId; @@ -34,8 +34,8 @@ public class StockDTOResponse { * @param stock 変換元の在庫エンティティ * @return 変換されたStockDTOオブジェクト */ - public static StockDTOResponse fromEntity(Stocks stock) { - StockDTOResponse dto = new StockDTOResponse(); + public static StockResponseDTO fromEntity(Stocks stock) { + StockResponseDTO dto = new StockResponseDTO(); Stuffs stuff = stock.getStuff(); dto.setStockId(stock.getStockId()); diff --git a/backend/src/main/java/com/example/todoapp/dto/StuffDetailDTO.java b/backend/src/main/java/com/example/todoapp/dto/StuffDetailDTO.java index adde9bb..bf63d6d 100644 --- a/backend/src/main/java/com/example/todoapp/dto/StuffDetailDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/StuffDetailDTO.java @@ -1,10 +1,30 @@ package com.example.todoapp.dto; import lombok.Data; - +/** + * 食材詳細情報のデータ転送オブジェクト(DTO) + *

+ * このクラスはレシピに含まれる個別食材情報を伝送するために使用されます。 + * 必要最小限の食材情報を含みます。 + *

+ */ @Data public class StuffDetailDTO { + /** + * 食材ID + * ユニークな食材を識別するためのID + */ private Long stuffId; + + /** + * 食材名 + * 食材の名称を表します + */ private String stuffName; + + /** + * 数量 + * レシピに必要な食材の量 + */ private Integer amount; } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/StuffRequestDTO.java b/backend/src/main/java/com/example/todoapp/dto/StuffRequestDTO.java index ce06291..65308fc 100644 --- a/backend/src/main/java/com/example/todoapp/dto/StuffRequestDTO.java +++ b/backend/src/main/java/com/example/todoapp/dto/StuffRequestDTO.java @@ -1,10 +1,36 @@ package com.example.todoapp.dto; import lombok.Data; +/** + * 食材操作要求のデータ転送オブジェクト(DTO) + *

+ * このクラスは食材操作要求をサーバーに送信するために使用されます。 + * 新規作成時の必須情報を含みます。 + *

+ */ @Data public class StuffRequestDTO { - private String stuffId; - private String stuffName; - private String category; - private String amount; + /** + * 食材ID + * 新規作成時は未指定 + */ + private String stuffId; + + /** + * 食材名 + * 食材の名称を表します + */ + private String stuffName; + + /** + * カテゴリ + * 食材の分類を示します + */ + private String category; + + /** + * 数量 + * 食材の保有量を示します + */ + private String amount; } \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java deleted file mode 100644 index 407ae91..0000000 --- a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.example.todoapp.dto; - -import lombok.Data; - -@Data -public class ToBuyResponse { - private Long tobuyId; - private Long stuffId; - private String stuffName; - private int amount; - private String shop; -} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/dto/ToBuyResponseDTO.java b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponseDTO.java new file mode 100644 index 0000000..e45eae5 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/dto/ToBuyResponseDTO.java @@ -0,0 +1,44 @@ +package com.example.todoapp.dto; + +import lombok.Data; + +/** + * 購入予定情報のデータ転送オブジェクト(DTO) + *

+ * このクラスは購入予定食材情報をクライアントとサーバー間でやり取りするために使用されます。 + * 必要な情報を含み、関連エンティティへの参照ではなくIDのみを保持します。 + *

+ */ +@Data +public class ToBuyResponseDTO { + + /** + * 購入ID + * 購入予定を識別するためのID + */ + private Long tobuyId; + + /** + * 食材ID + * 関連する食材のID + */ + private Long stuffId; + + /** + * 食材名 + * 購入予定の食材名称 + */ + private String stuffName; + + /** + * 数量 + * 購入予定数量 + */ + private int amount; + + /** + * 購入先 + * 購入を予定している店舗名 + */ + private String shop; +} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/repository/RecipeStuffsRepository.java b/backend/src/main/java/com/example/todoapp/repository/RecipeStuffsRepository.java deleted file mode 100644 index 000574b..0000000 --- a/backend/src/main/java/com/example/todoapp/repository/RecipeStuffsRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.example.todoapp.repository; - -import java.util.List; -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.example.todoapp.model.RecipeStuffs; - -public interface RecipeStuffsRepository extends JpaRepository { - List findByRecipesRecipeId(Long recipeId); - - - Optional findByRecipesRecipeIdAndStuffStuffId(Long recipeId, Long stuffId); -} - - - diff --git a/backend/src/main/java/com/example/todoapp/repository/RecipesRepository.java b/backend/src/main/java/com/example/todoapp/repository/RecipesRepository.java index 6151530..f651269 100644 --- a/backend/src/main/java/com/example/todoapp/repository/RecipesRepository.java +++ b/backend/src/main/java/com/example/todoapp/repository/RecipesRepository.java @@ -4,4 +4,11 @@ import org.springframework.data.jpa.repository.JpaRepository; import com.example.todoapp.model.Recipes; -public interface RecipesRepository extends JpaRepository {} +/** + * レシピエンティティのリポジトリインターフェース + *

+ * このインターフェースはレシピデータへのアクセスと操作を提供します。 + * Spring Data JPAによって自動的に実装されます。 + *

+ */ +public interface RecipesRepository extends JpaRepository {} \ No newline at end of file diff --git a/backend/src/main/java/com/example/todoapp/repository/RecipesStuffsRepository.java b/backend/src/main/java/com/example/todoapp/repository/RecipesStuffsRepository.java new file mode 100644 index 0000000..729b825 --- /dev/null +++ b/backend/src/main/java/com/example/todoapp/repository/RecipesStuffsRepository.java @@ -0,0 +1,37 @@ +package com.example.todoapp.repository; + +import java.util.List; +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.todoapp.model.RecipeStuffs; + +/** + * レシピ食材関連データのリポジトリインターフェース + *

+ * このインターフェースはレシピと食材の関連データへのアクセスを提供します。 + * Spring Data JPAによって自動的に実装されます。 + *

+ */ +public interface RecipesStuffsRepository extends JpaRepository { + /** + * レシピIDで食材情報を検索する + * + * @param recipeId 検索するレシピID + * @return 関連する食材情報リスト + */ + List findByRecipesRecipeId(Long recipeId); + + /** + * レシピIDと食材IDで関連情報を検索する + * + * @param recipeId 検索するレシピID + * @param stuffId 検索する食材ID + * @return 関連情報(存在する場合) + */ + Optional findByRecipesRecipeIdAndStuffStuffId(Long recipeId, Long stuffId); +} + + + diff --git a/backend/src/main/java/com/example/todoapp/service/RecipeService.java b/backend/src/main/java/com/example/todoapp/service/RecipeService.java index 9b50deb..2eab2b8 100644 --- a/backend/src/main/java/com/example/todoapp/service/RecipeService.java +++ b/backend/src/main/java/com/example/todoapp/service/RecipeService.java @@ -24,7 +24,7 @@ import com.example.todoapp.dto.StuffRequestDTO; import com.example.todoapp.model.RecipeStuffs; import com.example.todoapp.model.Recipes; import com.example.todoapp.model.Stuffs; -import com.example.todoapp.repository.RecipeStuffsRepository; +import com.example.todoapp.repository.RecipesStuffsRepository; import com.example.todoapp.repository.RecipesRepository; import com.example.todoapp.repository.StuffsRepository; @@ -47,7 +47,7 @@ public class RecipeService { private StuffsRepository stuffsRepository; @Autowired - private RecipeStuffsRepository recipeStuffsRepository; + private RecipesStuffsRepository recipeStuffsRepository; /** * レシピを新規登録する @@ -94,20 +94,20 @@ public class RecipeService { } /** - * 登録済のレシピを取得する + * すべてのレシピ情報を取得する * - * @param authentication 認証情報 - * @return 登録済のレシピ情報 + * @return 登録済みレシピ情報リスト */ public List getAllRecipes() { return recipesRepository.findAll(); } /** - * レシピをIDで取得する - * + * 指定されたIDのレシピ詳細情報を取得する + * * @param recipeId 検索するレシピID - * @return 検索結果のレシピ情報 + * @return レシピ詳細情報(レシピ基本情報と関連食材情報) + * @throws RuntimeException レシピが見つからない場合 */ public RecipeDetailDTO getRecipeDetailsById(Long recipeId) { Recipes recipe = recipesRepository.findById(recipeId) @@ -134,25 +134,36 @@ public class RecipeService { return dto; } - + /** + * レシピ情報を更新する + * + * @param dto 更新するレシピ詳細情報 + * @return 更新されたレシピエンティティ + * @throws RuntimeException レシピまたは材料情報が見つからない場合 + */ @Transactional public Recipes updateRecipe(RecipeDetailDTO dto) { + // IDでレシピを検索し、見つからない場合は例外をスロー Recipes recipe = recipesRepository.findById(dto.getRecipeId()) .orElseThrow(() -> new RuntimeException("レシピが見つかりません")); + // レシピ名と概要を更新 recipe.setRecipeName(dto.getRecipeName()); recipe.setSummary(dto.getSummary()); recipesRepository.save(recipe); Set incomingStuffIds = new HashSet<>(); + // 提供された材料の詳細を繰り返し処理 for (StuffDetailDTO stuffDTO : dto.getStuffs()) { if (stuffDTO.getStuffId() == null) { + // 材料IDがnullの場合、新しい材料を作成 Stuffs newStuff = new Stuffs(); newStuff.setStuffName(stuffDTO.getStuffName()); newStuff.setCategory("その他"); newStuff = stuffsRepository.save(newStuff); + // 新しいRecipeStuffsエントリを作成 RecipeStuffs rs = new RecipeStuffs(); rs.setRecipes(recipe); rs.setStuff(newStuff); @@ -161,16 +172,18 @@ public class RecipeService { incomingStuffIds.add(newStuff.getStuffId()); } else { + // 材料IDが提供されている場合、既存のRecipeStuffsエントリを検索 Optional optionalRs = recipeStuffsRepository .findByRecipesRecipeIdAndStuffStuffId(dto.getRecipeId(), stuffDTO.getStuffId()); if (optionalRs.isPresent()) { + // RecipeStuffsエントリが存在する場合、数量を更新 RecipeStuffs rs = optionalRs.get(); rs.setAmount(stuffDTO.getAmount()); recipeStuffsRepository.save(rs); incomingStuffIds.add(rs.getStuff().getStuffId()); } else { - // 可选:创建新的 RecipeStuffs + // オプション:見つからない場合、新しいRecipeStuffsエントリを作成 Stuffs existingStuff = stuffsRepository.findById(stuffDTO.getStuffId()) .orElseThrow(() -> new RuntimeException("材料が見つかりません")); @@ -184,9 +197,9 @@ public class RecipeService { } } + // 入ってきたリストにないRecipeStuffsエントリを削除 List existingStuffs = recipeStuffsRepository.findByRecipesRecipeId(dto.getRecipeId()); for (RecipeStuffs rs : existingStuffs) { - System.out.println("dddddwtestst" + rs.getStuff().getStuffId()); if (!incomingStuffIds.contains(rs.getStuff().getStuffId())) { recipeStuffsRepository.delete(rs); }