From 199d39e342714c599d4105c1a7e6d19adc401b85 Mon Sep 17 00:00:00 2001 From: JSoi Date: Fri, 29 Jul 2022 05:58:01 +0900 Subject: [PATCH] =?UTF-8?q?#39=20[Add]=20DTO=EC=97=90=20=EC=B9=B4=EC=9A=B4?= =?UTF-8?q?=ED=8A=B8=20=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/dto/StorePagedResponseDto.java | 11 ++++++++-- .../baechelin/store/service/StoreService.java | 22 +++++-------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/mpnp/baechelin/store/dto/StorePagedResponseDto.java b/src/main/java/com/mpnp/baechelin/store/dto/StorePagedResponseDto.java index dcd7b84..1e89072 100644 --- a/src/main/java/com/mpnp/baechelin/store/dto/StorePagedResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/store/dto/StorePagedResponseDto.java @@ -7,10 +7,17 @@ import java.util.List; -@Getter @Setter +@Getter +@Setter @NoArgsConstructor -@AllArgsConstructor public class StorePagedResponseDto { private boolean hasNextPage; + private long totalCount; private List cards; + + public StorePagedResponseDto(boolean hasNextPage, List cards, long totalCount) { + this.hasNextPage = hasNextPage; + this.cards = cards; + this.totalCount = totalCount; + } } \ No newline at end of file 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 66158ea..ef4ec0a 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -15,6 +15,7 @@ import com.mpnp.baechelin.user.domain.User; import com.mpnp.baechelin.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -58,13 +59,6 @@ public StorePagedResponseDto getStoreInRange(BigDecimal latStart, BigDecimal lat 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 위도 @@ -126,17 +120,11 @@ public StorePagedResponseDto getStoreInRangeHighBookmark(BigDecimal lat, BigDeci */ private StorePagedResponseDto getStoreCardPagedResponseDto(User targetUser, Page resultStoreList) { List mappingResult = new ArrayList<>(); - if (targetUser == null) { - for (Store store : resultStoreList) { - mappingResult.add(new StoreCardResponseDto(store, "N")); - } - } else { - for (Store store : resultStoreList) { - boolean isBookmark = bookmarkRepository.existsByStoreIdAndUserId(store, targetUser); - mappingResult.add(new StoreCardResponseDto(store, isBookmark ? "Y" : "N")); - } + for (Store store : resultStoreList) { + boolean isBookmark = bookmarkRepository.existsByStoreIdAndUserId(store, targetUser); + mappingResult.add(new StoreCardResponseDto(store, isBookmark ? "Y" : "N")); } - return new StorePagedResponseDto(resultStoreList.hasNext(), mappingResult); + return new StorePagedResponseDto(resultStoreList.hasNext(), mappingResult, resultStoreList.getTotalElements()); }