From de1c59c2ad4eb295b39cb5bd6444982bf5951c29 Mon Sep 17 00:00:00 2001 From: govl6113 Date: Thu, 22 Jun 2023 16:56:16 +0900 Subject: [PATCH] =?UTF-8?q?feat(store):=20=EC=A2=8C=ED=91=9C=20=EB=82=B4?= =?UTF-8?q?=20=EC=BC=80=EC=9D=B4=ED=81=AC=EC=83=B5=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84=20#31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/in/web/StoreController.java | 18 +++++++++++++ .../persistence/StorePersistenceAdapter.java | 27 ++++++++++++++++--- .../application/port/in/StoreUseCase.java | 6 +++++ .../application/port/out/LoadStorePort.java | 6 ++++- .../application/service/StoreService.java | 24 ++++++++++++++++- 5 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/StoreController.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/StoreController.java index 5d5025a..695db97 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/StoreController.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/StoreController.java @@ -39,6 +39,24 @@ public ResponseEntity> getList( return ResponseEntity.ok().body(this.storeUseCase.getList(district, page)); } + @Operation(description = "이 지역 재검색") + @GetMapping("/reload") + public ResponseEntity> reload( + @RequestParam(value = "page", required = false, defaultValue = "1") int page, + @RequestParam(value = "southwestLatitude", required = true) Double southwestLatitude, + @RequestParam(value = "southwestLongitude", required = true) Double southwestLongitude, + @RequestParam(value = "northeastLatitude", required = true) Double northeastLatitude, + @RequestParam(value = "northeastLongitude", required = true) Double northeastLongitude + ) { + return ResponseEntity.ok().body( + this.storeUseCase.reload( + page, + southwestLatitude, southwestLongitude, + northeastLatitude, northeastLongitude + ) + ); + } + @Operation(description = "케이크샵 상세 정보 조회(상세 정보만)") @GetMapping("/{id}") public ResponseEntity getStoreDetail(@PathVariable("id") Long storeId) { diff --git a/src/main/java/prography/cakeke/server/store/adapter/out/persistence/StorePersistenceAdapter.java b/src/main/java/prography/cakeke/server/store/adapter/out/persistence/StorePersistenceAdapter.java index 1d2cc6a..8d8ce33 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/out/persistence/StorePersistenceAdapter.java +++ b/src/main/java/prography/cakeke/server/store/adapter/out/persistence/StorePersistenceAdapter.java @@ -11,6 +11,7 @@ import org.springframework.stereotype.Repository; import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -46,13 +47,19 @@ public List getDistrictCount() { } @Override - public List getList(List district, Pageable pageable) { + public List getList( + List district, Pageable pageable, + Double southwestLatitude, Double southwestLongitude, + Double northeastLatitude, Double northeastLongitude + ) { return queryFactory .selectFrom(store) .leftJoin(store.storeAndTagList, storeAndTag) .leftJoin(storeAndTag.storeTag, storeTag) .where( - store.district.in(district) + storeDistrictIn(district), + storeLongitudeBetween(southwestLongitude, northeastLongitude), + storeLatitudeBetween(southwestLatitude, northeastLatitude) ) .distinct() .offset(pageable.getOffset()) @@ -89,4 +96,18 @@ public Map getStoreDetail(Long storeId) { public Optional getByName(String name) { return storeRepository.findByName(name); } -} + + private BooleanExpression storeDistrictIn(List district) { + return district != null ? store.district.in(district) : null; + } + + private BooleanExpression storeLongitudeBetween(Double southwestLongitude, Double northeastLongitude) { + return southwestLongitude != null || northeastLongitude != null ? + store.longitude.between(southwestLongitude, northeastLongitude) : null; + } + + private BooleanExpression storeLatitudeBetween(Double southwestLatitude, Double northeastLatitude) { + return southwestLatitude != null || northeastLatitude != null ? + store.latitude.between(southwestLatitude, northeastLatitude) : null; + } +} \ No newline at end of file diff --git a/src/main/java/prography/cakeke/server/store/application/port/in/StoreUseCase.java b/src/main/java/prography/cakeke/server/store/application/port/in/StoreUseCase.java index 2d585fd..33e705d 100644 --- a/src/main/java/prography/cakeke/server/store/application/port/in/StoreUseCase.java +++ b/src/main/java/prography/cakeke/server/store/application/port/in/StoreUseCase.java @@ -14,6 +14,12 @@ public interface StoreUseCase { List getList(List district, int page); + List reload( + int page, + Double southwestLatitude, Double southwestLongitude, + Double northeastLatitude, Double northeastLongitude + ); + StoreDetailResponse getStoreDetail(Long storeId); StoreBlogResponse getStoreBlog(Long storeId, Integer blogNum); diff --git a/src/main/java/prography/cakeke/server/store/application/port/out/LoadStorePort.java b/src/main/java/prography/cakeke/server/store/application/port/out/LoadStorePort.java index 23f98ab..fbc2a5e 100644 --- a/src/main/java/prography/cakeke/server/store/application/port/out/LoadStorePort.java +++ b/src/main/java/prography/cakeke/server/store/application/port/out/LoadStorePort.java @@ -14,7 +14,11 @@ public interface LoadStorePort { List getDistrictCount(); - List getList(List district, Pageable pageable); + List getList( + List district, Pageable pageable, + Double southwestLongitude, Double northeastLongitude, + Double southwestLatitude, Double northeastLatitude + ); Map getStoreDetail(Long storeId); diff --git a/src/main/java/prography/cakeke/server/store/application/service/StoreService.java b/src/main/java/prography/cakeke/server/store/application/service/StoreService.java index d775271..f242292 100644 --- a/src/main/java/prography/cakeke/server/store/application/service/StoreService.java +++ b/src/main/java/prography/cakeke/server/store/application/service/StoreService.java @@ -45,7 +45,29 @@ public List getCount() { */ @Override public List getList(List district, int page) { - return loadStorePort.getList(district, PageRequest.of(page - 1, 15)); + return loadStorePort.getList(district, PageRequest.of(page - 1, 100), null, null, null, null); + } + + /** + * 현재 화면의 남서쪽 위도, 경도, 북동쪽 위도, 경도를 받아 해당하는 가게 리스트를 반환합니다. + * @param page 페이지 번호 + * @param southwestLatitude 남서쪽 위도 + * @param southwestLongitude 남서쪽 경도 + * @param northeastLatitude 북동쪽 위도 + * @param northeastLongitude 북동쪽 경도 + * @return 가게 리스트 + */ + @Override + public List reload( + int page, + Double southwestLatitude, Double southwestLongitude, + Double northeastLatitude, Double northeastLongitude + ) { + return loadStorePort.getList( + null, PageRequest.of(page - 1, 100), + southwestLatitude, southwestLongitude, + northeastLatitude, northeastLongitude + ); } /**