From cd3c8816c379695a0f6d081866f0d58c5c07e54b Mon Sep 17 00:00:00 2001 From: mmihye Date: Wed, 12 Jun 2024 17:38:30 +0900 Subject: [PATCH] =?UTF-8?q?[#76]=20feat:=20=EA=B4=80=EA=B4=91=EC=A7=80=20?= =?UTF-8?q?=EC=9E=A5=EC=95=A0=20=EC=84=B8=EB=B6=80=EC=9C=A0=ED=98=95=20?= =?UTF-8?q?=EC=84=A4=EB=AA=85=20=EC=B6=94=EA=B0=80=20&=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/PlaceDetailGuestRes.java | 4 +- .../place/dto/response/PlaceDetailRes.java | 4 +- .../place/dto/response/PlaceReviewDto.java | 7 ++++ .../place/dto/response/SubDisability.java | 12 ++++++ .../place/entity/DisabilityPlaceCategory.java | 2 + .../DisabilityPlaceCategoryRepository.java | 4 +- .../repository/PlaceReviewRepository.java | 5 ++- .../domain/place/service/PlaceService.java | 39 ++++++++++++++++--- 8 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 src/main/java/Journey/Together/domain/place/dto/response/SubDisability.java diff --git a/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailGuestRes.java b/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailGuestRes.java index 929d363..fb8a111 100644 --- a/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailGuestRes.java +++ b/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailGuestRes.java @@ -17,11 +17,11 @@ public record PlaceDetailGuestRes( Integer bookmarkNum, List disability, - List subDisability, + List subDisability, List reviewList ) { static String cat = "관광지"; - public static PlaceDetailGuestRes of(Place place, Integer bookmarkNum, List disability, List subDisability, List reviewList){ + public static PlaceDetailGuestRes of(Place place, Integer bookmarkNum, List disability, List subDisability, List reviewList){ if(place.getCategory().equals("B02")) cat = "숙소"; else if (place.getCategory().equals("A05")) diff --git a/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailRes.java b/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailRes.java index e54d7b8..9b3f73c 100644 --- a/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailRes.java +++ b/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailRes.java @@ -19,11 +19,11 @@ public record PlaceDetailRes( Integer bookmarkNum, List disability, - List subDisability, + List subDisability, List reviewList ) { static String cat = "관광지"; - public static PlaceDetailRes of(Place place, Boolean isMark, Integer bookmarkNum, List disability, List subDisability, List reviewList){ + public static PlaceDetailRes of(Place place, Boolean isMark, Integer bookmarkNum, List disability, List subDisability, List reviewList){ if(place.getCategory().equals("B02")) cat = "숙소"; else if (place.getCategory().equals("A05")) diff --git a/src/main/java/Journey/Together/domain/place/dto/response/PlaceReviewDto.java b/src/main/java/Journey/Together/domain/place/dto/response/PlaceReviewDto.java index be15da9..1754af5 100644 --- a/src/main/java/Journey/Together/domain/place/dto/response/PlaceReviewDto.java +++ b/src/main/java/Journey/Together/domain/place/dto/response/PlaceReviewDto.java @@ -1,5 +1,7 @@ package Journey.Together.domain.place.dto.response; +import Journey.Together.domain.place.entity.PlaceReview; + import java.time.LocalDate; import java.time.LocalDateTime; @@ -11,4 +13,9 @@ public record PlaceReviewDto( String reviewImg, Float grade, LocalDate date) { + + public static PlaceReviewDto of(PlaceReview placeReview, String profileImg, String img){ + return new PlaceReviewDto(placeReview.getId(), placeReview.getMember().getNickname(), profileImg, + placeReview.getContent(), img, placeReview.getGrade(), placeReview.getDate()); + } } diff --git a/src/main/java/Journey/Together/domain/place/dto/response/SubDisability.java b/src/main/java/Journey/Together/domain/place/dto/response/SubDisability.java new file mode 100644 index 0000000..425785d --- /dev/null +++ b/src/main/java/Journey/Together/domain/place/dto/response/SubDisability.java @@ -0,0 +1,12 @@ +package Journey.Together.domain.place.dto.response; + +import Journey.Together.domain.place.entity.DisabilityPlaceCategory; + +public record SubDisability( + String subDisabilityName, + String description +) { + public static SubDisability of(DisabilityPlaceCategory disabilityPlaceCategory){ + return new SubDisability(disabilityPlaceCategory.getSubCategory().getSubname(), disabilityPlaceCategory.getDescription()); + } +} diff --git a/src/main/java/Journey/Together/domain/place/entity/DisabilityPlaceCategory.java b/src/main/java/Journey/Together/domain/place/entity/DisabilityPlaceCategory.java index a5e0094..65b5397 100644 --- a/src/main/java/Journey/Together/domain/place/entity/DisabilityPlaceCategory.java +++ b/src/main/java/Journey/Together/domain/place/entity/DisabilityPlaceCategory.java @@ -23,6 +23,8 @@ public class DisabilityPlaceCategory { @JoinColumn(name = "subCategory_id") private DisabilitySubCategory subCategory; + private String description; + @Builder public DisabilityPlaceCategory(Place place, DisabilitySubCategory subCategory){ this.place=place; diff --git a/src/main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java b/src/main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java index 4406415..0cbefda 100644 --- a/src/main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java +++ b/src/main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java @@ -17,7 +17,7 @@ public interface DisabilityPlaceCategoryRepository extends JpaRepository findDisabilityCategoryIds(@Param("placeId") long placeId); - @Query("SELECT DISTINCT dpc.subCategory.subname FROM DisabilityPlaceCategory dpc " + + @Query("SELECT DISTINCT dpc FROM DisabilityPlaceCategory dpc " + "WHERE dpc.place.id = :placeId") - List findDisabilitySubCategoryNames(@Param("placeId") long placeId); + List findDisabilitySubCategory(@Param("placeId") long placeId); } 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 94832f4..668a75e 100644 --- a/src/main/java/Journey/Together/domain/place/repository/PlaceReviewRepository.java +++ b/src/main/java/Journey/Together/domain/place/repository/PlaceReviewRepository.java @@ -7,9 +7,12 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface PlaceReviewRepository extends JpaRepository { - PlaceReview findPlaceReviewByPlace(Place place); + List findAllByPlaceOrderByCreatedAtDesc(Place place); + PlaceReview findPlaceReviewByMemberAndPlace(Member member, Place place); Page findAllByPlaceOrderByCreatedAtDesc(Place place, Pageable pageable); 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 55d8b28..e714ffc 100644 --- a/src/main/java/Journey/Together/domain/place/service/PlaceService.java +++ b/src/main/java/Journey/Together/domain/place/service/PlaceService.java @@ -75,9 +75,23 @@ public PlaceDetailRes getPlaceDetail(Member member, Long placeId){ .anyMatch(placeBookmark -> placeBookmark.getMember().equals(member)); List disability = disabilityPlaceCategoryRepository.findDisabilityCategoryIds(placeId); - List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategoryNames(placeId); + List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategory(placeId).stream().map(SubDisability::of).toList(); - return PlaceDetailRes.of(place, isMark, placeBookmarkList.size(), disability, subDisability, null); + List placeReviews = placeReviewRepository.findAllByPlaceOrderByCreatedAtDesc(place); + if(placeReviews.size()<0) + return PlaceDetailRes.of(place, isMark, placeBookmarkList.size(), disability, subDisability, null); + + List reviewList = new ArrayList<>(); + + placeReviews.forEach(placeReview -> { + List placeReviewImgs = placeReviewImgRepository.findAllByPlaceReview(placeReview); + if (placeReviewImgs.size() > 0) { + reviewList.add(PlaceReviewDto.of(placeReview, s3Client.getUrl()+placeReview.getMember().getProfileUuid()+"/profile",placeReviewImgs.get(0).getImgUrl())); + } else + reviewList.add(PlaceReviewDto.of(placeReview,s3Client.getUrl()+placeReview.getMember().getProfileUuid()+"/profile", placeReview.getPlace().getFirstImg())); + }); + + return PlaceDetailRes.of(place, isMark, placeBookmarkList.size(), disability, subDisability, reviewList); } @@ -88,9 +102,24 @@ public PlaceDetailGuestRes getGeustPlaceDetail(Long placeId){ List placeBookmarkList = placeBookmarkRepository.findAllByPlace(place); List disability = disabilityPlaceCategoryRepository.findDisabilityCategoryIds(placeId); - List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategoryNames(placeId); + List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategory(placeId).stream().map(SubDisability::of).toList(); + + List placeReviews = placeReviewRepository.findAllByPlaceOrderByCreatedAtDesc(place); + if(placeReviews.size()<0) + return PlaceDetailGuestRes.of(place, placeBookmarkList.size(), disability, subDisability, null); + + List reviewList = new ArrayList<>(); + + placeReviews.forEach(placeReview -> { + List placeReviewImgs = placeReviewImgRepository.findAllByPlaceReview(placeReview); + if (placeReviewImgs.size() > 0) { + reviewList.add(PlaceReviewDto.of(placeReview, s3Client.getUrl()+placeReview.getMember().getProfileUuid()+"/profile",placeReviewImgs.get(0).getImgUrl())); + } else + reviewList.add(PlaceReviewDto.of(placeReview,s3Client.getUrl()+placeReview.getMember().getProfileUuid()+"/profile", placeReview.getPlace().getFirstImg())); + }); + - return PlaceDetailGuestRes.of(place, placeBookmarkList.size(), disability, subDisability, null); + return PlaceDetailGuestRes.of(place, placeBookmarkList.size(), disability, subDisability, reviewList); } @@ -124,7 +153,7 @@ public List searchPlaceMap(String category, List disabilityType, public void createReview(Member member, List images, PlaceReviewReq placeReviewReq, Long placeId){ Place place = getPlace(placeId); - if(placeReviewRepository.findPlaceReviewByPlace(place) != null) + if(placeReviewRepository.findPlaceReviewByMemberAndPlace(member,place) != null) throw new ApplicationException(ErrorCode.ALREADY_EXIST_EXCEPTION); PlaceReview placeReview = PlaceReview.builder()