From 5e73c5007500cffbf0bf64bc7c3d4f4df6131794 Mon Sep 17 00:00:00 2001 From: mmihye Date: Mon, 3 Jun 2024 03:52:53 +0900 Subject: [PATCH] =?UTF-8?q?[#20]=20feat:=20=EA=B4=80=EA=B4=91=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 +++ .../place/controller/PlaceController.java | 10 +++++ .../place/dto/response/PlaceDetailRes.java | 37 +++++++++++++++++++ .../place/dto/response/PlaceReviewDto.java | 13 +++++++ .../DisabilityPlaceCategoryRepository.java | 11 ++++++ .../domain/place/service/PlaceService.java | 32 ++++++++++++++++ .../repository/PlaceBookmarkRepository.java | 17 +++++++++ .../Together/global/exception/ErrorCode.java | 2 +- .../Together/global/exception/Success.java | 1 + 9 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailRes.java create mode 100644 src/main/java/Journey/Together/domain/place/dto/response/PlaceReviewDto.java create mode 100644 src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java diff --git a/build.gradle b/build.gradle index a3d6fb5..ec2ea9f 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,12 @@ dependencies { // MAC OS implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64' + //Querydsl 추가 + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor """com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta""" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + } tasks.named('test') { diff --git a/src/main/java/Journey/Together/domain/place/controller/PlaceController.java b/src/main/java/Journey/Together/domain/place/controller/PlaceController.java index b06fbbd..99a14a9 100644 --- a/src/main/java/Journey/Together/domain/place/controller/PlaceController.java +++ b/src/main/java/Journey/Together/domain/place/controller/PlaceController.java @@ -4,11 +4,14 @@ import Journey.Together.domain.member.dto.MemberRes; import Journey.Together.domain.member.service.MemberService; import Journey.Together.domain.place.dto.response.MainRes; +import Journey.Together.domain.place.dto.response.PlaceDetailRes; import Journey.Together.domain.place.service.PlaceService; import Journey.Together.global.common.ApiResponse; import Journey.Together.global.exception.Success; +import Journey.Together.global.security.PrincipalDetails; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @RestController @@ -24,4 +27,11 @@ public ApiResponse getMain(@RequestHeader("Authorization") String acces @RequestParam String areacode, @RequestParam String sigungucode) { return ApiResponse.success(Success.GET_MAIN_SUCCESS, placeService.getMainPage(areacode, sigungucode)); } + + @GetMapping("/{placeId}") + public ApiResponse getPlaceDetail(@AuthenticationPrincipal PrincipalDetails principalDetails, + @PathVariable Long placeId){ + return ApiResponse.success(Success.GET_PLACE_DETAIL_SUCCESS, placeService.getPlaceDetail(principalDetails.getMember(), placeId)); + } + } 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 new file mode 100644 index 0000000..5d26ec5 --- /dev/null +++ b/src/main/java/Journey/Together/domain/place/dto/response/PlaceDetailRes.java @@ -0,0 +1,37 @@ +package Journey.Together.domain.place.dto.response; + +import Journey.Together.domain.place.entity.Place; + +import java.util.List; + +public record PlaceDetailRes( + Long placeId, + String name, + String imgae, + String address, + String category, + String overview, + String mapX, + String mapY, + + Boolean isMark, + + Integer bookmarkNum, + + List disability, + List subDisability, + List reviewList +) { + static String cat = "관광지"; + 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")) + cat = "맛집"; + + + + return new PlaceDetailRes(place.getId(), place.getName(), place.getFirstImg(), place.getAddress(), cat, place.getOverview(), place.getMapX(), place.getMapY(), isMark, + bookmarkNum, disability, subDisability, reviewList); + } +} 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 new file mode 100644 index 0000000..019802f --- /dev/null +++ b/src/main/java/Journey/Together/domain/place/dto/response/PlaceReviewDto.java @@ -0,0 +1,13 @@ +package Journey.Together.domain.place.dto.response; + +import java.time.LocalDateTime; + +public record PlaceReviewDto( + Long reviewId, + String nickname, + String profileImg, + String content, + String reviewImg, + Float grade, + LocalDateTime date) { +} 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 963663c..a702c63 100644 --- a/src/main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java +++ b/src/main/java/Journey/Together/domain/place/repository/DisabilityPlaceCategoryRepository.java @@ -3,10 +3,21 @@ import Journey.Together.domain.place.entity.DisabilityPlaceCategory; import Journey.Together.domain.place.entity.Place; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; public interface DisabilityPlaceCategoryRepository extends JpaRepository { List findAllByPlace(Place place); + + + @Query("SELECT DISTINCT dpc.subCategory.category.id FROM DisabilityPlaceCategory dpc " + + "WHERE dpc.place.id = :placeId") + List findDisabilityCategoryIds(@Param("placeId") long placeId); + + @Query("SELECT DISTINCT dpc.subCategory.id FROM DisabilityPlaceCategory dpc " + + "WHERE dpc.place.id = :placeId") + List findDisabilitySubCategoryIds(@Param("placeId") long placeId); } 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 cc47985..1c9ae52 100644 --- a/src/main/java/Journey/Together/domain/place/service/PlaceService.java +++ b/src/main/java/Journey/Together/domain/place/service/PlaceService.java @@ -1,12 +1,20 @@ package Journey.Together.domain.place.service; +import Journey.Together.domain.member.entity.Member; import Journey.Together.domain.place.dto.response.MainRes; +import Journey.Together.domain.place.dto.response.PlaceDetailRes; import Journey.Together.domain.place.dto.response.PlaceRes; +import Journey.Together.domain.place.dto.response.PlaceReviewDto; import Journey.Together.domain.place.entity.DisabilityPlaceCategory; import Journey.Together.domain.place.entity.Place; import Journey.Together.domain.place.repository.DisabilityPlaceCategoryRepository; import Journey.Together.domain.place.repository.PlaceRepository; +import Journey.Together.domain.placeBookbark.entity.PlaceBookmark; +import Journey.Together.domain.placeBookbark.repository.PlaceBookmarkRepository; import Journey.Together.global.common.ApiResponse; +import Journey.Together.global.exception.ApplicationException; +import Journey.Together.global.exception.ErrorCode; +import Journey.Together.global.exception.ErrorResponse; import Journey.Together.global.exception.Success; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,6 +27,9 @@ public class PlaceService { private final PlaceRepository placeRepository; private final DisabilityPlaceCategoryRepository disabilityPlaceCategoryRepository; + private final PlaceBookmarkRepository placeBookmarkRepository; + + private final Integer recommnedPlaceNum = 4; private final Integer aroundPlaceNum = 2; @@ -32,6 +43,26 @@ public MainRes getMainPage(String areacode, String sigungucode){ return new MainRes(getPlaceRes(recommondPlaces), getPlaceRes(aroundPlaces)); } + //여행지 상세 정보 가져오기 + public PlaceDetailRes getPlaceDetail(Member member, Long placeId){ + // PlaceDetailRes of(Place place, Boolean isMark, Integer bookmarkNum, List disability, List subDisability, List< PlaceReviewDto > reviewList) + + Place place = placeRepository.findById(placeId).orElseThrow( + ()->new ApplicationException(ErrorCode.NOT_FOUND_PLACE_EXCEPTION)); + + List placeBookmarkList = placeBookmarkRepository.findAllByPlace(place); + Boolean isMark = placeBookmarkList.stream() + .anyMatch(placeBookmark -> placeBookmark.getMember().equals(member)); + + List disability = disabilityPlaceCategoryRepository.findDisabilityCategoryIds(placeId); + List subDisability = disabilityPlaceCategoryRepository.findDisabilitySubCategoryIds(placeId); + + return PlaceDetailRes.of(place, isMark, placeBookmarkList.size(), disability, subDisability, null); + + + + } + private List getPlaceRes(List list){ List placeList = new ArrayList<>(); @@ -47,4 +78,5 @@ private List getPlaceRes(List list){ return placeList; } + } diff --git a/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java b/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java new file mode 100644 index 0000000..5d82f64 --- /dev/null +++ b/src/main/java/Journey/Together/domain/placeBookbark/repository/PlaceBookmarkRepository.java @@ -0,0 +1,17 @@ +package Journey.Together.domain.placeBookbark.repository; + + +import Journey.Together.domain.place.entity.Place; +import Journey.Together.domain.placeBookbark.entity.PlaceBookmark; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface PlaceBookmarkRepository extends JpaRepository { + + List findAllByPlace(Place place); + + +} diff --git a/src/main/java/Journey/Together/global/exception/ErrorCode.java b/src/main/java/Journey/Together/global/exception/ErrorCode.java index 6ba6075..0037cc0 100644 --- a/src/main/java/Journey/Together/global/exception/ErrorCode.java +++ b/src/main/java/Journey/Together/global/exception/ErrorCode.java @@ -32,7 +32,7 @@ public enum ErrorCode { //4000: Apply Error NOT_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4000,"지원 기간 지났습니다"), - NOT_FOUND_POST_EXCEPTION(HttpStatus.NOT_FOUND,4001,"존재하지 않는 글입니다."), + NOT_FOUND_PLACE_EXCEPTION(HttpStatus.NOT_FOUND,4001,"존재하지 않는 여행지입니다."), NOT_FOUND_APPLY_EXCEPTION(HttpStatus.NOT_FOUND,4002,"존재하지 않는 지원서입니다."), ALREADY_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4003,"이미 지원했습니다."), ALREADY_DECISION_EXCEPION(HttpStatus.BAD_REQUEST,4004,"이미 지원 결정했습니다."), diff --git a/src/main/java/Journey/Together/global/exception/Success.java b/src/main/java/Journey/Together/global/exception/Success.java index 010830c..93f9bac 100644 --- a/src/main/java/Journey/Together/global/exception/Success.java +++ b/src/main/java/Journey/Together/global/exception/Success.java @@ -19,6 +19,7 @@ public enum Success { * 200 OK */ GET_MAIN_SUCCESS(HttpStatus.OK, "메인 페이지 정보 조회 성공"), + GET_PLACE_DETAIL_SUCCESS(HttpStatus.OK, "여행지 상세정보 조회 성공"), GET_MYPAGE_SUCCESS(HttpStatus.OK, "마이 페이지 조회 성공"), GET_LINKS_SUCCESS(HttpStatus.OK, "이주의 링크 조회 성공"), GET_SITES_SUCCESS(HttpStatus.OK, "추천 사이트 조회 성공"),