diff --git a/src/docs/asciidoc/search.adoc b/src/docs/asciidoc/search.adoc index 044e0042..a8150047 100644 --- a/src/docs/asciidoc/search.adoc +++ b/src/docs/asciidoc/search.adoc @@ -32,3 +32,4 @@ operation::v1/search-engine/document/bread[snippets='http-request,request-parame === 빵집명으로 검색 테스트 API [GET] operation::v1/search-engine/document/bakery[snippets='http-request,request-parameters,http-response,response-fields'] + diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/admin/bakery/AdminBakeryServiceImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/admin/bakery/AdminBakeryServiceImpl.java index b6cc2912..bf4571ea 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/admin/bakery/AdminBakeryServiceImpl.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/admin/bakery/AdminBakeryServiceImpl.java @@ -1,41 +1,6 @@ package com.depromeet.breadmapbackend.domain.admin.bakery; -import java.security.SecureRandom; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import com.depromeet.breadmapbackend.domain.search.dto.OpenSearchIndex; -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BreadLoadData; -import com.depromeet.breadmapbackend.domain.search.events.OpenSearchEventPublisher; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminBakeryAlarmBar; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminBakeryDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminBakeryIsNewDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminImageBarDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminImageDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminImageRegisterRequest; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminProductDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminSimpleBakeryDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryAddDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryAddRequest; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryLocationDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryProductsDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryUpdateReportDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryUpdateRequest; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.NewReviewDto; -import com.depromeet.breadmapbackend.domain.admin.bakery.dto.ProductAddReportDto; +import com.depromeet.breadmapbackend.domain.admin.bakery.dto.*; import com.depromeet.breadmapbackend.domain.admin.bakery.param.AdminBakeryFilter; import com.depromeet.breadmapbackend.domain.admin.bakery.param.AdminBakeryImageType; import com.depromeet.breadmapbackend.domain.bakery.Bakery; @@ -48,19 +13,16 @@ import com.depromeet.breadmapbackend.domain.bakery.product.report.ProductAddReportImage; import com.depromeet.breadmapbackend.domain.bakery.product.report.ProductAddReportImageRepository; import com.depromeet.breadmapbackend.domain.bakery.product.report.ProductAddReportRepository; -import com.depromeet.breadmapbackend.domain.bakery.report.BakeryAddReport; -import com.depromeet.breadmapbackend.domain.bakery.report.BakeryAddReportRepository; -import com.depromeet.breadmapbackend.domain.bakery.report.BakeryReportImage; -import com.depromeet.breadmapbackend.domain.bakery.report.BakeryReportImageRepository; -import com.depromeet.breadmapbackend.domain.bakery.report.BakeryUpdateReport; -import com.depromeet.breadmapbackend.domain.bakery.report.BakeryUpdateReportRepository; +import com.depromeet.breadmapbackend.domain.bakery.report.*; import com.depromeet.breadmapbackend.domain.notice.dto.NoticeEventDto; import com.depromeet.breadmapbackend.domain.notice.factory.NoticeType; -import com.depromeet.breadmapbackend.domain.review.Review; -import com.depromeet.breadmapbackend.domain.review.ReviewImage; -import com.depromeet.breadmapbackend.domain.review.ReviewImageRepository; -import com.depromeet.breadmapbackend.domain.review.ReviewProductRatingRepository; -import com.depromeet.breadmapbackend.domain.review.ReviewRepository; +import com.depromeet.breadmapbackend.domain.review.*; +import com.depromeet.breadmapbackend.domain.search.dto.OpenSearchIndex; +import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; +import com.depromeet.breadmapbackend.domain.search.dto.keyword.BreadLoadData; +import com.depromeet.breadmapbackend.domain.search.events.BakeryCreationEvent; +import com.depromeet.breadmapbackend.domain.search.events.BreadCreationEvent; +import com.depromeet.breadmapbackend.domain.search.events.BakeryDeletionEvent; import com.depromeet.breadmapbackend.domain.user.User; import com.depromeet.breadmapbackend.global.S3Uploader; import com.depromeet.breadmapbackend.global.dto.PageResponseDto; @@ -73,9 +35,23 @@ import com.depromeet.breadmapbackend.global.infra.feign.sgis.dto.SgisTranscoordDto; import com.depromeet.breadmapbackend.global.infra.properties.CustomAWSS3Properties; import com.depromeet.breadmapbackend.global.infra.properties.CustomSGISKeyProperties; - import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import java.security.SecureRandom; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; @Slf4j @Service @@ -95,7 +71,6 @@ public class AdminBakeryServiceImpl implements AdminBakeryService { private final S3Uploader s3Uploader; private final SgisClient sgisClient; private final ApplicationEventPublisher eventPublisher; - private final OpenSearchEventPublisher openSearchEventPublisher; private final CustomSGISKeyProperties customSGISKeyProperties; private final CustomAWSS3Properties customAWSS3Properties; private final UpdateBakerySQSService updateBakerySQSService; // TODO : migrate to AOP @@ -242,7 +217,8 @@ public BakeryAddDto addBakery(BakeryAddRequest request) { .build() ); - openSearchEventPublisher.publishSaveBakery(new BakeryLoadData(bakery.getId(), bakery.getName(), bakery.getAddress(), bakery.getLongitude(), bakery.getLatitude())); + BakeryCreationEvent publishSaveBakery = new BakeryCreationEvent(this, new BakeryLoadData(bakery.getId(), bakery.getName(), bakery.getAddress(), bakery.getLongitude(), bakery.getLatitude())); + eventPublisher.publishEvent(publishSaveBakery); } return BakeryAddDto.builder().bakeryId(bakery.getId()).build(); @@ -257,9 +233,12 @@ public void updateBakery(Long bakeryId, BakeryUpdateRequest request) { BakeryStatus status = request.getStatus(); if(status == BakeryStatus.POSTING) { - openSearchEventPublisher.publishSaveBakery(new BakeryLoadData(bakery.getId(), bakery.getName(), bakery.getAddress(), bakery.getLongitude(), bakery.getLatitude())); + BakeryCreationEvent publishSaveBakery = new BakeryCreationEvent(this, new BakeryLoadData(bakery.getId(), bakery.getName(), bakery.getAddress(), bakery.getLongitude(), bakery.getLatitude())); + eventPublisher.publishEvent(publishSaveBakery); + } else if(status == BakeryStatus.UNPOSTING) { - openSearchEventPublisher.publishDeleteBakery(bakeryId); + BakeryDeletionEvent publishDeleteBakery = new BakeryDeletionEvent(this, OpenSearchIndex.BAKERY_SEARCH, bakeryId); + eventPublisher.publishEvent(publishDeleteBakery); } bakery.update(request.getName(), @@ -271,7 +250,8 @@ public void updateBakery(Long bakeryId, BakeryUpdateRequest request) { request.getFacilityInfoList(), status); if (request.getProductList() != null && !request.getProductList().isEmpty()) { // TODO - openSearchEventPublisher.publishDeleteAllProducts(bakeryId); + BakeryDeletionEvent publishDeleteBakery = new BakeryDeletionEvent(this, OpenSearchIndex.BAKERY_SEARCH, bakeryId); + eventPublisher.publishEvent(publishDeleteBakery); for (BakeryUpdateRequest.ProductUpdateRequest productUpdateRequest : request.getProductList()) { Product product; if (productUpdateRequest.getProductId() == null) { // 새로운 product 일 때 @@ -289,7 +269,8 @@ public void updateBakery(Long bakeryId, BakeryUpdateRequest request) { productUpdateRequest.getPrice(), productUpdateRequest.getImage()); } - openSearchEventPublisher.publishSaveBread(new BreadLoadData(product.getId(), product.getName(), bakeryId, bakery.getName(), bakery.getAddress(), bakery.getLongitude(), bakery.getLatitude())); + BreadCreationEvent publishSaveBread = new BreadCreationEvent(this, new BreadLoadData(product.getId(), product.getName(), bakeryId, bakery.getName(), bakery.getAddress(), bakery.getLongitude(), bakery.getLatitude())); + eventPublisher.publishEvent(publishSaveBread); } } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/HotKeywordService.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/HotKeywordService.java new file mode 100644 index 00000000..b1b0cc37 --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/HotKeywordService.java @@ -0,0 +1,10 @@ +package com.depromeet.breadmapbackend.domain.search; + +import com.depromeet.breadmapbackend.domain.admin.search.HotKeyword; + +import java.util.List; + +public interface HotKeywordService { + List getHotKeywordsRanking(); + +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/HotKeywordServiceImpl.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/HotKeywordServiceImpl.java new file mode 100644 index 00000000..5fa2eddc --- /dev/null +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/HotKeywordServiceImpl.java @@ -0,0 +1,19 @@ +package com.depromeet.breadmapbackend.domain.search; + +import com.depromeet.breadmapbackend.domain.admin.search.HotKeyword; +import com.depromeet.breadmapbackend.domain.admin.search.HotKeywordRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class HotKeywordServiceImpl implements HotKeywordService { + + private final HotKeywordRepository hotKeywordRepository; + @Override + public List getHotKeywordsRanking() { + return hotKeywordRepository.findAllByOrderByRankingAsc(); + } +} diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/SearchV2Controller.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/SearchV2Controller.java index 048f26ed..4eb601db 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/SearchV2Controller.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/SearchV2Controller.java @@ -1,5 +1,7 @@ package com.depromeet.breadmapbackend.domain.search; +import com.depromeet.breadmapbackend.domain.admin.search.Mapper; +import com.depromeet.breadmapbackend.domain.admin.search.dto.HotKeywordResponse; import com.depromeet.breadmapbackend.domain.search.dto.SearchType; import com.depromeet.breadmapbackend.domain.search.dto.keyword.response.KeywordSuggestionResponse; import com.depromeet.breadmapbackend.domain.search.dto.keyword.response.RecentKeywords; @@ -24,6 +26,7 @@ public class SearchV2Controller { private final SearchService searchService; private final SearchLogService searchLogService; + private final HotKeywordService hotKeywordService; @GetMapping("/keyword") @ResponseStatus(HttpStatus.OK) @@ -58,4 +61,15 @@ public ApiResponse searchKeywordSuggestions(@RequestP List keywordSuggestions = searchService.searchKeywordSuggestions(keyword); return new ApiResponse<>(KeywordSuggestionResponse.builder().keywordSuggestions(keywordSuggestions).build()); } + + @GetMapping("/rank") + public ApiResponse> getHotKeywords() { + return new ApiResponse<>( + hotKeywordService.getHotKeywordsRanking() + .stream() + .map(Mapper::of) + .toList() + ); + } + } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEvent.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BakeryCreationEvent.java similarity index 56% rename from src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEvent.java rename to src/main/java/com/depromeet/breadmapbackend/domain/search/events/BakeryCreationEvent.java index d0d71aa6..b5f20bc9 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEvent.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BakeryCreationEvent.java @@ -5,16 +5,12 @@ import org.springframework.context.ApplicationEvent; @Getter -public class OpenSearchBakeryEvent extends ApplicationEvent { +public class BakeryCreationEvent extends ApplicationEvent { Long bakeryId; BakeryLoadData bakeryLoadData; - public OpenSearchBakeryEvent(Object source, BakeryLoadData bakeryLoadData) { + public BakeryCreationEvent(Object source, BakeryLoadData bakeryLoadData) { super(source); this.bakeryLoadData = bakeryLoadData; } - public OpenSearchBakeryEvent(Object source, Long bakeryId) { - super(source); - this.bakeryId = bakeryId; - } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEvent.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BakeryDeletionEvent.java similarity index 59% rename from src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEvent.java rename to src/main/java/com/depromeet/breadmapbackend/domain/search/events/BakeryDeletionEvent.java index 9482eb8f..c4ed95f7 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEvent.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BakeryDeletionEvent.java @@ -5,13 +5,13 @@ import org.springframework.context.ApplicationEvent; @Getter -public class OpenSearchDeleteBreadEvent extends ApplicationEvent { +public class BakeryDeletionEvent extends ApplicationEvent { OpenSearchIndex openSearchIndex; - Long targetId; + Long bakeryId; - public OpenSearchDeleteBreadEvent(Object source, OpenSearchIndex openSearchIndex, Long targetId) { + public BakeryDeletionEvent(Object source, OpenSearchIndex openSearchIndex, Long bakeryId) { super(source); this.openSearchIndex = openSearchIndex; - this.targetId = targetId; + this.bakeryId = bakeryId; } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEvent.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BreadCreationEvent.java similarity index 61% rename from src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEvent.java rename to src/main/java/com/depromeet/breadmapbackend/domain/search/events/BreadCreationEvent.java index 4bf5c5ba..9c75f372 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEvent.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BreadCreationEvent.java @@ -1,16 +1,15 @@ package com.depromeet.breadmapbackend.domain.search.events; -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; import com.depromeet.breadmapbackend.domain.search.dto.keyword.BreadLoadData; import lombok.Getter; import org.springframework.context.ApplicationEvent; @Getter -public class OpenSearchBreadEvent extends ApplicationEvent { +public class BreadCreationEvent extends ApplicationEvent { Long breadId; BreadLoadData breadLoadData; - public OpenSearchBreadEvent(Object source, BreadLoadData breadLoadData) { + public BreadCreationEvent(Object source, BreadLoadData breadLoadData) { super(source); this.breadLoadData = breadLoadData; } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEvent.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BreadDelitionEvent.java similarity index 59% rename from src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEvent.java rename to src/main/java/com/depromeet/breadmapbackend/domain/search/events/BreadDelitionEvent.java index b7e86bf9..acbde3c7 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEvent.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/BreadDelitionEvent.java @@ -5,13 +5,13 @@ import org.springframework.context.ApplicationEvent; @Getter -public class OpenSearchDeleteBakeryEvent extends ApplicationEvent { +public class BreadDelitionEvent extends ApplicationEvent { OpenSearchIndex openSearchIndex; - Long targetId; + Long breadId; - public OpenSearchDeleteBakeryEvent(Object source, OpenSearchIndex openSearchIndex, Long targetId) { + public BreadDelitionEvent(Object source, OpenSearchIndex openSearchIndex, Long breadId) { super(source); this.openSearchIndex = openSearchIndex; - this.targetId = targetId; + this.breadId = breadId; } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEventListener.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEventListener.java index a6cc1914..42cfd3b2 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEventListener.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBakeryEventListener.java @@ -11,10 +11,10 @@ @Slf4j @RequiredArgsConstructor -public class OpenSearchBakeryEventListener implements ApplicationListener { +public class OpenSearchBakeryEventListener implements ApplicationListener { private final OpenSearchService openSearchService; @Override - public void onApplicationEvent(OpenSearchBakeryEvent event) { + public void onApplicationEvent(BakeryCreationEvent event) { try { openSearchService.convertDataAndLoadToEngine(OpenSearchIndex.BAKERY_SEARCH.getIndexNameWithVersion(), Collections.singletonList(event.getBakeryLoadData())); } catch (IOException e) { diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEventListener.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEventListener.java index a1f4f9ac..206c7153 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEventListener.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchBreadEventListener.java @@ -2,23 +2,20 @@ import com.depromeet.breadmapbackend.domain.search.OpenSearchService; import com.depromeet.breadmapbackend.domain.search.dto.OpenSearchIndex; -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BreadLoadData; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationListener; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; @Slf4j @RequiredArgsConstructor -public class OpenSearchBreadEventListener implements ApplicationListener { +public class OpenSearchBreadEventListener implements ApplicationListener { private final OpenSearchService openSearchService; @Override - public void onApplicationEvent(OpenSearchBreadEvent event) { + public void onApplicationEvent(BreadCreationEvent event) { try { openSearchService.convertDataAndLoadToEngine(OpenSearchIndex.BREAD_SEARCH.getIndexNameWithVersion(), Collections.singletonList(event.getBreadLoadData())); } catch (IOException e) { diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEventListener.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEventListener.java index 6c8e3c8d..9cd9f840 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEventListener.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBakeryEventListener.java @@ -9,15 +9,15 @@ @Slf4j @RequiredArgsConstructor -public class OpenSearchDeleteBakeryEventListener implements ApplicationListener { +public class OpenSearchDeleteBakeryEventListener implements ApplicationListener { private final OpenSearchService openSearchService; @Override - public void onApplicationEvent(OpenSearchDeleteBakeryEvent event) { + public void onApplicationEvent(BakeryDeletionEvent event) { try { - openSearchService.deleteIndex(event.getOpenSearchIndex(), event.targetId); + openSearchService.deleteIndex(event.getOpenSearchIndex(), event.bakeryId); } catch (IOException e) { - log.error("====== onApplicationEvent Starting with " + event.getOpenSearchIndex() + event.getTargetId() + " has been error"); + log.error("====== onApplicationEvent Starting with " + event.getOpenSearchIndex() + event.getBakeryId() + " has been error"); } } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEventListener.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEventListener.java index f09ca0f0..b6d3a329 100644 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEventListener.java +++ b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchDeleteBreadEventListener.java @@ -9,15 +9,15 @@ @Slf4j @RequiredArgsConstructor -public class OpenSearchDeleteBreadEventListener implements ApplicationListener { +public class OpenSearchDeleteBreadEventListener implements ApplicationListener { private final OpenSearchService openSearchService; @Override - public void onApplicationEvent(OpenSearchDeleteBakeryEvent event) { + public void onApplicationEvent(BakeryDeletionEvent event) { try { - openSearchService.deleteIndex(event.getOpenSearchIndex(), event.targetId); + openSearchService.deleteIndex(event.getOpenSearchIndex(), event.bakeryId); } catch (IOException e) { - log.error("====== onApplicationEvent Starting with " + event.getOpenSearchIndex() + event.getTargetId() + " has been error"); + log.error("====== onApplicationEvent Starting with " + event.getOpenSearchIndex() + event.getBakeryId() + " has been error"); } } } diff --git a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchEventPublisher.java b/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchEventPublisher.java deleted file mode 100644 index f34120eb..00000000 --- a/src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchEventPublisher.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.depromeet.breadmapbackend.domain.search.events; - -import com.depromeet.breadmapbackend.domain.search.dto.OpenSearchIndex; -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BreadLoadData; -import lombok.RequiredArgsConstructor; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class OpenSearchEventPublisher { - - private final ApplicationEventPublisher applicationEventPublisher; - - public void publishSaveBakery(final BakeryLoadData bakeryLoadData) { - OpenSearchBakeryEvent publishSaveBakery = new OpenSearchBakeryEvent(this, bakeryLoadData); - applicationEventPublisher.publishEvent(publishSaveBakery); - } - - public void publishSaveBread(final BreadLoadData breadLoadData) { - OpenSearchBreadEvent publishSaveBread = new OpenSearchBreadEvent(this, breadLoadData); - applicationEventPublisher.publishEvent(publishSaveBread); - } - - public void publishDeleteBakery(final Long bakeryId) { - OpenSearchDeleteBakeryEvent publishDeleteBakery = new OpenSearchDeleteBakeryEvent(this, OpenSearchIndex.BAKERY_SEARCH, bakeryId); - applicationEventPublisher.publishEvent(publishDeleteBakery); - } - - public void publishDeleteAllProducts(final Long bakeryId) { - OpenSearchDeleteBakeryEvent publishDeleteBakery = new OpenSearchDeleteBakeryEvent(this, OpenSearchIndex.BAKERY_SEARCH, bakeryId); - applicationEventPublisher.publishEvent(publishDeleteBakery); - } - -} diff --git a/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/handler/OpenSearchEventPublisher.java b/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/handler/OpenSearchEventPublisher.java new file mode 100644 index 00000000..5bd90b17 --- /dev/null +++ b/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/handler/OpenSearchEventPublisher.java @@ -0,0 +1,20 @@ +package com.depromeet.breadmapbackend.domain.admin.bakery.handler; + +import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; +import com.depromeet.breadmapbackend.domain.search.events.BakeryCreationEvent; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class OpenSearchEventPublisher { + + private final ApplicationEventPublisher applicationEventPublisher; + + public void publishSaveBakery(final BakeryLoadData bakeryLoadData) { + BakeryCreationEvent publishSaveBakery = new BakeryCreationEvent(this, bakeryLoadData); + applicationEventPublisher.publishEvent(publishSaveBakery); + } + +} diff --git a/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/service/AdminBakeryServiceTest.java b/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/service/AdminBakeryServiceTest.java index 1ebf3152..a130b1fa 100644 --- a/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/service/AdminBakeryServiceTest.java +++ b/src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/service/AdminBakeryServiceTest.java @@ -1,28 +1,5 @@ package com.depromeet.breadmapbackend.domain.admin.bakery.service; -import static org.assertj.core.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.BDDMockito.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; -import com.depromeet.breadmapbackend.domain.search.events.OpenSearchEventPublisher; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.context.ApplicationEventPublisher; - import com.depromeet.breadmapbackend.domain.admin.bakery.AdminBakeryServiceImpl; import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminBakeryDto; import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryAddDto; @@ -39,6 +16,24 @@ import com.depromeet.breadmapbackend.domain.bakery.report.BakeryAddReportRepository; import com.depromeet.breadmapbackend.domain.user.User; import com.depromeet.breadmapbackend.global.infra.properties.CustomAWSS3Properties; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.BDDMockito.*; @ExtendWith(MockitoExtension.class) public class AdminBakeryServiceTest { @@ -55,12 +50,10 @@ public class AdminBakeryServiceTest { private CustomAWSS3Properties customAWSS3Properties; @Mock private ApplicationEventPublisher eventPublisher; - @Mock - private OpenSearchEventPublisher openSearchEventPublisher; private List bakeries; private List products; - private CustomAWSS3Properties.DefaultImage defaultImage = new CustomAWSS3Properties.DefaultImage( + private final CustomAWSS3Properties.DefaultImage defaultImage = new CustomAWSS3Properties.DefaultImage( "bakery default image", "comment default image", "like default image", @@ -74,6 +67,8 @@ public class AdminBakeryServiceTest { @BeforeEach void setup() { +// MockitoAnnotations.openMocks(this); + List images1 = List.of("bakery test image 1", "bakery test image 2"); List images2 = List.of("bakery test image 1"); @@ -151,6 +146,8 @@ void after() { verify(customAWSS3Properties, times(bakeries.get(0).getImages().size())) .getDefaultImage(); + ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher); + } @DisplayName("addBakery 테스트") @@ -202,8 +199,7 @@ void after() { verify(bakeryRepository, times(1)) .existsByNameAndAddress(addRequest.getName(), addRequest.getAddress()); - ArgumentCaptor bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class); - verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture()); + ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher); } @@ -255,8 +251,8 @@ void after() { verify(bakeryRepository, times(1)) .existsByNameAndAddress(addRequest.getName(), addRequest.getAddress()); - ArgumentCaptor bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class); - verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture()); + ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher); + } @DisplayName("updateBakery 테스트") @@ -317,9 +313,6 @@ void after() { "2023-08-2700:00:00", "update check point" ); - ArgumentCaptor bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class); - verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture()); - } @DisplayName("updateBakery 테스트 - 수정 이미지가 0개일 경우 기본 이미지 1개를 삽입한다") @@ -365,7 +358,7 @@ void after() { assertThat(bakeries.get(0).getImages().get(0)).contains( customAWSS3Properties.getCloudFront() + "/" + customAWSS3Properties.getDefaultImage().getBakery()); - ArgumentCaptor bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class); - verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture()); + ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher); + } } diff --git a/src/test/java/com/depromeet/breadmapbackend/domain/search/FakeSearchV2ControllerTest.java b/src/test/java/com/depromeet/breadmapbackend/domain/search/FakeSearchV2ControllerTest.java index a89ed60e..d1048fcb 100644 --- a/src/test/java/com/depromeet/breadmapbackend/domain/search/FakeSearchV2ControllerTest.java +++ b/src/test/java/com/depromeet/breadmapbackend/domain/search/FakeSearchV2ControllerTest.java @@ -1,17 +1,9 @@ package com.depromeet.breadmapbackend.domain.search; -import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.*; -import static org.springframework.restdocs.request.RequestDocumentation.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import java.sql.Connection; - -import javax.sql.DataSource; - +import com.depromeet.breadmapbackend.domain.search.dto.SearchType; +import com.depromeet.breadmapbackend.global.security.domain.RoleType; +import com.depromeet.breadmapbackend.utils.ControllerTest; +import com.depromeet.breadmapbackend.utils.TestConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -21,10 +13,18 @@ import org.springframework.jdbc.datasource.init.ScriptUtils; import org.springframework.test.web.servlet.MockMvc; -import com.depromeet.breadmapbackend.domain.search.dto.SearchType; -import com.depromeet.breadmapbackend.global.security.domain.RoleType; -import com.depromeet.breadmapbackend.utils.ControllerTest; -import com.depromeet.breadmapbackend.utils.TestConfig; +import javax.sql.DataSource; +import java.sql.Connection; + +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @Import(TestConfig.class) class FakeSearchV2ControllerTest extends ControllerTest { @@ -38,6 +38,7 @@ class FakeSearchV2ControllerTest extends ControllerTest { private void setUpTestDate() throws Exception { try (final Connection connection = dataSource.getConnection()) { ScriptUtils.executeSqlScript(connection, new ClassPathResource("user-test-data.sql")); + ScriptUtils.executeSqlScript(connection, new ClassPathResource("hot-keyword-test-data.sql")); } } @@ -90,7 +91,6 @@ void searchKeyword() throws Exception { .andExpect(status().isOk()); } - // TODO: github CI test check... mock 객체 return이 안됨 @Test void searchKeywordSuggestions() throws Exception { String keyword = "베이커리"; diff --git a/src/test/java/com/depromeet/breadmapbackend/domain/search/SearchV2ControllerTest.java b/src/test/java/com/depromeet/breadmapbackend/domain/search/SearchV2ControllerTest.java index 818a8967..70c39056 100644 --- a/src/test/java/com/depromeet/breadmapbackend/domain/search/SearchV2ControllerTest.java +++ b/src/test/java/com/depromeet/breadmapbackend/domain/search/SearchV2ControllerTest.java @@ -7,7 +7,6 @@ import com.depromeet.breadmapbackend.utils.ControllerTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.io.ClassPathResource; @@ -25,14 +24,12 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class SearchV2ControllerTest extends ControllerTest { @Autowired @@ -41,7 +38,6 @@ class SearchV2ControllerTest extends ControllerTest { private DataSource dataSource; @MockBean private SearchService searchService; - private String userToken; private void setUpTestDate() throws Exception { @@ -120,34 +116,4 @@ void searchKeyword() throws Exception { )) .andExpect(MockMvcResultMatchers.status().isOk()); } - -// TODO: github CI test check... mock 객체 return이 안됨 -// @Test -// void searchKeywordSuggestions() throws Exception { -// String keyword = "베이커리"; -// -// List keywordSuggestions = new ArrayList<>(); -// keywordSuggestions.add("test1"); -// keywordSuggestions.add("test2"); -// keywordSuggestions.add("test3"); -// -// when(searchService.searchKeywordSuggestions(eq(keyword))) -// .thenReturn(keywordSuggestions); -// -// mockMvc.perform(get("/v2/search/suggestions") -// .param("keyword", keyword) -// .contentType(MediaType.APPLICATION_JSON)) -// .andDo(print()) -// .andDo(document("v2/search/suggestions", -// preprocessRequest(prettyPrint()), -// preprocessResponse(prettyPrint()), -// requestParameters( -// parameterWithName("keyword").description("검색 키워드") -// ), -// responseFields( -// fieldWithPath("data.keywordSuggestions").description("추천 검색어 리스트") -// ) -// )) -// .andExpect(status().isOk()); -// } } diff --git a/src/test/java/com/depromeet/breadmapbackend/mock/FakeSearchServiceImpl.java b/src/test/java/com/depromeet/breadmapbackend/mock/FakeSearchServiceImpl.java index 3e82c5a8..a45197aa 100644 --- a/src/test/java/com/depromeet/breadmapbackend/mock/FakeSearchServiceImpl.java +++ b/src/test/java/com/depromeet/breadmapbackend/mock/FakeSearchServiceImpl.java @@ -1,13 +1,13 @@ package com.depromeet.breadmapbackend.mock; -import java.util.List; - import com.depromeet.breadmapbackend.domain.search.SearchService; import com.depromeet.breadmapbackend.domain.search.dto.SearchDto; import com.depromeet.breadmapbackend.domain.search.dto.SearchResultDto; import com.depromeet.breadmapbackend.domain.search.dto.SearchType; import com.depromeet.breadmapbackend.domain.search.dto.keyword.response.SearchResultResponse; +import java.util.List; + /** * FakeSearchServiceImpl *