diff --git a/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java b/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java index 6540203..fb8c647 100644 --- a/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java +++ b/src/main/java/com/mpnp/baechelin/review/controller/ReviewController.java @@ -4,6 +4,7 @@ import com.mpnp.baechelin.review.dto.ReviewResDTO; import com.mpnp.baechelin.review.service.ReviewService; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -38,4 +39,9 @@ public ReviewResDTO review(@RequestParam double point, reviewService.review(reviewReqDTO); return null; } + // TODO - 최근 등록한 리뷰 보여주기 + @GetMapping("/recent-review") + public ReviewResDTO recentReview(){ + return null; + } } diff --git a/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java b/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java new file mode 100644 index 0000000..83a1ec2 --- /dev/null +++ b/src/main/java/com/mpnp/baechelin/review/repository/ReviewQueryRepository.java @@ -0,0 +1,47 @@ +package com.mpnp.baechelin.review.repository; + +import com.mpnp.baechelin.review.domain.QReview; +import com.mpnp.baechelin.review.domain.Review; +import com.mpnp.baechelin.store.domain.Store; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.jpa.impl.JPAQueryFactory; +import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; +import org.springframework.stereotype.Repository; + +import javax.transaction.Transactional; +import java.math.BigDecimal; +import java.util.List; + +import static com.mpnp.baechelin.review.domain.QReview.review1; +import static com.mpnp.baechelin.store.domain.QStore.store; + +@Repository +@Transactional +public class ReviewQueryRepository extends QuerydslRepositorySupport { + private final JPAQueryFactory queryFactory; + private final BooleanBuilder builder = new BooleanBuilder(); + + public ReviewQueryRepository(JPAQueryFactory queryFactory) { + super(Review.class); + this.queryFactory = queryFactory; + } + + public List findRecentReviews(BigDecimal latStart, + BigDecimal latEnd, + BigDecimal lngStart, + BigDecimal lngEnd, + int limit) { + builder.and(store.latitude.goe(latStart)); + builder.and(store.latitude.loe(latEnd)); + builder.and(store.longitude.goe(lngStart)); + builder.and(store.longitude.loe(lngEnd)); + // 위도 경도에 해당하는 가게를 찾음 -> 해당 댓글을 다 가져옴 -> 내림차순 정렬 -> limit + return queryFactory.selectFrom(review1) + .innerJoin(review1.storeId, store) + .where(review1.storeId + .in(queryFactory.select(store).from(store).where(builder))) + .limit(limit) + .fetch(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java index 5808f72..429f124 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -26,8 +26,7 @@ public class StoreController { @GetMapping public List getStoreList() { - List storeList = storeService.getStoreList(); - return storeList; + return storeService.getStoreList(); } @GetMapping("/near") @@ -37,10 +36,31 @@ public List giveStoreInRange(@RequestParam BigDecimal latStart @RequestParam BigDecimal lngEnd, @RequestParam(required = false) String category, @RequestParam(required = false) List facility, - // sort 기준 정하기 - //@PageableDefault(sort = {""}, direction = Sort.Direction.DESC) Pageable pageable){ @PageableDefault Pageable pageable) { List betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 } + @GetMapping("/near/high-point") + public List giveStoreInRangeHighPoint(@RequestParam BigDecimal latStart, + @RequestParam BigDecimal latEnd, + @RequestParam BigDecimal lngStart, + @RequestParam BigDecimal lngEnd, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @PageableDefault Pageable pageable) { + List betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); + return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 + } + + @GetMapping("/near/high-bookmark") + public List giveStoreInRangeHighBookmark(@RequestParam BigDecimal latStart, + @RequestParam BigDecimal latEnd, + @RequestParam BigDecimal lngStart, + @RequestParam BigDecimal lngEnd, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @RequestParam int limit) { + List betweenLngLat = storeQueryRepository.findStoreOrderByBookmark(latStart, latEnd, lngStart, lngEnd, category, facility, limit); + return betweenLngLat.parallelStream().map(storeService::storeToResDto).collect(Collectors.toList());// 순서보장 + } } diff --git a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java index 9b68a89..eec65b5 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -25,6 +25,7 @@ @Transactional public class StoreQueryRepository extends QuerydslRepositorySupport { private final JPAQueryFactory queryFactory; + private final BooleanBuilder builder = new BooleanBuilder(); public StoreQueryRepository(JPAQueryFactory queryFactory) { super(Store.class); @@ -40,25 +41,51 @@ public List findBetweenLngLat(BigDecimal latStart, List facility, Pageable pageable) { - BooleanBuilder builder = new BooleanBuilder(); - builder.and(store.latitude.goe(latStart)); - builder.and(store.latitude.loe(latEnd)); - builder.and(store.longitude.goe(lngStart)); - builder.and(store.longitude.loe(lngEnd)); - builder.and(category == null ? null : store.category.eq(category)); - if (facility != null && facility.size() > 0) { - for (String fac : facility) { - builder.and(facilityTF(fac)); - } - } + locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); - List storeList = queryFactory.selectFrom(store) + return queryFactory.selectFrom(store) .where(builder) .limit(pageable.getPageSize()) .offset(pageable.getOffset()) .fetch(); + } + + //TODO 별점순 + public List findStoreOrderByPoint(BigDecimal latStart, + BigDecimal latEnd, + BigDecimal lngStart, + BigDecimal lngEnd, + String category, + List facility, + int limit) { + + + locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); + + return queryFactory.selectFrom(store) + .where(builder) + .orderBy(store.pointAvg.desc()) + .limit(limit) + .fetch(); + } + + //TODO 북마크순 + public List findStoreOrderByBookmark(BigDecimal latStart, + BigDecimal latEnd, + BigDecimal lngStart, + BigDecimal lngEnd, + String category, + List facility, + int limit) { + + locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); + + return queryFactory.selectFrom(store) + .where(builder) + .orderBy(store.bookMarkCount.desc()) + .limit(limit) + .fetch(); - return storeList; } private BooleanExpression facilityTF(String facility) { @@ -79,12 +106,16 @@ private StringPath givePath(String dbFacility) { return store.toilet; } - - - - //TODO 별점순 - - //TODO 실시간 맛집 - - //TODO 북마크순 + private void locAndConditions(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List facility) { + builder.and(store.latitude.goe(latStart)); + builder.and(store.latitude.loe(latEnd)); + builder.and(store.longitude.goe(lngStart)); + builder.and(store.longitude.loe(lngEnd)); + builder.and(category == null ? null : store.category.eq(category)); + if (facility != null && facility.size() > 0) { + for (String fac : facility) { + builder.and(facilityTF(fac)); + } + } + } } diff --git a/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java b/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java index 6785642..5b8775a 100644 --- a/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/user/dto/UserInfoResponseDto.java @@ -24,7 +24,7 @@ public class UserInfoResponseDto { public UserInfoResponseDto(User user) { this.name = user.getName(); - this.reviewList = user.getReviewsList().stream().map(ReviewResponseDto::new).collect(Collectors.toList()); + this.reviewList = user.getReviewList().stream().map(ReviewResponseDto::new).collect(Collectors.toList()); this.bookmarkFolderList = user.getFolderList().stream().map(BookmarkFolderResponseDto::new).collect(Collectors.toList()); //folder