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())) { 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");