From 0ade9d94eefb56916590bcda698237010108e848 Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Tue, 28 Nov 2023 21:22:34 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:recycle:=20refactor:=20LocalTime=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=EB=A5=BC=20int=20=ED=98=95=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B6=84=ED=95=B4=20(#125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diareat/diareat/food/dto/ResponseFoodDto.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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()); } } From 2cd8eacb0389b905b8afd5613c5ca134b3b6ca68 Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Tue, 28 Nov 2023 21:23:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:bug:=20fix:=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=20=ED=8F=AC=ED=95=A8=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=9D=8C=EC=8B=9D=20=EC=A0=95=EB=B3=B4=20=EC=A3=BC=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diareat/diareat/food/service/FoodService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()); From 2a9ae51019b5519177531ff30be36f6153a2f408 Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Tue, 28 Nov 2023 21:23:41 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test:=20DTO=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95=20(#125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diareat/controller/FoodControllerTest.java | 2 +- .../com/diareat/diareat/service/FoodServiceTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) 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)); }