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 1bcf3fc..254560a 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -33,21 +33,26 @@ public class StoreController { @ApiOperation(value = "조건에 맞는 업장 목록을 반환하는 메소드") @GetMapping("/near") -// public List getStoreInRange(@RequestParam(required = false) BigDecimal latStart, + public StorePagedResponseDto getStoreInRange(@RequestParam(required = false) BigDecimal lat, + @RequestParam(required = false) BigDecimal lng, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @PageableDefault Pageable pageable, + @AuthenticationPrincipal User user) { + return storeService.getStoreInOnePointRange(lat, lng, category, facility, pageable, user == null ? null : user.getUsername()); + } + + @ApiOperation(value = "지도에서 조건에 맞는 업장 목록을 반환하는 메소드") + @GetMapping("/near-map") public StorePagedResponseDto getStoreInRange(@RequestParam(required = false) BigDecimal latStart, @RequestParam(required = false) BigDecimal latEnd, @RequestParam(required = false) BigDecimal lngStart, @RequestParam(required = false) BigDecimal lngEnd, - @RequestParam(required = false) BigDecimal lat, - @RequestParam(required = false) BigDecimal lng, @RequestParam(required = false) String category, @RequestParam(required = false) List facility, @PageableDefault Pageable pageable, @AuthenticationPrincipal User user) { - if (lat != null && lng != null) - return storeService.getStoreInRangeMain(lat, lng, category, facility, pageable, user == null ? null : user.getUsername()); - else - return storeService.getStoreInRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername()); + return storeService.getStoreInTwoPointsRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername()); } @GetMapping("/point") @@ -63,11 +68,11 @@ public StorePagedResponseDto getStoreInRangeHighPoint(@RequestParam(required = f @GetMapping("/bookmark") public StorePagedResponseDto getStoreInRangeHighBookmark(@RequestParam(required = false) BigDecimal lat, - @RequestParam(required = false) BigDecimal lng, - @RequestParam(required = false) String category, - @RequestParam(required = false) List facility, - @PageableDefault Pageable pageable, - @AuthenticationPrincipal User user) { + @RequestParam(required = false) BigDecimal lng, + @RequestParam(required = false) String category, + @RequestParam(required = false) List facility, + @PageableDefault Pageable pageable, + @AuthenticationPrincipal User user) { return storeService.getStoreInRangeHighBookmark(lat, lng, category, facility, pageable, user == null ? null : user.getUsername()); } 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 51a7dc0..a9f2b2d 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -36,13 +36,13 @@ public StoreQueryRepository(JPAQueryFactory queryFactory) { this.queryFactory = queryFactory; } - public Page findBetweenLngLat(BigDecimal latStart, - BigDecimal latEnd, - BigDecimal lngStart, - BigDecimal lngEnd, - String category, - List facility, - Pageable pageable) { + public Page findBetweenOnePointOrder(BigDecimal latStart, + BigDecimal latEnd, + BigDecimal lngStart, + BigDecimal lngEnd, + String category, + List facility, + Pageable pageable) { BigDecimal nowLat = (latStart.add(latEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP); BigDecimal nowLng = (lngStart.add(lngEnd)).divide(new BigDecimal("2"), 22, RoundingMode.HALF_UP); BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); @@ -62,6 +62,25 @@ public Page findBetweenLngLat(BigDecimal latStart, return new PageImpl<>(storeList, pageable, fetchCount); } + public Page findBetweenTwoPoint(BigDecimal latStart, + BigDecimal latEnd, + BigDecimal lngStart, + BigDecimal lngEnd, + String category, + List facility, + Pageable pageable) { + BooleanBuilder builder = QuerydslLocation.locAndConditions(latStart, latEnd, lngStart, lngEnd, category, facility); + List storeList = + queryFactory + .selectFrom(store) + .where(builder) + .limit(pageable.getPageSize()) + .offset(pageable.getOffset()) + .fetch(); + int fetchCount = queryFactory.selectFrom(store).where(builder).fetch().size(); + return new PageImpl<>(storeList, pageable, fetchCount); + } + //TODO 별점순 - 쿼리 결과로 산출된 리스트의 평균 구하기, 정렬, 페이징 public Page findStoreOrderByPoint(BigDecimal lat, BigDecimal lng, diff --git a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java index 7fc6151..66158ea 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -53,11 +53,19 @@ public class StoreService { public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List facility, Pageable pageable, String socialId) { // public List getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List facility, Pageable pageable, String socialId) { User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId); - Page betweenLngLat = storeQueryRepository.findBetweenLngLat(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); + Page betweenLngLat = storeQueryRepository.findBetweenOnePointOrder(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); // store 가져와서 dto 매핑 return getStoreCardPagedResponseDto(targetUser, betweenLngLat); } + public StorePagedResponseDto getStoreInTwoPointsRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List facility, Pageable pageable, String socialId) { +// public List getStoreInRange(BigDecimal latStart, BigDecimal latEnd, BigDecimal lngStart, BigDecimal lngEnd, String category, List facility, Pageable pageable, String socialId) { + User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId); + Page betweenSquare = storeQueryRepository.findBetweenTwoPoint(latStart, latEnd, lngStart, lngEnd, category, facility, pageable); + // store 가져와서 dto 매핑 + return getStoreCardPagedResponseDto(targetUser, betweenSquare); + } + /** * @param lat 위도 * @param lng 경도 @@ -67,7 +75,7 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat * @param socialId 유저 소셜 로그인 아이디 * @return 위도, 경도, 카테고리, 배리어 프리, 페이징을 만족하는 배리어 프리 업장 리턴 */ - public StorePagedResponseDto getStoreInRangeMain(BigDecimal lat, BigDecimal lng, String category, List facility, Pageable pageable, String socialId) { + public StorePagedResponseDto getStoreInOnePointRange(BigDecimal lat, BigDecimal lng, String category, List facility, Pageable pageable, String socialId) { BigDecimal[] range = QuerydslLocation.getRange(lat, lng, 10); return getStoreInRange(range[0], range[1], range[2], range[3], category, facility, pageable, socialId); } @@ -160,7 +168,8 @@ private List getStoreCardResponseDtos(User targetUser, Lis /** * 업장 상세 조회 - * @param storeId 업장 아이디 + * + * @param storeId 업장 아이디 * @param socialId 유저 social 아이디 * @return 업장 상세 정보 */ @@ -196,6 +205,7 @@ public StoreDetailResponseDto getStore(long storeId, String socialId) { /** * 시/도 (ex. 서울시, 대전광역시)의 시/군/구 리스트 조회 + * * @param sido 시/도 * @return 시/군/구 리스트 */ @@ -221,9 +231,10 @@ public Map> getSigungu(String sido) { /** * 업장 검색 - * @param sido 시/도명 - * @param sigungu 시/군/구명 - * @param keyword 검색어 + * + * @param sido 시/도명 + * @param sigungu 시/군/구명 + * @param keyword 검색어 * @param socialId 업장 pk * @param pageable page, size * @return