/tobuy/addByRecipeに新しい分量パラメータを追加

feature-backend-zhang
zhang.pengcheng 4 months ago
parent 3a3296b0d2
commit 12a0d38bd9
  1. 4
      backend/src/main/java/com/example/todoapp/controller/ToBuysController.java
  2. 6
      backend/src/main/java/com/example/todoapp/service/ToBuysService.java

@ -92,7 +92,6 @@ public class ToBuysController {
}
/**
* 指定されたユーザーIDに基づいてすべての買うものリストを取得する
*
@ -186,7 +185,8 @@ public class ToBuysController {
Authentication authentication) {
Long recipeId = payload.get("recipeId");
List<ToBuyResponseDTO> responseList = toBuysService.addByRecipeId(recipeId, authentication);
Long servings = payload.get("servings");
List<ToBuyResponseDTO> responseList = toBuysService.addByRecipeId(recipeId, servings,authentication);
//shopのフィールドを削除
List<Map<String, Object>> filteredList = responseList.stream()

@ -220,7 +220,7 @@ public class ToBuysService {
* @param authentication 認証情報
* @return 追加された買うもののリスト
*/
public List<ToBuyResponseDTO> addByRecipeId(Long recipeId, Authentication authentication) {
public List<ToBuyResponseDTO> addByRecipeId(Long recipeId, Long servings,Authentication authentication) {
// ユーザー情報を取得
String username = authentication.getName();
User user = userRepository.findByUsername(username)
@ -233,7 +233,9 @@ public class ToBuysService {
for (RecipeStuffs rs : recipeStuffsList) {
Stuffs stuff = rs.getStuff();
int requiredAmount = rs.getAmount();
// 材料の数量をサービング数に基づいて計算
int requiredAmount = rs.getAmount() * (servings != null ? servings.intValue() : 1);
Optional<ToBuys> existingToBuyOpt = toBuysRepository.findByUserAndStuff(user, stuff);

Loading…
Cancel
Save