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 3985a19..346c28b 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -37,11 +37,16 @@ public StorePagedResponseDto getStoreInRange(@RequestParam(required = false) Big @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) { - return storeService.getStoreInRange(latStart, latEnd, lngStart, lngEnd, category, facility, pageable, user == null ? null : user.getUsername()); + 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()); } @GetMapping("/point") 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 1a0667e..2a36d0e 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -1,6 +1,7 @@ package com.mpnp.baechelin.store.service; import com.mpnp.baechelin.bookmark.repository.BookmarkRepository; +import com.mpnp.baechelin.config.QuerydslLocation; import com.mpnp.baechelin.review.domain.Review; import com.mpnp.baechelin.review.repository.ReviewRepository; import com.mpnp.baechelin.store.domain.Store; @@ -87,7 +88,19 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat return getStoreCardPagedResponseDto(targetUser, betweenLngLat); } -// public List getStoreInRangeHighPoint(BigDecimal lat, BigDecimal lng, String + public StorePagedResponseDto getStoreInRangeMain(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); + } + + public StorePagedResponseDto getStoreInRangeMap(BigDecimal lat, BigDecimal lng, String category, List facility, Pageable pageable, String socialId) { + User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId); + Page betweenLngLat = storeQueryRepository.findStoreOrderByPoint(lat, lng, category, facility, pageable); + // store 가져와서 dto 매핑 + return getStoreCardPagedResponseDto(targetUser, betweenLngLat); + } + + // public List getStoreInRangeHighPoint(BigDecimal lat, BigDecimal lng, String public StorePagedResponseDto getStoreInRangeHighPoint(BigDecimal lat, BigDecimal lng, String category, List facility, Pageable pageable, String socialId) { User targetUser = socialId == null ? null : userRepository.findBySocialId(socialId); @@ -120,14 +133,14 @@ private StorePagedResponseDto getStoreCardPagedResponseDto(User targetUser, Page private List getStoreCardResponseDtos(User targetUser, List resultStoreList) { if (targetUser == null) { - return resultStoreList.parallelStream().map(store -> new StoreCardResponseDto(store, false)) + return resultStoreList.stream().map(store -> new StoreCardResponseDto(store, false)) .collect(Collectors.toList()); } else { - return resultStoreList.parallelStream().map(store -> { + return resultStoreList.stream().map(store -> { long count = targetUser.getBookmarkList().stream() .filter(b -> b.getUserId() == targetUser && b.getStoreId() == store).count(); return new StoreCardResponseDto(store, count > 0); - }).collect(Collectors.toList());// 순서보장} + }).collect(Collectors.toList()); } } } \ No newline at end of file