Skip to content

Commit

Permalink
[fix] like count가 사라짐에 따른 에러 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
ehyeok9 committed Nov 25, 2024
1 parent c8d74d6 commit 375ec5e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static ReviewResponse toDto(ArtReview review, ArtReviewLike reviewLike) {
.date(review.getCreateDate().toString())
.date(review.getCreateDate().format(DateTimeFormatter.ISO_LOCAL_DATE))
.isThumbed(reviewLike != null && reviewLike.getUser() != null)
.thumbsUpCnt(review.getLikeCount())
.thumbsUpCnt(review.getReviewLikes().size())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ public interface ReviewRepository extends JpaRepository<ArtReview, Long> {
@Query("select ar from ArtReview ar left join ar.reviewLikes arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.createDate desc")
Optional<List<ArtReview>> findAllByArtOrderByCreateDateDesc(Long artId, Long userId);

@Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.likeCount desc")
Optional<List<Object[]>> findAllByArtOrderByLikeCountDesc(Long artId, Long userId);
// @Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.likeCount desc")
// Optional<List<Object[]>> findAllByArtOrderByLikeCountDesc(Long artId, Long userId);

// 최신순 리뷰 목록 조회
@Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.user.id = :userId order by ar.createDate desc")
List<Object[]> findAllByUserOrderByCreateDateDesc(Long userId);

// 인기순 리뷰 목록 조회
@Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.user.id = :userId order by ar.likeCount desc")
List<Object[]> findAllByUserOrderByLikeCountDesc(Long userId);
@Query("select ar from ArtReview ar left join ar.reviewLikes arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.likeCount desc")
Optional<List<ArtReview>> findAllByArtOrderByLikeCountDesc(Long artId, Long userId);
// @Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.user.id = :userId order by ar.likeCount desc")
// List<Object[]> findAllByUserOrderByLikeCountDesc(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public AllReviewResponse getArtReview(long artId, long userId, String creteria)
userRepository.findById(userId).orElseThrow(() -> new CNotFoundException(userId + "은(는) 존재하지 않는 사용자입니다."));

List<ArtReview> result;
// if(creteria.equals("like")) {
// result = reviewRepository.findAllByArtOrderByLikeCountDesc(artId, userId);
// }
if(creteria.equals("date")){
result = reviewRepository.findAllByArtOrderByCreateDateDesc(artId, userId);
if(creteria.equals("like")) {
result = reviewRepository.findAllByArtOrderByCreateDateDesc(artId, userId).orElse(new ArrayList<>());
}
else if(creteria.equals("date")){
result = reviewRepository.findAllByArtOrderByCreateDateDesc(artId, userId).orElse(new ArrayList<>());
}
else {
throw new CBadRequestException("정렬 조건이 잘못되었습니다. 다시 요청해주세요.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ public List<ReviewResponse> getMyReview(User user, String creteria) {
List<Object[]> reviews;
if (sortType == Infos.ReviewSortType.LATEST) {
reviews = reviewRepository.findAllByUserOrderByCreateDateDesc(user.getId());
} else if (sortType == Infos.ReviewSortType.POPULAR) {
reviews = reviewRepository.findAllByUserOrderByLikeCountDesc(user.getId());
} else {
}
// else if (sortType == Infos.ReviewSortType.POPULAR) {
// reviews = reviewRepository.findAllByUserOrderByLikeCountDesc(user.getId());
// }
else {
throw new IllegalArgumentException("지원되지 않는 정렬 기준입니다.");
}

Expand Down

0 comments on commit 375ec5e

Please sign in to comment.