Skip to content

Commit

Permalink
[fix] 다이어리에 따른 좋아요 체킹 조건 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryeolee committed Aug 15, 2024
1 parent f429d34 commit 703745a
Showing 1 changed file with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,37 @@ public interface DiaryRepository extends JpaRepository<Diary, Long> {
@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<Diary> 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<DiaryComment> 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<SortedMyLikeDiary> 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<SortedMyLikeDiary> 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<Diary> findDiaryByToday(@Param("myVeggie") MyVeggie myVeggie);






}

0 comments on commit 703745a

Please sign in to comment.