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 86c50c9..6c01c5b 100644 --- a/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java +++ b/src/main/java/com/diareat/diareat/food/dto/ResponseFoodDto.java @@ -19,13 +19,14 @@ public class ResponseFoodDto { private String name; private BaseNutrition baseNutrition; private boolean favoriteChecked; - private LocalTime time; + private int hour; + private int minute; - public static ResponseFoodDto of(Long foodId, Long userId, String name, BaseNutrition baseNutrition, boolean favoriteChecked, LocalTime time) { - return new ResponseFoodDto(foodId, userId, name, baseNutrition, favoriteChecked, time); + public static ResponseFoodDto of(Long foodId, Long userId, String name, BaseNutrition baseNutrition, boolean favoriteChecked, int hour, int minute) { + return new ResponseFoodDto(foodId, userId, name, baseNutrition, favoriteChecked, hour, minute); } public static ResponseFoodDto from(Food food) { - return new ResponseFoodDto(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().toLocalTime()); + return new ResponseFoodDto(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().getHour(), food.getAddedTime().getMinute()); } } 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 fbd43d7..65e64df 100644 --- a/src/main/java/com/diareat/diareat/food/service/FoodService.java +++ b/src/main/java/com/diareat/diareat/food/service/FoodService.java @@ -60,7 +60,7 @@ 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().toLocalTime())).collect(Collectors.toList()); + .map(food -> ResponseFoodDto.of(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite(), food.getAddedTime().getHour(), food.getAddedTime().getMinute())).collect(Collectors.toList()); } // 음식 정보 수정 @@ -433,7 +433,7 @@ private void validateFavoriteFood(Long favoriteFoodId, Long userId) { // 1주일동안 먹은 음식들의 영양성분 총합을 요일을 Key로 한 Map을 통해 반환 private HashMap> getNutritionSumByDateMap(Long userId, LocalDate startDate, LocalDate endDate) { HashMap> maps = new HashMap<>(); - List foodList = foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(userId, startDate, endDate); + List foodList = foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(userId, startDate.plusDays(1), endDate.plusDays(1)); for (Food food : foodList) { if (maps.containsKey(food.getDate())) { maps.get(food.getDate()).add(food.getBaseNutrition()); diff --git a/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java b/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java index 91cc946..f73b5b9 100644 --- a/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java +++ b/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java @@ -104,7 +104,7 @@ void testGetFoodListByDate() throws Exception { int mm = 12; LocalDate date = LocalDate.of(yy, mm, dd); - ResponseFoodDto food1 = ResponseFoodDto.of(testFoodId, testUserId,"test",testBaseNutrition,false, LocalTime.of(12,0,0)); + ResponseFoodDto food1 = ResponseFoodDto.of(testFoodId, testUserId,"test",testBaseNutrition,false,12,1); when(foodService.getFoodListByDate(any(Long.class), any(LocalDate.class))).thenReturn(List.of(food1)); ApiResponse> expectedResponse = ApiResponse.success(List.of(food1), ResponseCode.FOOD_READ_SUCCESS.getMessage()); diff --git a/src/test/java/com/diareat/diareat/service/FoodServiceTest.java b/src/test/java/com/diareat/diareat/service/FoodServiceTest.java index 1861410..40698f9 100644 --- a/src/test/java/com/diareat/diareat/service/FoodServiceTest.java +++ b/src/test/java/com/diareat/diareat/service/FoodServiceTest.java @@ -445,9 +445,9 @@ void testGetAnalysisOfUser(){ given(userRepository.existsById(user.getId())).willReturn(true); given(userRepository.getReferenceById(any(Long.class))).willReturn(user); - given(foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(1), fixedDate)).willReturn(foodListOfWeek); - given(foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(3).with(DayOfWeek.MONDAY), fixedDate)).willReturn(foodListOfMonth); - given(foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.with(DayOfWeek.MONDAY), fixedDate)).willReturn(foodListOfWeek); + given(foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(1).plusDays(1), fixedDate.plusDays(1))).willReturn(foodListOfWeek); + given(foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(3).with(DayOfWeek.MONDAY).plusDays(1), fixedDate.plusDays(1))).willReturn(foodListOfMonth); + given(foodRepository.findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.with(DayOfWeek.MONDAY).plusDays(1), fixedDate.plusDays(1))).willReturn(foodListOfWeek); // when @@ -466,9 +466,9 @@ void testGetAnalysisOfUser(){ assertEquals(4, calorieLastFourWeeks.size()); //한달동안의 음식 -> 5개 - verify(foodRepository, times(1)).findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(1), fixedDate); - verify(foodRepository, times(1)).findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(3).with(DayOfWeek.MONDAY), fixedDate); - verify(foodRepository, times(1)).findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.with(DayOfWeek.MONDAY), fixedDate); + verify(foodRepository, times(1)).findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(1).plusDays(1), fixedDate.plusDays(1)); + verify(foodRepository, times(1)).findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.minusWeeks(3).with(DayOfWeek.MONDAY).plusDays(1), fixedDate.plusDays(1)); + verify(foodRepository, times(1)).findAllByUserIdAndDateBetweenOrderByAddedTimeAsc(user.getId(), fixedDate.with(DayOfWeek.MONDAY).plusDays(1), fixedDate.plusDays(1)); }