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 14519c6..8689bd1 100644 --- a/src/main/java/com/diareat/diareat/food/service/FoodService.java +++ b/src/main/java/com/diareat/diareat/food/service/FoodService.java @@ -142,7 +142,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByDate(Long userId, LocalDat validateUser(userId); List foodList = foodRepository.findAllByUserIdAndDateOrderByAddedTimeAsc(userId, date); log.info(date.toString() + "기준 "+ userId + "의 음식들의 영양성분별 총합 조회 완료"); - return calculateNutritionSumAndRatio(userId, foodList, date, 1); + return calculateNutritionSumAndRatio(userId, foodList, date, 1, foodList.isEmpty()); } @Transactional(readOnly = true) @@ -151,7 +151,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByWeek(Long userId, int year validateUser(userId); LocalDate endDate = LocalDate.of(year, month, day); List foodList = foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(userId, endDate.minusWeeks(1), endDate); - return calculateNutritionSumAndRatio(userId, foodList, endDate, 7); + return calculateNutritionSumAndRatio(userId, foodList, endDate, 7, foodList.isEmpty()); } @Transactional(readOnly = true) @@ -161,7 +161,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByMonth(Long userId, int yea LocalDate endDate = LocalDate.of(year, month, day); List foodList = foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(userId, endDate.minusMonths(1), endDate); - return calculateNutritionSumAndRatio(userId, foodList, endDate, 30); + return calculateNutritionSumAndRatio(userId, foodList, endDate, 30, foodList.isEmpty()); } @Transactional(readOnly = true) @@ -386,7 +386,8 @@ private ResponseRankUserDto calculateUserScoreThisWeek(User targetUser, LocalDat return ResponseRankUserDto.of(targetUser.getId(), targetUser.getName(), targetUser.getImage(), kcalScore, carbohydrateScore, proteinScore, fatScore, totalScore); } - private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId, List foodList, LocalDate checkDate, int nutritionSumType) { + private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId, List foodList, LocalDate checkDate, int nutritionSumType, + boolean isEmpty) { User targetUser = getUserById(userId); int totalKcal = 0; int totalCarbohydrate = 0; @@ -408,7 +409,7 @@ private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId, return ResponseNutritionSumByDateDto.of(userId, checkDate, nutritionSumType, totalKcal, totalCarbohydrate, totalProtein, totalFat, ratioKcal, - ratioCarbohydrate, ratioProtein, ratioFat, targetUser.getBaseNutrition()); + ratioCarbohydrate, ratioProtein, ratioFat, targetUser.getBaseNutrition(), isEmpty); } private void validateUser(Long userId) {