Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 128/일기, 일기 댓글 조회 #129

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading