From fb49155aec68c23d57f7dfb0db594a4d37278f58 Mon Sep 17 00:00:00 2001 From: junmo95 Date: Wed, 24 Jan 2024 11:24:50 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[feat]=20=EC=97=AC=ED=96=89=EC=A7=80=20?= =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripcometrue/domain/place/entity/Place.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java b/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java index 70977a0e..dcad9ad8 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/entity/Place.java @@ -26,6 +26,7 @@ public class Place extends BaseTimeEntity { @Column(nullable = false) private String address; private String description; + private String phoneNumber; private LocalTime weekdayOpenTime; private LocalTime weekdayCloseTime; private LocalTime weekendOpenTime; @@ -49,15 +50,15 @@ public void prePersist() { } @Builder - public Place(Long id, String name, String address, String description, - LocalTime weekdayOpenTime, - LocalTime weekdayCloseTime, LocalTime weekendOpenTime, LocalTime weekendCloseTime, - Double latitude, Double longitude, Integer storedCount, Integer reviewCount, - Integer commentCount, City city) { + public Place(Long id, String name, String address, String description, String phoneNumber, + LocalTime weekdayOpenTime, LocalTime weekdayCloseTime, LocalTime weekendOpenTime, + LocalTime weekendCloseTime, Double latitude, Double longitude, Integer storedCount, + Integer reviewCount, Integer commentCount, City city) { this.id = id; this.name = name; this.address = address; this.description = description; + this.phoneNumber = phoneNumber; this.weekdayOpenTime = weekdayOpenTime; this.weekdayCloseTime = weekdayCloseTime; this.weekendOpenTime = weekendOpenTime; From cc03eff52154b50945e0a34aea5f609df4767a81 Mon Sep 17 00:00:00 2001 From: junmo95 Date: Wed, 24 Jan 2024 11:25:59 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[feat]=20=EC=97=AC=ED=96=89=EC=A7=80=20'?= =?UTF-8?q?=EA=B7=BC=EC=B2=98=20=EC=B6=94=EC=B2=9C=20=EC=97=AC=ED=96=89?= =?UTF-8?q?=EC=A7=80'=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC,=20Dto=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/controller/PlaceController.java | 15 ++++++++++ .../dto/response/PlaceNearbyResponseDto.java | 28 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceNearbyResponseDto.java diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java b/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java index 64744e1b..93b04048 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/controller/PlaceController.java @@ -2,6 +2,7 @@ import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDto; import com.haejwo.tripcometrue.domain.place.dto.response.PlaceMapInfoResponseDto; +import com.haejwo.tripcometrue.domain.place.dto.response.PlaceNearbyResponseDto; import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDto; import com.haejwo.tripcometrue.domain.place.service.PlaceService; import com.haejwo.tripcometrue.global.util.ResponseDTO; @@ -67,6 +68,20 @@ public ResponseEntity>> placeMapInfoLi .body(responseBody); } + @GetMapping("/{placeId}/nearby") + public ResponseEntity>> placeNearbyList( + @PathVariable Long placeId + ) { + + List responseDtos = placeService.findNearbyPlaceList(placeId); + + ResponseDTO> responseBody = ResponseDTO.okWithData(responseDtos); + + return ResponseEntity.status(responseBody + .getCode()) + .body(responseBody); + } + @GetMapping public ResponseEntity>> placeList( Pageable pageable, diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceNearbyResponseDto.java b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceNearbyResponseDto.java new file mode 100644 index 00000000..3282585b --- /dev/null +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceNearbyResponseDto.java @@ -0,0 +1,28 @@ +package com.haejwo.tripcometrue.domain.place.dto.response; + +import lombok.Builder; + +public record PlaceNearbyResponseDto( + Long placeId, + String placeName, + String imageUrl, + Double latitude, + Double longitude, + Integer storedCount, + Integer reviewCount, + Integer commentCount +) { + + @Builder + public PlaceNearbyResponseDto(Long placeId, String placeName, String imageUrl, Double latitude, + Double longitude, Integer storedCount, Integer reviewCount, Integer commentCount) { + this.placeId = placeId; + this.placeName = placeName; + this.imageUrl = imageUrl; + this.latitude = latitude; + this.longitude = longitude; + this.storedCount = storedCount; + this.reviewCount = reviewCount; + this.commentCount = commentCount; + } +} From 550f04662a449e812337b7743728d56b796b170b Mon Sep 17 00:00:00 2001 From: junmo95 Date: Wed, 24 Jan 2024 11:26:33 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[feat]=20=EC=97=AC=ED=96=89=EC=A7=80=20'?= =?UTF-8?q?=EA=B7=BC=EC=B2=98=20=EC=B6=94=EC=B2=9C=20=EC=97=AC=ED=96=89?= =?UTF-8?q?=EC=A7=80'=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tripcometrue/domain/place/service/PlaceService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java b/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java index e4aaea5e..b26c3404 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/service/PlaceService.java @@ -5,6 +5,7 @@ import com.haejwo.tripcometrue.domain.city.repository.CityRepository; import com.haejwo.tripcometrue.domain.place.dto.request.PlaceRequestDto; import com.haejwo.tripcometrue.domain.place.dto.response.PlaceMapInfoResponseDto; +import com.haejwo.tripcometrue.domain.place.dto.response.PlaceNearbyResponseDto; import com.haejwo.tripcometrue.domain.place.dto.response.PlaceResponseDto; import com.haejwo.tripcometrue.domain.place.entity.Place; import com.haejwo.tripcometrue.domain.place.exception.PlaceNotFoundException; @@ -65,6 +66,14 @@ public List findPlaceMapInfoList(Long placeId) { return responseDtos; } + public List findNearbyPlaceList(Long placeId) { + + List responseDtos = placeRepository.findNearbyPlaces(placeId); + + return responseDtos; + + } + @Transactional public PlaceResponseDto modifyPlace(Long placeId, PlaceRequestDto requestDto) { From 20062a46580443ce77ad181908b6bd8a3b2ad8ab Mon Sep 17 00:00:00 2001 From: junmo95 Date: Wed, 24 Jan 2024 11:27:01 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[feat]=20=EC=97=AC=ED=96=89=EC=A7=80=20'?= =?UTF-8?q?=EA=B7=BC=EC=B2=98=20=EC=B6=94=EC=B2=9C=20=EC=97=AC=ED=96=89?= =?UTF-8?q?=EC=A7=80'=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositroy/PlaceCustomRepository.java | 3 ++ .../repositroy/PlaceCustomRepositoryImpl.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepository.java b/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepository.java index a78e6b05..beea5fa1 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepository.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepository.java @@ -2,6 +2,7 @@ import com.haejwo.tripcometrue.domain.city.entity.City; import com.haejwo.tripcometrue.domain.place.dto.response.PlaceMapInfoResponseDto; +import com.haejwo.tripcometrue.domain.place.dto.response.PlaceNearbyResponseDto; import com.haejwo.tripcometrue.domain.place.entity.Place; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -19,4 +20,6 @@ Page findPlaceWithFilter(Pageable pageable, List findPlacesByCityAndOrderByStoredCountLimitSize(City city, int size); List findPlaceMapInfoListByPlaceId(Long placeId); + + List findNearbyPlaces(Long placeId); } diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepositoryImpl.java b/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepositoryImpl.java index 46ccfc59..008efc75 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepositoryImpl.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/repositroy/PlaceCustomRepositoryImpl.java @@ -3,6 +3,7 @@ import com.haejwo.tripcometrue.domain.city.entity.City; import com.haejwo.tripcometrue.domain.city.entity.QCity; import com.haejwo.tripcometrue.domain.place.dto.response.PlaceMapInfoResponseDto; +import com.haejwo.tripcometrue.domain.place.dto.response.PlaceNearbyResponseDto; import com.haejwo.tripcometrue.domain.place.entity.Place; import com.haejwo.tripcometrue.domain.place.entity.QPlace; import com.haejwo.tripcometrue.domain.triprecord.entity.QTripRecordSchedule; @@ -149,6 +150,56 @@ public List findPlaceMapInfoListByPlaceId(Long placeId) } + @Override + public List findNearbyPlaces(Long placeId) { + + QPlace qPlace = QPlace.place; + QTripRecordSchedule qTripRecordSchedule = QTripRecordSchedule.tripRecordSchedule; + QTripRecordScheduleImage qTripRecordScheduleImage = QTripRecordScheduleImage.tripRecordScheduleImage; + + // 주어진 placeId에 해당하는 장소의 위도, 경도를 찾는다. + Place centerPlace = queryFactory + .selectFrom(qPlace) + .where(qPlace.id.eq(placeId)) + .fetchOne(); + + // 주변 장소를 뽑아냅니다. (1도 범위 내면 보통 11km 안쪽임) + List nearbyPlaces = queryFactory + .selectFrom(qPlace) + .where(qPlace.latitude.between(centerPlace.getLatitude() - 1, centerPlace.getLatitude() + 1) + .and(qPlace.longitude.between(centerPlace.getLongitude() - 1, centerPlace.getLongitude() + 1))) + .orderBy(qPlace.storedCount.desc()) + .where(qPlace.id.ne(placeId)) + .limit(5) + .fetch(); + + // 각 장소에 해당하는 스케줄 이미지를 찾아 PlaceNearbyResponseDto 객체를 생성한다. (어차피 컨텐츠가 5개 고정이여서 이게 더 간단함) + List result = nearbyPlaces.stream() + .map(place -> { + String imageUrl = queryFactory + .select(qTripRecordScheduleImage.imageUrl) + .from(qTripRecordScheduleImage) + .join(qTripRecordScheduleImage.tripRecordSchedule, qTripRecordSchedule) + .where(qTripRecordSchedule.place.id.eq(place.getId())) + .orderBy(qTripRecordScheduleImage.id.asc()) + .fetchFirst(); + + return new PlaceNearbyResponseDto( + place.getId(), + place.getName(), + imageUrl, + place.getLatitude(), + place.getLongitude(), + place.getStoredCount(), + place.getReviewCount(), + place.getCommentCount() + ); + }) + .collect(Collectors.toList()); + + return result; + } + private OrderSpecifier[] getSort(Pageable pageable) { QPlace place = QPlace.place; From f17515760fbc2da6c5bd583cfc78fcad8cfc1b2a Mon Sep 17 00:00:00 2001 From: junmo95 Date: Wed, 24 Jan 2024 11:28:44 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[feat]=20=EC=97=AC=ED=96=89=EC=A7=80=20?= =?UTF-8?q?=EC=84=B8=EB=B6=80=EC=A0=95=EB=B3=B4=20=EC=9D=91=EB=8B=B5=20DTO?= =?UTF-8?q?=20=EC=A2=8C=ED=91=9C,=20=EC=A0=84=ED=99=94=EB=B2=88=ED=98=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/dto/response/PlaceResponseDto.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java index ce5d3af6..029f3a8d 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/place/dto/response/PlaceResponseDto.java @@ -1,6 +1,7 @@ package com.haejwo.tripcometrue.domain.place.dto.response; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonFormat.Shape; import com.haejwo.tripcometrue.domain.place.entity.Place; import java.time.LocalTime; import lombok.Builder; @@ -9,35 +10,36 @@ public record PlaceResponseDto( String name, String address, String description, + String phoneNumber, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayOpenTime, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekdayCloseTime, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendOpenTime, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") LocalTime weekendCloseTime, + Double latitude, + Double longitude, Integer storedCount, Long cityId ) { @Builder - public PlaceResponseDto( - Long id, - String name, - String address, - String description, - LocalTime weekdayOpenTime, - LocalTime weekdayCloseTime, - LocalTime weekendOpenTime, - LocalTime weekendCloseTime, - Integer storedCount, - Long cityId - ) { + public PlaceResponseDto(Long id, String name, String address, String description, + String phoneNumber, + @JsonFormat(shape = Shape.STRING, pattern = "HH:mm") LocalTime weekdayOpenTime, + @JsonFormat(shape = Shape.STRING, pattern = "HH:mm") LocalTime weekdayCloseTime, + @JsonFormat(shape = Shape.STRING, pattern = "HH:mm") LocalTime weekendOpenTime, + @JsonFormat(shape = Shape.STRING, pattern = "HH:mm") LocalTime weekendCloseTime, + Double latitude, Double longitude, Integer storedCount, Long cityId) { this.id = id; this.name = name; this.address = address; this.description = description; + this.phoneNumber = phoneNumber; this.weekdayOpenTime = weekdayOpenTime; this.weekdayCloseTime = weekdayCloseTime; this.weekendOpenTime = weekendOpenTime; this.weekendCloseTime = weekendCloseTime; + this.latitude = latitude; + this.longitude = longitude; this.storedCount = storedCount; this.cityId = cityId; } @@ -48,10 +50,13 @@ public static PlaceResponseDto fromEntity(Place entity) { .name(entity.getName()) .address(entity.getAddress()) .description(entity.getDescription()) + .phoneNumber(entity.getPhoneNumber()) .weekdayOpenTime(entity.getWeekdayOpenTime()) .weekdayCloseTime(entity.getWeekdayCloseTime()) .weekendOpenTime(entity.getWeekendOpenTime()) .weekendCloseTime(entity.getWeekendCloseTime()) + .latitude(entity.getLatitude()) + .longitude(entity.getLongitude()) .storedCount(entity.getStoredCount()) .cityId(entity.getCity().getId()) .build(); From 70b1200fe438592bd76dd4dfb3baa3c5561b4109 Mon Sep 17 00:00:00 2001 From: junmo95 Date: Wed, 24 Jan 2024 11:29:19 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[feat]=20=EC=97=AC=ED=96=89=ED=9B=84?= =?UTF-8?q?=EA=B8=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=EC=97=90=20=ED=8F=89=EC=A0=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/triprecord/TripRecordListResponseDto.java | 8 +++++--- .../triprecord/TripRecordCustomRepositoryImpl.java | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/triprecord/TripRecordListResponseDto.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/triprecord/TripRecordListResponseDto.java index 7150dbed..c3b0ec32 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/triprecord/TripRecordListResponseDto.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/dto/response/triprecord/TripRecordListResponseDto.java @@ -11,20 +11,22 @@ public record TripRecordListResponseDto( Integer totalDays, Integer commentCount, Integer storeCount, + Double averageRating, String imageUrl, TripRecordMemberResponseDto member ) { @Builder - public TripRecordListResponseDto(Long tripRecordId, String title, String countries, Integer totalDays, - Integer commentCount, Integer storeCount, String imageUrl, - TripRecordMemberResponseDto member) { + public TripRecordListResponseDto(Long tripRecordId, String title, String countries, + Integer totalDays, Integer commentCount, Integer storeCount, Double averageRating, + String imageUrl, TripRecordMemberResponseDto member) { this.tripRecordId = tripRecordId; this.title = title; this.countries = countries; this.totalDays = totalDays; this.commentCount = commentCount; this.storeCount = storeCount; + this.averageRating = averageRating; this.imageUrl = imageUrl; this.member = member; } diff --git a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/triprecord/TripRecordCustomRepositoryImpl.java b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/triprecord/TripRecordCustomRepositoryImpl.java index d7aa36fc..385f460a 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/triprecord/TripRecordCustomRepositoryImpl.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/triprecord/repository/triprecord/TripRecordCustomRepositoryImpl.java @@ -105,6 +105,7 @@ public List finTripRecordWithFilter( qTripRecord.totalDays, qTripRecord.commentCount, qTripRecord.storeCount, + qTripRecord.averageRating, JPAExpressions .select(qTripRecordImage.imageUrl.min()) .from(qTripRecordImage)