From 4ed599fe3cc48980c6fe7d0d99b83b307c1a7d61 Mon Sep 17 00:00:00 2001 From: govl6113 Date: Thu, 27 Jul 2023 14:21:12 +0900 Subject: [PATCH 01/11] =?UTF-8?q?refactor(store):=20district=20=EB=B3=84?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EA=B2=8C=20=EA=B0=AF=EC=88=98=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C,=20querydsl=EC=97=90=EC=84=9C=20response?= =?UTF-8?q?=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20#30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/store/adapter/in/web/StoreController.java | 4 ++-- .../{DistrictCountResponse.java => DistrictCountDTO.java} | 2 +- .../in/web/response/StoreNaverLocalSearchApiResponse.java | 2 +- .../adapter/out/persistence/StorePersistenceAdapter.java | 7 +++---- .../server/store/application/port/in/StoreUseCase.java | 4 ++-- .../server/store/application/port/out/LoadStorePort.java | 4 ++-- .../server/store/application/service/StoreService.java | 4 ++-- 7 files changed, 13 insertions(+), 14 deletions(-) rename src/main/java/prography/cakeke/server/store/adapter/in/web/response/{DistrictCountResponse.java => DistrictCountDTO.java} (86%) 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 1e3aa4f..3977839 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 @@ -12,7 +12,7 @@ import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; -import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse; +import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.FeedImageResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreBlogResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreDetailResponse; @@ -31,7 +31,7 @@ public class StoreController { @Operation(description = "각 구별 가게 갯수 조회") @GetMapping("/district/count") - public ResponseEntity> getCount() { + public ResponseEntity> getCount() { return ResponseEntity.ok().body(this.storeUseCase.getCount()); } diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/DistrictCountResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/DistrictCountDTO.java similarity index 86% rename from src/main/java/prography/cakeke/server/store/adapter/in/web/response/DistrictCountResponse.java rename to src/main/java/prography/cakeke/server/store/adapter/in/web/response/DistrictCountDTO.java index 8e84b3c..ce99a74 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/DistrictCountResponse.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/DistrictCountDTO.java @@ -6,7 +6,7 @@ @Getter @NoArgsConstructor -public class DistrictCountResponse { +public class DistrictCountDTO { District district; diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreNaverLocalSearchApiResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreNaverLocalSearchApiResponse.java index 13ef15d..71d7e4b 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreNaverLocalSearchApiResponse.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreNaverLocalSearchApiResponse.java @@ -6,7 +6,7 @@ @Getter public class StoreNaverLocalSearchApiResponse { String link; // 가게 URL - + String description; // 가게 설명 String phoneNumber; // 가게 번호 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 c5a0c7a..59b0ebd 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 @@ -1,7 +1,6 @@ package prography.cakeke.server.store.adapter.out.persistence; import static com.querydsl.core.group.GroupBy.groupBy; -import static com.querydsl.core.group.GroupBy.list; import java.util.List; import java.util.Map; @@ -16,7 +15,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; -import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse; +import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.application.port.out.DeleteStorePort; import prography.cakeke.server.store.application.port.out.LoadStorePort; @@ -43,9 +42,9 @@ public class StorePersistenceAdapter implements LoadStorePort, SaveStorePort, De private final QStoreTag storeTag = QStoreTag.storeTag; @Override - public List getDistrictCount() { + public List getDistrictCount() { return queryFactory - .select(Projections.fields(DistrictCountResponse.class, + .select(Projections.fields(DistrictCountDTO.class, store.district, store.id.count().as("count") )) 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 71628fd..8063e71 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 @@ -2,7 +2,7 @@ import java.util.List; -import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse; +import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverBlogSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverLocalSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; @@ -12,7 +12,7 @@ import prography.cakeke.server.store.domain.StoreType; public interface StoreUseCase { - List getCount(); + List getCount(); List getList(List district, List storeTypes, int page); 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 7b1ce9e..812c7f2 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 @@ -6,7 +6,7 @@ import org.springframework.data.domain.Pageable; -import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse; +import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.domain.District; import prography.cakeke.server.store.domain.Store; @@ -14,7 +14,7 @@ import prography.cakeke.server.store.domain.StoreType; public interface LoadStorePort { - List getDistrictCount(); + List getDistrictCount(); List getList( List district, List storeTypes, Pageable pageable, 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 fe06094..621408d 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 @@ -7,7 +7,7 @@ import org.springframework.transaction.annotation.Transactional; import lombok.RequiredArgsConstructor; -import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse; +import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverBlogSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverLocalSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; @@ -39,7 +39,7 @@ public class StoreService implements StoreUseCase { * @return 각 구별 가게의 개수 */ @Override - public List getCount() { + public List getCount() { return loadStorePort.getDistrictCount(); } From f7f21ad4618e5569e1827046e9239cd9530c4434 Mon Sep 17 00:00:00 2001 From: govl6113 Date: Thu, 27 Jul 2023 23:09:17 +0900 Subject: [PATCH 02/11] =?UTF-8?q?refactor(store):=20feed=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=EB=A5=BC=20=EC=99=84=EC=A0=84=20=EB=9E=9C?= =?UTF-8?q?=EB=8D=A4=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20#53?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/in/web/StoreController.java | 19 +++++++------------ .../in/web/response/FeedImageResponse.java | 9 ++++++++- .../persistence/StorePersistenceAdapter.java | 2 -- 3 files changed, 15 insertions(+), 15 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 1e3aa4f..b4fed6f 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 @@ -1,5 +1,6 @@ package prography.cakeke.server.store.adapter.in.web; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -80,27 +81,21 @@ public ResponseEntity getStoreType(@PathVariable(value = "id") @Operation(description = "feed로 케이크 이미지 조회") @GetMapping("/feed") public ResponseEntity> getFeedImage( - @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 + @RequestParam(value = "page", required = false, defaultValue = "1") int page ) { - List stores = this.storeUseCase.reload( - null, page, - southwestLatitude, southwestLongitude, - northeastLatitude, northeastLongitude - ); + List stores = this.storeUseCase.getList(null, null, page); List response = stores .stream().flatMap( store -> store.getImageUrls() .stream().map( - imageUrl -> new FeedImageResponse(store.getId(), imageUrl) + imageUrl -> new FeedImageResponse( + store.getId(), store.getName(), store.getDistrict(), imageUrl) ) ) .collect(Collectors.toList()); - + + Collections.shuffle(response); return ResponseEntity.ok().body(response); } diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/FeedImageResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/FeedImageResponse.java index ff1a539..730934a 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/FeedImageResponse.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/FeedImageResponse.java @@ -2,17 +2,24 @@ import lombok.Builder; import lombok.Getter; +import prography.cakeke.server.store.domain.District; @Getter public class FeedImageResponse { Long storeId; + String storeName; + + District district; + String imageUrl; @Builder - public FeedImageResponse(Long storeId, String imageUrl) { + public FeedImageResponse(Long storeId, String storeName, District district, String imageUrl) { this.storeId = storeId; + this.storeName = storeName; + this.district = district; this.imageUrl = imageUrl; } } 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 c5a0c7a..69caba9 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 @@ -1,7 +1,6 @@ package prography.cakeke.server.store.adapter.out.persistence; import static com.querydsl.core.group.GroupBy.groupBy; -import static com.querydsl.core.group.GroupBy.list; import java.util.List; import java.util.Map; @@ -71,7 +70,6 @@ public List getList( .distinct() .offset(pageable.getOffset()) .limit(pageable.getPageSize()) - .orderBy(store.id.asc()) .fetch(); } From dd28d7f5319ebf40a15230864ed750c3b91a74f4 Mon Sep 17 00:00:00 2001 From: ympark99 Date: Fri, 28 Jul 2023 10:44:45 +0900 Subject: [PATCH 03/11] =?UTF-8?q?style(store):=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/application/service/StoreService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 621408d..9567a41 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 @@ -97,17 +97,32 @@ public List getStoreTypeByStoreId(Long storeId) { return loadStorePort.getStoreTagByStoreId(storeId); } + /** + * 가게 아이디를 받아 가게 정보를 반환합니다. + * @param storeId 가게 아이디 + * @return 가게 정보 + */ @Override public StoreResponse getStore(Long storeId) { return loadStorePort.getStore(storeId).get(storeId); } + /** + * 가게 정보를 받아 해당 가게의 네이버 지역 검색 결과를 반환합니다. + * @param store 가게 + * @return 네이버 지역 검색 결과 + */ @Override public StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(StoreResponse storeResponse) { final String storeName = storeResponse.getName(); return loadNaverSearchApiPort.getNaverLocalSearchResponse(storeName); } + /** + * 가게 Id와 원하는 블로그 개수를 받아 해당 가게의 네이버 블로그 검색 결과를 반환합니다. + * @param storeId 가게 Id, blogNum 보여줄 블로그 개수 + * @return 네이버 블로그 검색 결과 + */ @Override public List getNaverBlogApiByStore(Long storeId, Integer blogNum) { StoreResponse storeResponse = loadStorePort.getStore(storeId).get(storeId); From d0ebe3c7d3830ec0afc25d171a69653e1211d5d8 Mon Sep 17 00:00:00 2001 From: ympark99 Date: Fri, 28 Jul 2023 11:22:01 +0900 Subject: [PATCH 04/11] =?UTF-8?q?refactor(store):=20StoreResponse=20Store?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20DistrictCountDTO=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/in/web/StoreController.java | 6 ++-- .../in/web/response/StoreDetailResponse.java | 36 +++++++++++-------- .../persistence/StorePersistenceAdapter.java | 18 ++-------- .../application/port/in/StoreUseCase.java | 5 ++- .../application/port/out/LoadStorePort.java | 4 +-- .../application/service/StoreService.java | 13 ++++--- .../application/service/StoreServiceTest.java | 27 +++++++------- 7 files changed, 50 insertions(+), 59 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 3977839..a1b7471 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 @@ -107,10 +107,10 @@ public ResponseEntity> getFeedImage( @Operation(description = "케이크샵 상세 정보 조회(상세 정보만)") @GetMapping("/{id}") public ResponseEntity getStoreDetail(@PathVariable("id") Long storeId) { - StoreResponse storeResponse = this.storeUseCase.getStore(storeId); + Store store = this.storeUseCase.getStore(storeId); return ResponseEntity.ok().body( - new StoreDetailResponse(storeResponse, - this.storeUseCase.getNaverLocalApiByStore(storeResponse))); + new StoreDetailResponse(store, + this.storeUseCase.getNaverLocalApiByStore(store))); } @Operation(description = "케이크샵 블로그 정보 조회") diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java index 3989d36..9b88249 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java @@ -2,12 +2,16 @@ import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Collectors; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import prography.cakeke.server.store.domain.City; import prography.cakeke.server.store.domain.District; +import prography.cakeke.server.store.domain.Store; +import prography.cakeke.server.store.domain.StoreAndTag; +import prography.cakeke.server.store.domain.StoreTag; import prography.cakeke.server.store.domain.StoreType; @Getter @@ -49,21 +53,25 @@ public class StoreDetailResponse { @Builder public StoreDetailResponse( - StoreResponse storeResponse, StoreNaverLocalSearchApiResponse storeNaverLocalSearchApiResponse + Store store, StoreNaverLocalSearchApiResponse storeNaverLocalSearchApiResponse ) { - this.id = storeResponse.getId(); - this.createdAt = storeResponse.getCreatedAt(); - this.modifiedAt = storeResponse.getModifiedAt(); - this.name = storeResponse.getName(); - this.shareLink = storeResponse.getShareLink(); - this.city = storeResponse.getCity(); - this.district = storeResponse.getDistrict(); - this.location = storeResponse.getLocation(); - this.latitude = storeResponse.getLatitude(); - this.longitude = storeResponse.getLongitude(); - this.storeTypes = storeResponse.getStoreTypes(); - this.thumbnail = storeResponse.getThumbnail(); - this.imageUrls = storeResponse.getImageUrls(); + List storeTagList = store.getStoreAndTags().stream().map(StoreAndTag::getStoreTag).toList(); + + this.id = store.getId(); + this.createdAt = store.getCreatedAt(); + this.modifiedAt = store.getModifiedAt(); + this.name = store.getName(); + this.shareLink = store.getShareLink(); + this.city = store.getCity(); + this.district = store.getDistrict(); + this.location = store.getLocation(); + this.latitude = store.getLatitude(); + this.longitude = store.getLongitude(); + this.storeTypes = storeTagList != null ? + storeTagList.stream().map(StoreTag::getStoreType).collect(Collectors.toList()) + : List.of(); + this.thumbnail = store.getThumbnail(); + this.imageUrls = store.getImageUrls(); this.link = storeNaverLocalSearchApiResponse.getLink(); this.description = storeNaverLocalSearchApiResponse.getDescription(); this.phoneNumber = storeNaverLocalSearchApiResponse.getPhoneNumber(); 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 59b0ebd..2b8456a 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 @@ -1,9 +1,6 @@ package prography.cakeke.server.store.adapter.out.persistence; -import static com.querydsl.core.group.GroupBy.groupBy; - import java.util.List; -import java.util.Map; import java.util.Optional; import org.springframework.data.domain.Pageable; @@ -16,7 +13,6 @@ import lombok.RequiredArgsConstructor; import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; -import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.application.port.out.DeleteStorePort; import prography.cakeke.server.store.application.port.out.LoadStorePort; import prography.cakeke.server.store.application.port.out.SaveStorePort; @@ -75,21 +71,13 @@ public List getList( } @Override - public Map getStore(Long storeId) { + public Store getStore(Long storeId) { return queryFactory - .select(store) - .from(store) + .selectFrom(store) .leftJoin(store.storeAndTags, storeAndTag) .leftJoin(storeAndTag.storeTag, storeTag) .where(store.id.eq(storeId)) - .transform( - groupBy(store.id).as( - Projections.constructor(StoreResponse.class, - store, - list(storeTag) - ) - ) - ); + .fetchOne(); } @Override 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 8063e71..7c555b4 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 @@ -5,7 +5,6 @@ import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverBlogSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverLocalSearchApiResponse; -import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.domain.District; import prography.cakeke.server.store.domain.Store; import prography.cakeke.server.store.domain.StoreTag; @@ -24,9 +23,9 @@ List reload( List getStoreTypeByStoreId(Long storeId); - StoreResponse getStore(Long storeId); + Store getStore(Long storeId); - StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(StoreResponse storeResponse); + StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(Store store); List getNaverBlogApiByStore(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 812c7f2..b19fcc1 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 @@ -1,13 +1,11 @@ package prography.cakeke.server.store.application.port.out; import java.util.List; -import java.util.Map; import java.util.Optional; import org.springframework.data.domain.Pageable; import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; -import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.domain.District; import prography.cakeke.server.store.domain.Store; import prography.cakeke.server.store.domain.StoreTag; @@ -22,7 +20,7 @@ List getList( Double southwestLatitude, Double northeastLatitude ); - Map getStore(Long storeId); + Store getStore(Long storeId); Optional getByName(String name); 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 9567a41..80afc4b 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 @@ -10,7 +10,6 @@ import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverBlogSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverLocalSearchApiResponse; -import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.application.port.in.StoreUseCase; import prography.cakeke.server.store.application.port.out.LoadNaverSearchApiPort; import prography.cakeke.server.store.application.port.out.LoadStorePort; @@ -103,8 +102,8 @@ public List getStoreTypeByStoreId(Long storeId) { * @return 가게 정보 */ @Override - public StoreResponse getStore(Long storeId) { - return loadStorePort.getStore(storeId).get(storeId); + public Store getStore(Long storeId) { + return loadStorePort.getStore(storeId); } /** @@ -113,8 +112,8 @@ public StoreResponse getStore(Long storeId) { * @return 네이버 지역 검색 결과 */ @Override - public StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(StoreResponse storeResponse) { - final String storeName = storeResponse.getName(); + public StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(Store store) { + final String storeName = store.getName(); return loadNaverSearchApiPort.getNaverLocalSearchResponse(storeName); } @@ -125,8 +124,8 @@ public StoreNaverLocalSearchApiResponse getNaverLocalApiByStore(StoreResponse st */ @Override public List getNaverBlogApiByStore(Long storeId, Integer blogNum) { - StoreResponse storeResponse = loadStorePort.getStore(storeId).get(storeId); - final String storeName = storeResponse.getName(); + Store store = loadStorePort.getStore(storeId); + final String storeName = store.getName(); return loadNaverSearchApiPort.getNaverBlogSearchResponse(storeName, blogNum); } diff --git a/src/test/java/prography/cakeke/server/store/application/service/StoreServiceTest.java b/src/test/java/prography/cakeke/server/store/application/service/StoreServiceTest.java index e4ef5cb..0666361 100644 --- a/src/test/java/prography/cakeke/server/store/application/service/StoreServiceTest.java +++ b/src/test/java/prography/cakeke/server/store/application/service/StoreServiceTest.java @@ -11,10 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired; import prography.cakeke.server.common.BaseMock; -import prography.cakeke.server.store.adapter.in.web.response.DistrictCountResponse; +import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverBlogSearchApiResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreNaverLocalSearchApiResponse; -import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.adapter.out.persistence.StoreAndTagRepository; import prography.cakeke.server.store.adapter.out.persistence.StoreRepository; import prography.cakeke.server.store.adapter.out.persistence.StoreTagRepository; @@ -62,7 +61,7 @@ void setup() { @Test @DisplayName("각 구의 개수 반환(성공)") public void getCountTestSuccess() { - List districtCountResponseList = storeService.getCount(); + List districtCountResponseList = storeService.getCount(); assertThat((long) districtCountResponseList.size()).isEqualTo(1L); } @@ -126,24 +125,24 @@ public void getStoreTypeByStoreIdTestSuccess() { @DisplayName("가게 조회(성공)") public void getStoreByStoreIdTestSuccess() { Long testStoreId = storeRepository.findByName(testName).get().getId(); - StoreResponse testStoreResponse = storeService.getStore(testStoreId); - - assertThat(testStoreResponse.getCity()).isEqualTo(testCity); - assertThat(testStoreResponse.getDistrict()).isEqualTo(testDistrict); - assertThat(testStoreResponse.getLatitude()).isEqualTo(testLatitude); - assertThat(testStoreResponse.getLocation()).isEqualTo(testLocation); - assertThat(testStoreResponse.getLongitude()).isEqualTo(testLongitude); - assertThat(testStoreResponse.getName()).isEqualTo(testName); - assertThat(testStoreResponse.getShareLink()).isEqualTo(testShareLink); + Store testStore = storeService.getStore(testStoreId); + + assertThat(testStore.getCity()).isEqualTo(testCity); + assertThat(testStore.getDistrict()).isEqualTo(testDistrict); + assertThat(testStore.getLatitude()).isEqualTo(testLatitude); + assertThat(testStore.getLocation()).isEqualTo(testLocation); + assertThat(testStore.getLongitude()).isEqualTo(testLongitude); + assertThat(testStore.getName()).isEqualTo(testName); + assertThat(testStore.getShareLink()).isEqualTo(testShareLink); } @Test @DisplayName("네이버 로컬 API 조회 테스트(성공)") public void getNaverLocalApiTestSuccess() { Long testStoreId = storeRepository.findByName(testNaverStoreName).get().getId(); - StoreResponse testStoreResponse = storeService.getStore(testStoreId); + Store testStore = storeService.getStore(testStoreId); StoreNaverLocalSearchApiResponse testStoreNaverLocalSearchApiResponse = - storeService.getNaverLocalApiByStore(testStoreResponse); + storeService.getNaverLocalApiByStore(testStore); assertThat(testStoreNaverLocalSearchApiResponse.getAddress()).isEqualTo(testNaverStoreAddress); } From e04cd5a3f8bb789d3f782e5dc5a9fe030204d976 Mon Sep 17 00:00:00 2001 From: ympark99 Date: Fri, 28 Jul 2023 11:23:23 +0900 Subject: [PATCH 05/11] =?UTF-8?q?refactor(store):=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/in/web/StoreController.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 a1b7471..1bce6e1 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 @@ -54,10 +54,10 @@ public ResponseEntity> getList( public ResponseEntity> reload( @RequestParam(value = "storeTypes", required = false) List storeTypes, @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 + @RequestParam(value = "southwestLatitude") Double southwestLatitude, + @RequestParam(value = "southwestLongitude") Double southwestLongitude, + @RequestParam(value = "northeastLatitude") Double northeastLatitude, + @RequestParam(value = "northeastLongitude") Double northeastLongitude ) { return ResponseEntity.ok().body( this.storeUseCase.reload( @@ -81,10 +81,10 @@ public ResponseEntity getStoreType(@PathVariable(value = "id") @GetMapping("/feed") public ResponseEntity> getFeedImage( @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 + @RequestParam(value = "southwestLatitude") Double southwestLatitude, + @RequestParam(value = "southwestLongitude") Double southwestLongitude, + @RequestParam(value = "northeastLatitude") Double northeastLatitude, + @RequestParam(value = "northeastLongitude") Double northeastLongitude ) { List stores = this.storeUseCase.reload( null, page, From 75495fc421c28a006960b97c0aa056dcb9c4fec1 Mon Sep 17 00:00:00 2001 From: ympark99 Date: Fri, 28 Jul 2023 11:42:38 +0900 Subject: [PATCH 06/11] =?UTF-8?q?refactor(store):=20=EC=B6=A9=EB=8F=8C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20#30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/in/web/StoreController.java | 16 ++++++++-------- .../in/web/response/StoreDetailResponse.java | 7 +++---- 2 files changed, 11 insertions(+), 12 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 1e41662..1d83f58 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 @@ -55,10 +55,10 @@ public ResponseEntity> getList( public ResponseEntity> reload( @RequestParam(value = "storeTypes", required = false) List storeTypes, @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 + @RequestParam(value = "southwestLatitude") Double southwestLatitude, + @RequestParam(value = "southwestLongitude") Double southwestLongitude, + @RequestParam(value = "northeastLatitude") Double northeastLatitude, + @RequestParam(value = "northeastLongitude") Double northeastLongitude ) { return ResponseEntity.ok().body( this.storeUseCase.reload( @@ -94,7 +94,7 @@ public ResponseEntity> getFeedImage( ) ) .collect(Collectors.toList()); - + Collections.shuffle(response); return ResponseEntity.ok().body(response); } @@ -102,10 +102,10 @@ public ResponseEntity> getFeedImage( @Operation(description = "케이크샵 상세 정보 조회(상세 정보만)") @GetMapping("/{id}") public ResponseEntity getStoreDetail(@PathVariable("id") Long storeId) { - StoreResponse storeResponse = this.storeUseCase.getStore(storeId); + Store store = this.storeUseCase.getStore(storeId); return ResponseEntity.ok().body( - new StoreDetailResponse(storeResponse, - this.storeUseCase.getNaverLocalApiByStore(storeResponse))); + new StoreDetailResponse(store, + this.storeUseCase.getNaverLocalApiByStore(store))); } @Operation(description = "케이크샵 블로그 정보 조회") diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java index 9b88249..9d443b4 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreDetailResponse.java @@ -56,7 +56,9 @@ public StoreDetailResponse( Store store, StoreNaverLocalSearchApiResponse storeNaverLocalSearchApiResponse ) { List storeTagList = store.getStoreAndTags().stream().map(StoreAndTag::getStoreTag).toList(); - + this.storeTypes = storeTagList != null ? + storeTagList.stream().map(StoreTag::getStoreType).collect(Collectors.toList()) + : List.of(); this.id = store.getId(); this.createdAt = store.getCreatedAt(); this.modifiedAt = store.getModifiedAt(); @@ -67,9 +69,6 @@ public StoreDetailResponse( this.location = store.getLocation(); this.latitude = store.getLatitude(); this.longitude = store.getLongitude(); - this.storeTypes = storeTagList != null ? - storeTagList.stream().map(StoreTag::getStoreType).collect(Collectors.toList()) - : List.of(); this.thumbnail = store.getThumbnail(); this.imageUrls = store.getImageUrls(); this.link = storeNaverLocalSearchApiResponse.getLink(); From fd9334240f27b1c3725de7464bd7391bdb2e47ff Mon Sep 17 00:00:00 2001 From: govl6113 Date: Sun, 30 Jul 2023 21:09:49 +0900 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20persistence=20adapter=EC=9D=98=20q?= =?UTF-8?q?uerydsl=20import=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/out/persistence/StorePersistenceAdapter.java | 1 + 1 file changed, 1 insertion(+) 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 c551878..53a78db 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 @@ -1,6 +1,7 @@ package prography.cakeke.server.store.adapter.out.persistence; import static com.querydsl.core.group.GroupBy.groupBy; +import static com.querydsl.core.group.GroupBy.list; import java.util.List; import java.util.Map; From cc2e8b2f3082a081faee570ceb61495e9ac34dac Mon Sep 17 00:00:00 2001 From: ympark99 Date: Tue, 1 Aug 2023 20:26:39 +0900 Subject: [PATCH 08/11] =?UTF-8?q?refactor(store):=20N+1=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0=20#30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/out/persistence/StorePersistenceAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 40fd355..feab1ab 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 @@ -73,8 +73,8 @@ public List getList( public Store getStore(Long storeId) { return queryFactory .selectFrom(store) - .leftJoin(store.storeAndTags, storeAndTag) - .leftJoin(storeAndTag.storeTag, storeTag) + .leftJoin(store.storeAndTags, storeAndTag).fetchJoin() + .leftJoin(storeAndTag.storeTag, storeTag).fetchJoin() .where(store.id.eq(storeId)) .fetchOne(); } From 348b8546718b24c57710a39630f0d4e9c8753369 Mon Sep 17 00:00:00 2001 From: govl6113 Date: Sat, 5 Aug 2023 21:45:22 +0900 Subject: [PATCH 09/11] =?UTF-8?q?feat(store):=20store=20bookmark=20?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C,=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=A3=BC=EB=8A=94=20api=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/in/web/StoreController.java | 7 +++++ .../web/response/StoreBookmarkResponse.java | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java 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 1d83f58..9b5654a 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 @@ -16,6 +16,7 @@ import prography.cakeke.server.store.adapter.in.web.response.DistrictCountDTO; import prography.cakeke.server.store.adapter.in.web.response.FeedImageResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreBlogResponse; +import prography.cakeke.server.store.adapter.in.web.response.StoreBookmarkResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreDetailResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreResponse; import prography.cakeke.server.store.adapter.in.web.response.StoreTagResponse; @@ -116,4 +117,10 @@ public ResponseEntity getStoreBlog( return ResponseEntity.ok().body( new StoreBlogResponse(this.storeUseCase.getNaverBlogApiByStore(storeId, blogNum))); } + + @Operation(description = "북마크 가게 조회") + @GetMapping("/{id}/bookmark") + public ResponseEntity getStoreBookmark(@PathVariable(value = "id") Long storeId) { + return ResponseEntity.ok().body(new StoreBookmarkResponse(this.storeUseCase.getStore(storeId))); + } } diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java new file mode 100644 index 0000000..83a9c2d --- /dev/null +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java @@ -0,0 +1,31 @@ +package prography.cakeke.server.store.adapter.in.web.response; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import prography.cakeke.server.store.domain.District; +import prography.cakeke.server.store.domain.Store; + +@Getter +@AllArgsConstructor +public class StoreBookmarkResponse { + + Long id; + + String name; + + District district; + + String location; + + List imageUrls; + + public StoreBookmarkResponse(Store store) { + this.id = store.getId(); + this.name = store.getName(); + this.district = store.getDistrict(); + this.location = store.getLocation(); + this.imageUrls = store.getImageUrls()!=null? store.getImageUrls() : List.of(); + } +} \ No newline at end of file From 2e4517ab2daf8f55ea313d3d366db6c71b691fb2 Mon Sep 17 00:00:00 2001 From: ympark99 Date: Mon, 7 Aug 2023 16:32:01 +0900 Subject: [PATCH 10/11] =?UTF-8?q?refactor(store):=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B2=84=20=EB=B8=94=EB=A1=9C=EA=B7=B8=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EA=B0=92=20=EA=B3=A0=EC=A0=95=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/adapter/out/external/NaverSearchApiAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/prography/cakeke/server/store/adapter/out/external/NaverSearchApiAdapter.java b/src/main/java/prography/cakeke/server/store/adapter/out/external/NaverSearchApiAdapter.java index 8eaacff..239fcc6 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/out/external/NaverSearchApiAdapter.java +++ b/src/main/java/prography/cakeke/server/store/adapter/out/external/NaverSearchApiAdapter.java @@ -108,7 +108,7 @@ public List getNaverBlogSearchResponse(String s * sim: 정확도순으로 내림차순 정렬(기본값) * date: 날짜순으로 내림차순 정렬 * */ - final String sortType = "sim"; + final String sortType = "date"; JSONArray responseJson = getNaverSearchApiResponse(storeName, blogNum, sortType, blogPath); List storeNaverBlogSearchApiResponseList = new ArrayList<>(); From d288f137caebd7605281480aaa632adb1ed695a9 Mon Sep 17 00:00:00 2001 From: govl6113 Date: Mon, 7 Aug 2023 16:38:04 +0900 Subject: [PATCH 11/11] =?UTF-8?q?refactor(store):=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20api=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prography/cakeke/server/TestController.java | 14 -------------- .../in/web/response/StoreBookmarkResponse.java | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 src/main/java/prography/cakeke/server/TestController.java diff --git a/src/main/java/prography/cakeke/server/TestController.java b/src/main/java/prography/cakeke/server/TestController.java deleted file mode 100644 index 91d2d2e..0000000 --- a/src/main/java/prography/cakeke/server/TestController.java +++ /dev/null @@ -1,14 +0,0 @@ -package prography.cakeke.server; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/api") -public class TestController { - @GetMapping("/test") - public String test() { - return "test"; - } -} diff --git a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java index 83a9c2d..e11a06b 100644 --- a/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java +++ b/src/main/java/prography/cakeke/server/store/adapter/in/web/response/StoreBookmarkResponse.java @@ -26,6 +26,6 @@ public StoreBookmarkResponse(Store store) { this.name = store.getName(); this.district = store.getDistrict(); this.location = store.getLocation(); - this.imageUrls = store.getImageUrls()!=null? store.getImageUrls() : List.of(); + this.imageUrls = store.getImageUrls() != null ? store.getImageUrls() : List.of(); } } \ No newline at end of file