From 7a3f003d1db92482e7ba037755eeb0cc2388107a Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Sun, 12 Nov 2023 14:10:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:bug:=20fix:=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=9D=98=20=EC=B9=BC=EB=9F=BC=20=EB=AA=85=EA=B3=BC=20=EC=A7=81?= =?UTF-8?q?=EC=A0=91=20=EB=A7=A4=ED=95=91=20(#74)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/diareat/diareat/food/domain/Food.java | 1 + .../diareat/diareat/food/service/FoodService.java | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) 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 e230619..a8166c6 100644 --- a/src/main/java/com/diareat/diareat/food/domain/Food.java +++ b/src/main/java/com/diareat/diareat/food/domain/Food.java @@ -32,6 +32,7 @@ public class Food { private LocalDate date; + @Column(name = "added_time") //테이블과 매핑 private LocalDateTime addedTime; //클라이언트에서 추가하도록 요청 보낸 timestamp private BaseNutrition baseNutrition; 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 3a5843c..9f8961b 100644 --- a/src/main/java/com/diareat/diareat/food/service/FoodService.java +++ b/src/main/java/com/diareat/diareat/food/service/FoodService.java @@ -52,7 +52,7 @@ public Long saveFood(CreateFoodDto createFoodDto) { @Transactional(readOnly = true) public List getFoodListByDate(Long userId, LocalDate date){ validateUser(userId); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDate(userId, date, sort); return foodList.stream() .map(food -> ResponseFoodDto.of(food.getId(), food.getUser().getId(), food.getName(), food.getBaseNutrition(), food.isFavorite())).collect(Collectors.toList()); @@ -119,7 +119,7 @@ public void deleteFavoriteFood(Long favoriteFoodId, Long userId) { // 유저의 특정 날짜에 먹은 음식들의 영양성분별 총합 조회 (섭취영양소/기준영양소 및 비율까지 계산해서 반환, dto 구체적 협의 필요) public ResponseNutritionSumByDateDto getNutritionSumByDate(Long userId, LocalDate date) { validateUser(userId); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDate(userId, date, sort); return calculateNutritionSumAndRatio(userId, foodList, date, 1); } @@ -129,7 +129,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByDate(Long userId, LocalDat public ResponseNutritionSumByDateDto getNutritionSumByWeek(Long userId) { validateUser(userId); LocalDate endDate = LocalDate.now(); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusWeeks(1), endDate, sort); return calculateNutritionSumAndRatio(userId, foodList, endDate, 7); @@ -140,7 +140,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByWeek(Long userId) { public ResponseNutritionSumByDateDto getNutritionSumByMonth(Long userId) { validateUser(userId); LocalDate endDate = LocalDate.now(); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusMonths(1), endDate, sort); return calculateNutritionSumAndRatio(userId, foodList, endDate, 30); @@ -151,7 +151,7 @@ public ResponseNutritionSumByDateDto getNutritionSumByMonth(Long userId) { public ResponseFoodRankDto getBestFoodByWeek(Long userId) { validateUser(userId); LocalDate endDate = LocalDate.now(); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusWeeks(1), endDate, sort); List top3Foods = foodList.stream() @@ -174,7 +174,7 @@ public ResponseFoodRankDto getBestFoodByWeek(Long userId) { public ResponseFoodRankDto getWorstFoodByWeek(Long userId) { validateUser(userId); LocalDate endDate = LocalDate.now(); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDateBetween(userId, endDate.minusWeeks(1), endDate, sort); List worst3Foods = foodList.stream() @@ -402,7 +402,7 @@ private void validateFavoriteFood(Long favoriteFoodId, Long userId) { // 1주일동안 먹은 음식들의 영양성분 총합을 요일을 Key로 한 Map을 통해 반환 private HashMap> getNutritionSumByDateMap(Long userId, LocalDate startDate, LocalDate endDate) { HashMap> maps = new HashMap<>(); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time"); List foodList = foodRepository.findAllByUserIdAndDateBetween(userId, startDate, endDate, sort); for (Food food : foodList) { if (maps.containsKey(food.getDate())) { From 25d7bddbb20d36f766ea274540342c2d91e9025e Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Sun, 12 Nov 2023 14:14:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:bug:=20fix:=20test=EC=9D=98=20Sort=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#74)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/diareat/diareat/service/FoodServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/diareat/diareat/service/FoodServiceTest.java b/src/test/java/com/diareat/diareat/service/FoodServiceTest.java index f1a6d0d..9316536 100644 --- a/src/test/java/com/diareat/diareat/service/FoodServiceTest.java +++ b/src/test/java/com/diareat/diareat/service/FoodServiceTest.java @@ -425,7 +425,7 @@ void testGetAnalysisOfUser(){ List foodListOfWeek = List.of(food1,food1_1, food2, food3); List foodListOfMonth = List.of(food1, food1_1,food2, food3, food4, food5); - Sort sort = Sort.by(Sort.Direction.DESC, "addedTime"); + Sort sort = Sort.by(Sort.Direction.DESC, "added_time");