diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java index d5d57d12..9fc60d7f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java @@ -63,9 +63,7 @@ public BaseResponseDto checkTodayDiary( } @GetMapping(value = "/{myVeggieId}/one") - public BaseResponseDto selectDiaryOne( - @PathVariable("myVeggieId") Long myVeggieId - ) { + public BaseResponseDto selectDiaryOne(@PathVariable("myVeggieId") Long myVeggieId) { return myVeggieDiaryService.selectDiaryOne(MyVeggie.builder().id(myVeggieId).build()); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java index d019f8ae..2b553155 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java @@ -62,9 +62,7 @@ public BaseResponseDto checkVeggieRoutine(@Validated @RequestBody RoutineChec } @GetMapping(value = "/{myVeggieId}") - public BaseResponseDto selectMyVeggieRoutineById( - @PathVariable("myVeggieId") Long myVeggieId - ) { + public BaseResponseDto selectRoutineToday(@PathVariable("myVeggieId") Long myVeggieId) { MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); List result = myVeggieRoutineService.selectMyVeggieRoutineById(myVeggie); return BaseResponseDto.of(SuccessCode.SUCCESS, result); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java index 77087673..f4586d98 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java @@ -45,4 +45,9 @@ public interface DiaryRepository extends JpaRepository { ) List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId); + @Query("SELECT d FROM diary AS d WHERE d.myVeggie = :myVeggie AND FUNCTION('DATE', d.createdDate) = CURRENT_DATE") + List findDiaryByToday(@Param("myVeggie") MyVeggie myVeggie); + + + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java index 7a875755..28fc8837 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/RoutineRepository.java @@ -39,4 +39,7 @@ public interface RoutineRepository extends JpaRepository { "FUNCTION('YEAR', r.date) = FUNCTION('YEAR', :month) AND FUNCTION('MONTH', r.date) = FUNCTION('MONTH', :month)") List findRoutineAndRoutineAndMyVeggieByMonthWithUser(@Param("month") Date month, @Param("user") User user ); + + @Query("SELECT r FROM routine AS r WHERE r.myVeggie = :myVeggie AND r.date = CURRENT_DATE") + List findRoutineByIdAndToday(@Param("myVeggie") MyVeggie myVeggie); } \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index 73de7865..139b848d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -141,10 +141,8 @@ public void updateComment(User user, Long diaryCommentId, String content) { myVeggieRepository.updateDiaryCommentByIdAndUserId(diaryCommentId, user, content); } @Transactional - public BaseResponseDto selectDiaryOne( - MyVeggie myVeggie - ) { - List diaryList = selectDiaryByMyVeggie(myVeggie); + public BaseResponseDto selectDiaryOne(MyVeggie myVeggie) { + List diaryList = diaryRepository.findDiaryByToday(myVeggie); if(diaryList.isEmpty()) { return BaseResponseDto.of(MyVeggieGardenSuccessCode.NOT_FOUND_DIARY, null); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java index 16eb71d0..ee1fcdcd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java @@ -51,7 +51,7 @@ public void eraseRoutine(RoutineDelete routineDelete) { @Transactional public List selectMyVeggieRoutineById(MyVeggie myVeggie) { - List routineList = myVeggieRepository.findMyVeggieRoutineById(myVeggie); + List routineList = routineRepository.findRoutineByIdAndToday(myVeggie); return MyVeggieRoutine.processData(routineList); }