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 403a9d69..e9efd747 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/repository/DiaryRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/DiaryRepository.java index 6b43cfd6..68481a3d 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 @@ -46,4 +46,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/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index e34426c9..0f1dd7e3 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); }