diff --git a/src/main/java/com/diareat/diareat/food/domain/Food.java b/src/main/java/com/diareat/diareat/food/domain/Food.java index 13f0aac..fa9ab46 100644 --- a/src/main/java/com/diareat/diareat/food/domain/Food.java +++ b/src/main/java/com/diareat/diareat/food/domain/Food.java @@ -3,6 +3,7 @@ import com.diareat.diareat.user.domain.BaseNutrition; import com.diareat.diareat.user.domain.User; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseAnalysisDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseAnalysisDto.java index 7d94a36..8780f35 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseAnalysisDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseAnalysisDto.java @@ -1,6 +1,7 @@ package com.diareat.diareat.food.dto; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,6 +10,7 @@ import java.util.Map; @Getter +@Builder @NoArgsConstructor @AllArgsConstructor public class ResponseAnalysisDto { // 그래프 + 점수에 사용되는 DTO diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseFavoriteFoodDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseFavoriteFoodDto.java index 5e4c41f..90c0f67 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseFavoriteFoodDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseFavoriteFoodDto.java @@ -3,10 +3,12 @@ import com.diareat.diareat.food.domain.FavoriteFood; import com.diareat.diareat.user.domain.BaseNutrition; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter +@Builder @NoArgsConstructor @AllArgsConstructor public class ResponseFavoriteFoodDto { diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java index 6c01c5b..91a6878 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java @@ -3,6 +3,7 @@ import com.diareat.diareat.food.domain.Food; import com.diareat.diareat.user.domain.BaseNutrition; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,6 +11,7 @@ import java.time.LocalTime; @Getter +@Builder @AllArgsConstructor @NoArgsConstructor public class ResponseFoodDto { diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java index d54b8d0..a55a648 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodRankDto.java @@ -1,6 +1,7 @@ package com.diareat.diareat.food.dto; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,6 +9,7 @@ import java.util.List; @Getter +@Builder @NoArgsConstructor @AllArgsConstructor public class ResponseFoodRankDto { diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseNutritionSumByDateDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseNutritionSumByDateDto.java index 17e7dd3..9eb8630 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseNutritionSumByDateDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseNutritionSumByDateDto.java @@ -2,6 +2,7 @@ import com.diareat.diareat.user.domain.BaseNutrition; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,6 +10,7 @@ import java.time.LocalDate; @Getter +@Builder @NoArgsConstructor @AllArgsConstructor public class ResponseNutritionSumByDateDto implements Serializable { diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java index 7f12af0..3a5bea1 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseScoreBestWorstDto.java @@ -1,12 +1,14 @@ package com.diareat.diareat.food.dto; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import java.util.List; @Getter +@Builder @NoArgsConstructor @AllArgsConstructor public class ResponseScoreBestWorstDto { // 일기 분석 자세히보기에 사용되는 DTO diff --git a/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java b/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java index 2160e67..d3cfedb 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseSimpleFoodDto.java @@ -2,12 +2,14 @@ import com.diareat.diareat.food.domain.Food; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import java.time.LocalDate; @Getter +@Builder @NoArgsConstructor @AllArgsConstructor public class ResponseSimpleFoodDto { // Best 3 and Worst 3에 사용될 객체 diff --git a/src/main/java/com/diareat/diareat/food/service/FoodService.java b/src/main/java/com/diareat/diareat/food/service/FoodService.java index ec4dcae..fb7f21e 100644 --- a/src/main/java/com/diareat/diareat/food/service/FoodService.java +++ b/src/main/java/com/diareat/diareat/food/service/FoodService.java @@ -51,7 +51,16 @@ public List getFoodListByDate(Long userId, LocalDate date){ List foodList = foodRepository.findAllByUserIdAndDateOrderByAddedTimeAsc(userId, date); log.info(date.toString() + "의 "+ userId + "에게 조회된 음식 개수: " + foodList.size() + "개"); return foodList.stream() - .map(food -> ResponseFoodDto.of(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().getHour(), food.getAddedTime().getMinute())).collect(Collectors.toList()); + .map(food -> ResponseFoodDto.builder() + .foodId(food.getId()) + .userId(food.getUser().getId()) + .name(food.getName()) + .baseNutrition(food.getBaseNutrition()) + .favoriteChecked(food.isFavorite()) + .hour(food.getAddedTime().getHour()) + .minute(food.getAddedTime().getMinute()) + .build()) + .collect(Collectors.toList()); } // 음식 정보 수정 @@ -101,8 +110,13 @@ public List getFavoriteFoodList(Long userId){ List foodList = favoriteFoodRepository.findAllByUserId(userId); log.info(userId + "의 즐겨찾기 음식 개수: " + foodList.size() + "개 조회 완료"); return foodList.stream() - .map(favoriteFood -> ResponseFavoriteFoodDto.of(favoriteFood.getId(),favoriteFood.getName(), - favoriteFood.getBaseNutrition(), favoriteFood.getCount())).collect(Collectors.toList()); + .map(favoriteFood -> ResponseFavoriteFoodDto.builder() + .favoriteFoodId(favoriteFood.getId()) + .name(favoriteFood.getName()) + .baseNutrition(favoriteFood.getBaseNutrition()) + .count(favoriteFood.getCount()) + .build()) + .collect(Collectors.toList()); } // 즐겨찾기 음식 수정 @@ -171,10 +185,22 @@ public ResponseFoodRankDto getBestFoodByWeek(Long userId, int year, int month, i // ** Best 3 기준 논의 필요 ** List top3FoodsDtoList = top3Foods.stream() - .map(food -> ResponseSimpleFoodDto.of(food.getName(), food.getBaseNutrition().getKcal(), food.getBaseNutrition().getCarbohydrate(), - food.getBaseNutrition().getProtein(), food.getBaseNutrition().getFat(), food.getDate())).collect(Collectors.toList()); - - return ResponseFoodRankDto.of(userId, top3FoodsDtoList, endDate, true); + .map(food -> ResponseSimpleFoodDto.builder() + .name(food.getName()) + .calorie(food.getBaseNutrition().getKcal()) + .carbohydrate(food.getBaseNutrition().getCarbohydrate()) + .protein(food.getBaseNutrition().getProtein()) + .fat(food.getBaseNutrition().getFat()) + .date(food.getDate()) + .build()) + .collect(Collectors.toList()); + + return ResponseFoodRankDto.builder() + .userId(userId) + .rankFoodList(top3FoodsDtoList) + .startDate(endDate.minusWeeks(1)) + .isBest(true) + .build(); } @Transactional(readOnly = true) @@ -195,10 +221,22 @@ public ResponseFoodRankDto getWorstFoodByWeek(Long userId, int year, int month, // 우선 임시로 지방 비율을 높게 설정 List worst3FoodDtoList = worst3Foods.stream() - .map(food -> ResponseSimpleFoodDto.of(food.getName(), food.getBaseNutrition().getKcal(), food.getBaseNutrition().getCarbohydrate(), - food.getBaseNutrition().getProtein(), food.getBaseNutrition().getFat(), food.getDate())).collect(Collectors.toList()); - - return ResponseFoodRankDto.of(userId, worst3FoodDtoList, endDate, false); + .map(food -> ResponseSimpleFoodDto.builder() + .name(food.getName()) + .calorie(food.getBaseNutrition().getKcal()) + .carbohydrate(food.getBaseNutrition().getCarbohydrate()) + .protein(food.getBaseNutrition().getProtein()) + .fat(food.getBaseNutrition().getFat()) + .date(food.getDate()) + .build()) + .collect(Collectors.toList()); + + return ResponseFoodRankDto.builder() + .userId(userId) + .rankFoodList(worst3FoodDtoList) + .startDate(endDate.minusWeeks(1)) + .isBest(false) + .build(); } // 잔여 기능 구현 부분 @@ -228,7 +266,14 @@ public ResponseScoreBestWorstDto getScoreOfUserWithBestAndWorstFoods(Long userId List simpleBestFoodList = getBestFoodByWeek(userId, year, month, day).getRankFoodList(); List simpleWorstFoodList = getWorstFoodByWeek(userId, year, month, day).getRankFoodList(); - return ResponseScoreBestWorstDto.of(kcalScore, carbohydrateScore, proteinScore, fatScore, totalScore, simpleBestFoodList, simpleWorstFoodList); + return ResponseScoreBestWorstDto.builder() + .totalScore(totalScore) + .carbohydrateScore(carbohydrateScore) + .proteinScore(proteinScore) + .fatScore(fatScore) + .best(simpleBestFoodList) + .worst(simpleWorstFoodList) + .build(); } @@ -300,7 +345,17 @@ public ResponseAnalysisDto getAnalysisOfUser(Long userId, int year, int month, i totalWeekScore = Math.round(totalWeekScore * 100.0) / 100.0; - return ResponseAnalysisDto.of(totalWeekScore, calorieLastSevenDays, calorieLastFourWeek, carbohydrateLastSevenDays, carbohydrateLastFourWeek, proteinLastSevenDays, proteinLastFourWeek, fatLastSevenDays, fatLastFourWeek); + return ResponseAnalysisDto.builder() + .totalScore(totalWeekScore) + .calorieLastSevenDays(calorieLastSevenDays) + .calorieLastFourWeek(calorieLastFourWeek) + .carbohydrateLastSevenDays(carbohydrateLastSevenDays) + .carbohydrateLastFourWeek(carbohydrateLastFourWeek) + .proteinLastSevenDays(proteinLastSevenDays) + .proteinLastFourWeek(proteinLastFourWeek) + .fatLastSevenDays(fatLastSevenDays) + .fatLastFourWeek(fatLastFourWeek) + .build(); } @@ -374,7 +429,14 @@ private ResponseRankUserDto calculateUserScoreThisWeek(User targetUser, LocalDat kcalScore += calculateNutriRatioAndScore(totalKcal, targetUser.getBaseNutrition().getKcal(), 1); } totalScore = (kcalScore + carbohydrateScore + proteinScore + fatScore); - return ResponseRankUserDto.of(targetUser.getId(), targetUser.getName(), targetUser.getImage(), kcalScore, carbohydrateScore, proteinScore, fatScore, totalScore); + return ResponseRankUserDto.builder() + .userId(targetUser.getId()) + .totalScore(totalScore) + .calorieScore(kcalScore) + .carbohydrateScore(carbohydrateScore) + .proteinScore(proteinScore) + .fatScore(fatScore) + .build(); } private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId, List foodList, LocalDate checkDate, int nutritionSumType, @@ -398,9 +460,20 @@ private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId, double ratioProtein = Math.round((((double) totalProtein / (double) targetUser.getBaseNutrition().getProtein()) * 100.0) * 10.0) / 10.0; double ratioFat = Math.round((((double) totalFat / (double) targetUser.getBaseNutrition().getFat()) * 100.0) * 10.0) / 10.0; - return ResponseNutritionSumByDateDto.of(userId, checkDate, nutritionSumType, totalKcal, - totalCarbohydrate, totalProtein, totalFat, ratioKcal, - ratioCarbohydrate, ratioProtein, ratioFat, targetUser.getBaseNutrition(), isEmpty); + return ResponseNutritionSumByDateDto.builder() + .userId(userId) + .nutritionSumType(nutritionSumType) + .totalKcal(totalKcal) + .totalCarbohydrate(totalCarbohydrate) + .totalProtein(totalProtein) + .totalFat(totalFat) + .ratioKcal(ratioKcal) + .ratioCarbohydrate(ratioCarbohydrate) + .ratioProtein(ratioProtein) + .ratioFat(ratioFat) + .baseNutrition(targetUser.getBaseNutrition()) + .isEmpty(isEmpty) + .build(); } private void validateUser(Long userId) {