Skip to content

Commit

Permalink
Merge pull request #129 from Mojacknong/fix_128/일기,-일기-댓글-조회
Browse files Browse the repository at this point in the history
Fix 128/일기, 일기 댓글 조회
  • Loading branch information
Ryeolee authored Sep 14, 2024
2 parents 3b3c373 + df43b51 commit c27af1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ public interface DiaryRepository extends JpaRepository<Diary, Long> {
"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);
"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<DiaryComment> 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<SortedMyLikeDiary> findDiaryByFarmClub(@Param("farmClubId") Long farmClubId, @Param("userId") Long userId);

@Query("SELECT new com.modernfarmer.farmusspring.domain.myveggiegarden.dto.SortedMyLikeDiary(d, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public void verifyMyVeggie(Optional<MyVeggie> myVeggie){
@Transactional
public List<FarmClubDiary> findDiaryAccordingToFarmClub(Long farmClubId, Long userId) {
List<SortedMyLikeDiary> diaryList = diaryRepository.findDiaryByFarmClub(farmClubId, userId);
List<FarmClubDiary> proccessData = proccessFarmClubData(diaryList);
return proccessData;
return proccessFarmClubData(diaryList);
}
private List<FarmClubDiary> proccessFarmClubData(List<SortedMyLikeDiary> diaryAllList){
return diaryAllList.stream().map(allDiary -> {
Expand Down Expand Up @@ -195,7 +194,7 @@ public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(MyVeggie myVeggie)
}
@Transactional
public DiaryInteractionsDto selectComment(Long userId, Long diaryId) {
List<DiaryComment> diaryCommentList = diaryRepository.findDiaryById(diaryId);
List<DiaryComment> diaryCommentList = diaryRepository.findDiaryByIdWithUserId(diaryId, userId);
List<DiaryCommentContent> diaryCommentContent = DiaryCommentContent.processData(diaryCommentList, userId);
int likeCount = diaryLikeRepository.findDiaryLikeCountById(diaryId);
int commentCount = diaryCommentRepository.findDiaryCommentCountById(diaryId);
Expand Down

0 comments on commit c27af1f

Please sign in to comment.