From b0e1397e7c0c4da3caae7a7a20dbd541f4a5b628 Mon Sep 17 00:00:00 2001 From: Chris Park Date: Tue, 12 Dec 2023 07:21:38 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Bakery,=20Bread=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EC=82=AD=EC=A0=9C=20=EC=9D=B4=EB=B2=A4=ED=8A=B8?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/bakery/AdminBakeryServiceImpl.java | 89 ++++++++----------- ...eryEvent.java => BakeryCreationEvent.java} | 8 +- ...eadEvent.java => BakeryDeletionEvent.java} | 8 +- ...readEvent.java => BreadCreationEvent.java} | 5 +- ...keryEvent.java => BreadDelitionEvent.java} | 8 +- .../events/OpenSearchBakeryEventListener.java | 4 +- .../events/OpenSearchBreadEventListener.java | 7 +- .../OpenSearchDeleteBakeryEventListener.java | 8 +- .../OpenSearchDeleteBreadEventListener.java | 8 +- .../events/OpenSearchEventPublisher.java | 36 -------- .../handler/OpenSearchEventPublisher.java | 20 +++++ .../service/AdminBakeryServiceTest.java | 2 +- 12 files changed, 80 insertions(+), 123 deletions(-) rename src/main/java/com/depromeet/breadmapbackend/domain/search/events/{OpenSearchBakeryEvent.java => BakeryCreationEvent.java} (56%) rename src/main/java/com/depromeet/breadmapbackend/domain/search/events/{OpenSearchDeleteBreadEvent.java => BakeryDeletionEvent.java} (59%) rename src/main/java/com/depromeet/breadmapbackend/domain/search/events/{OpenSearchBreadEvent.java => BreadCreationEvent.java} (61%) rename src/main/java/com/depromeet/breadmapbackend/domain/search/events/{OpenSearchDeleteBakeryEvent.java => BreadDelitionEvent.java} (59%) delete mode 100644 src/main/java/com/depromeet/breadmapbackend/domain/search/events/OpenSearchEventPublisher.java create mode 100644 src/test/java/com/depromeet/breadmapbackend/domain/admin/bakery/handler/OpenSearchEventPublisher.java 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/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..d6d19c15 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 @@ -11,7 +11,7 @@ import java.util.Optional; import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData; -import com.depromeet.breadmapbackend.domain.search.events.OpenSearchEventPublisher; +import com.depromeet.breadmapbackend.domain.admin.bakery.handler.OpenSearchEventPublisher; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName;