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 a6c7006..a89205f 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 @@ -34,16 +34,21 @@ public interface DiaryRepository extends JpaRepository { "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); + "LEFT JOIN diary_comment_report AS dcr ON dcr.diaryComment.id = dc.id AND dcr.user.id = :userId " + + "WHERE d.id = :diaryId " + + "AND dcr.id IS NULL" + ) + List findDiaryByIdWithUserId(@Param("diaryId") Long diaryId, @Param("userId") Long userId); @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " + "CASE WHEN d.myVeggie.user.id = :userId THEN true ELSE false END, " + "CASE WHEN dl.user.id = :userId THEN true ELSE false END) " + "FROM diary AS d " + "JOIN FETCH d.myVeggie AS mv " + "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 " - ) + "LEFT JOIN diary_report AS dr ON dr.diary.id = d.id AND dr.user.id = :userId " + + "WHERE d.farmClub.id = :farmClubId AND d.isOpen = true "+ + "AND dr.id IS NULL" + ) List findDiaryByFarmClub(@Param("farmClubId") Long farmClubId, @Param("userId") Long userId); @Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " + 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 3bcdcb0..fdbc209 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 @@ -116,8 +116,7 @@ public void verifyMyVeggie(Optional myVeggie){ @Transactional public List findDiaryAccordingToFarmClub(Long farmClubId, Long userId) { List diaryList = diaryRepository.findDiaryByFarmClub(farmClubId, userId); - List proccessData = proccessFarmClubData(diaryList); - return proccessData; + return proccessFarmClubData(diaryList); } private List proccessFarmClubData(List diaryAllList){ return diaryAllList.stream().map(allDiary -> { @@ -195,7 +194,7 @@ public BaseResponseDto selectDiaryOne(MyVeggie myVeggie) } @Transactional public DiaryInteractionsDto selectComment(Long userId, Long diaryId) { - List diaryCommentList = diaryRepository.findDiaryById(diaryId); + List diaryCommentList = diaryRepository.findDiaryByIdWithUserId(diaryId, userId); List diaryCommentContent = DiaryCommentContent.processData(diaryCommentList, userId); int likeCount = diaryLikeRepository.findDiaryLikeCountById(diaryId); int commentCount = diaryCommentRepository.findDiaryCommentCountById(diaryId);