From 703745ae6fc6958b8350cd05f774cd070663b6d4 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 16 Aug 2024 02:19:55 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EB=8B=A4=EC=9D=B4=EC=96=B4=EB=A6=AC?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EC=B2=B4=ED=82=B9=20=EC=A1=B0=EA=B1=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/DiaryRepository.java | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) 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 e62aca5..ba0a67b 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 @@ -22,56 +22,37 @@ public interface DiaryRepository extends JpaRepository { @Modifying @Query("DELETE FROM diary_like AS dl WHERE dl.diary = :diary AND dl.user = :user") void deleteDiaryLikeByIdAndUser(@Param("user") User user, @Param("diary") Diary diary); - @Modifying @Query("DELETE FROM diary AS d WHERE d.id = :diaryId") void deleteDiaryById(@Param("diaryId") Long diaryId); - - - - @Query("SELECT d FROM diary AS d WHERE d.id = :diaryId AND d.myVeggie.id = :myVeggieId") Optional findDiaryByIdAndMyVeggieId(@Param("diaryId") Long diaryId, @Param("myVeggieId") Long myVeggieId); @Query("SELECT dl FROM diary_like AS dl WHERE dl.diary = :diary AND dl.user = :user") DiaryLike findDiaryLikeByIdAndUser(@Param("user") User user, @Param("diary") Diary diary); - - @Query("SELECT dc FROM diary_comment AS dc " + "JOIN FETCH dc.diary AS d " + "JOIN FETCH d.myVeggie AS mv " + "JOIN FETCH mv.user " + "WHERE d.id = :diaryId") List findDiaryById(@Param("diaryId") Long diaryId); - - @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + "FROM diary AS d " + "JOIN FETCH d.myVeggie AS mv " + - "JOIN FETCH mv.user " + - "LEFT JOIN diary_comment AS dc ON dc.id = d.id "+ - "LEFT JOIN diary_like AS dl ON dl.id = d.id " + + "LEFT JOIN diary_like AS dl ON dl.diary.id = d.id AND dl.user.id = :userId " + "WHERE d.farmClub.id = :farmClubId AND d.isOpen = true " ) List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId, @Param("userId") Long userId); - @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + "FROM diary AS d " + "JOIN FETCH d.myVeggie AS mv " + - "JOIN FETCH mv.user " + "LEFT JOIN diary_like AS dl ON dl.diary.id = d.id AND dl.user.id = :userId " + "WHERE d.myVeggie = :myVeggie " + - "ORDER BY d.createdDate DESC") + "ORDER BY d.createdDate DESC " + ) List findDiariesByMyVeggie(@Param("myVeggie") MyVeggie myVeggie, @Param("userId") Long userId); - @Query("SELECT d FROM diary AS d WHERE d.myVeggie = :myVeggie AND FUNCTION('DATE', d.createdDate) = CURRENT_DATE") List findDiaryByToday(@Param("myVeggie") MyVeggie myVeggie); - - - - - - }