From 141d8f4741cf9c45793285f227bb67c66033bdb7 Mon Sep 17 00:00:00 2001 From: Anna-Jin Date: Tue, 26 Jul 2022 03:56:16 +0900 Subject: [PATCH] =?UTF-8?q?#39=20[Update]=20=EC=97=85=EC=9E=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=ED=8E=98=EC=9D=B4=EC=A7=95=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/controller/StoreController.java | 4 +-- .../repository/StoreQueryRepository.java | 4 ++- .../baechelin/store/service/StoreService.java | 26 ++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) 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 6170203..2cd2d28 100644 --- a/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java +++ b/src/main/java/com/mpnp/baechelin/store/controller/StoreController.java @@ -97,9 +97,9 @@ public List searchStoresByKeyword( @RequestParam String sido, @RequestParam String sigungu, @RequestParam String keyword, + @PageableDefault Pageable pageable, @AuthenticationPrincipal User user) { - storeService.searchStores(sido, sigungu, keyword); - return null; + return storeService.searchStores(sido, sigungu, keyword, user == null ? null : user.getUsername(), pageable); } } \ No newline at end of file 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 719dcd0..20cb8bd 100644 --- a/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java +++ b/src/main/java/com/mpnp/baechelin/store/repository/StoreQueryRepository.java @@ -111,7 +111,7 @@ public Page findStoreOrderByBookmark(BigDecimal lat, } // 주소로 검색, 검색어로 검색 - public List searchStores(String sido, String sigungu, String keyword) { + public List searchStores(String sido, String sigungu, String keyword, Pageable pageable) { BooleanExpression matchAddress = QueryDslSearch.matchAddress(sido, sigungu); BooleanExpression matchKeyword = QueryDslSearch.matchKeyword(keyword); @@ -119,6 +119,8 @@ public List searchStores(String sido, String sigungu, String keyword) { .selectFrom(store) .where(matchAddress, matchKeyword) + .limit(pageable.getPageSize()) + .offset(pageable.getOffset()) .fetch(); } 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 d4ecea8..532796b 100644 --- a/src/main/java/com/mpnp/baechelin/store/service/StoreService.java +++ b/src/main/java/com/mpnp/baechelin/store/service/StoreService.java @@ -203,12 +203,26 @@ public Map> getSigungu(String sido) { return result; } - public List searchStores(String sido, String sigungu, String keyword) { - List storeList = storeQueryRepository.searchStores(sido, sigungu, keyword); + public List searchStores(String sido, String sigungu, String keyword, String socialId, Pageable pageable) { + List storeList = storeQueryRepository.searchStores(sido, sigungu, keyword, pageable); -// for (Store store : storeList) { -// -// } - return null; + List result = new ArrayList<>(); + + for (Store store : storeList) { + if (socialId == null) { + result.add(new StoreCardResponseDto(store, "N")); + } else { + String isBookmark = "N"; + for (Bookmark bookmark : store.getBookmarkList()) { + if (bookmark.getStoreId().getId() == store.getId() + && bookmark.getUserId().getSocialId().equals(socialId)) { + isBookmark = "Y"; + break; + } + } + result.add(new StoreCardResponseDto(store, isBookmark)); + } + } + return result; } } \ No newline at end of file