From 7dd79f34f74f4c83bcc170ebc6721f6102435aba Mon Sep 17 00:00:00 2001 From: sycuuui <102959791+sycuuui@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:19:58 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20placeReivew=20jpa=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/place/repository/PlaceReviewRepository.java | 3 ++- .../Together/domain/place/service/PlaceService.java | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/Journey/Together/domain/place/repository/PlaceReviewRepository.java b/src/main/java/Journey/Together/domain/place/repository/PlaceReviewRepository.java index 3740b90..e12d84d 100644 --- a/src/main/java/Journey/Together/domain/place/repository/PlaceReviewRepository.java +++ b/src/main/java/Journey/Together/domain/place/repository/PlaceReviewRepository.java @@ -15,7 +15,8 @@ public interface PlaceReviewRepository extends JpaRepository { PlaceReview findPlaceReviewById(Long id); - List findTop2ByPlaceAndReportIsNullOrReportFalseOrderByCreatedAtDesc(Place place); + @Query("SELECT pr FROM PlaceReview pr WHERE pr.place = :place AND (pr.report IS NULL OR pr.report = false) ORDER BY pr.createdAt DESC") + List findTop2ByPlaceAndReportIsNullOrReportFalseOrderByCreatedAtDesc(@Param("place") Place place, Pageable pageable); PlaceReview findPlaceReviewByMemberAndPlace(Member member, Place place); @Query("SELECT COUNT(pr) FROM PlaceReview pr WHERE pr.member = :member") diff --git a/src/main/java/Journey/Together/domain/place/service/PlaceService.java b/src/main/java/Journey/Together/domain/place/service/PlaceService.java index b6f17c6..05f8dff 100644 --- a/src/main/java/Journey/Together/domain/place/service/PlaceService.java +++ b/src/main/java/Journey/Together/domain/place/service/PlaceService.java @@ -82,6 +82,7 @@ public PlaceDetailRes getPlaceDetail(Member member, Long placeId){ Boolean isMark = false; Place place = getPlace(placeId); + System.out.println(place.getId()); Long myPlaceReviewId; List placeBookmarkList = placeBookmarkRepository.findAllByPlaceAndMember(place,member); @@ -90,8 +91,8 @@ public PlaceDetailRes getPlaceDetail(Member member, Long placeId){ List disability = disabilityPlaceCategoryRepository.findDisabilityCategoryIds(placeId); List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategory(placeId).stream().map(SubDisability::of).toList(); - - List placeReviews = placeReviewRepository.findTop2ByPlaceAndReportIsNullOrReportFalseOrderByCreatedAtDesc(place); + Pageable pageable = PageRequest.of(0, 2); + List placeReviews = placeReviewRepository.findTop2ByPlaceAndReportIsNullOrReportFalseOrderByCreatedAtDesc(place,pageable); if(placeReviewRepository.findPlaceReviewByMemberAndPlace(member,place) != null) { isReview = true; @@ -135,7 +136,9 @@ public PlaceDetailGuestRes getGeustPlaceDetail(Long placeId){ List disability = disabilityPlaceCategoryRepository.findDisabilityCategoryIds(placeId); List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategory(placeId).stream().map(SubDisability::of).toList(); - List placeReviews = placeReviewRepository.findTop2ByPlaceAndReportIsNullOrReportFalseOrderByCreatedAtDesc(place); + Pageable pageable = PageRequest.of(0, 2); + List placeReviews = placeReviewRepository.findTop2ByPlaceAndReportIsNullOrReportFalseOrderByCreatedAtDesc(place,pageable); + if(placeReviews.size()<0) return PlaceDetailGuestRes.of(place, placeBookmarkList.size(), disability, subDisability, null);