From 2cce9507d69605cb9239b2647e631d6869b5b339 Mon Sep 17 00:00:00 2001 From: kimujae Date: Tue, 6 Aug 2024 15:33:17 +0900 Subject: [PATCH] =?UTF-8?q?KAN-701=20feat:=20=ED=83=80=EC=9E=84=EC=84=B8?= =?UTF-8?q?=EC=9D=BC=20=EA=B4=91=EA=B3=A0=EC=8B=A0=EC=B2=AD=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=EB=B0=9C=ED=96=89=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/customerservice/AdvertisementRequest.java | 4 ++-- .../dto/customerservice/TimesaleRequestForCustomer.java | 4 ++-- .../customerservice/AdvertisementManagementService.java | 8 +++----- .../customerservice/TimesaleManagementService.java | 8 +++----- .../web/controller/AdvertisementController.java | 8 +++++++- .../web/controller/TimesaleController.java | 9 +++++++-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/AdvertisementRequest.java b/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/AdvertisementRequest.java index a4134ba..4a1bfba 100644 --- a/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/AdvertisementRequest.java +++ b/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/AdvertisementRequest.java @@ -38,9 +38,9 @@ public ProductAdvertisementService toEntity(Product product, ServiceStatus statu .build(); } - public AdvertisementEventMessage toEventMessage() { + public AdvertisementEventMessage toEventMessage(Long id) { return AdvertisementEventMessage.builder() - .productId(this.getProductId()) + .productId(id) .startDate(this.getStartDate()) .endDate(this.getEndDate()) .build(); diff --git a/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/TimesaleRequestForCustomer.java b/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/TimesaleRequestForCustomer.java index ee92d29..02660a3 100644 --- a/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/TimesaleRequestForCustomer.java +++ b/src/main/java/com/yeonieum/productservice/domain/product/dto/customerservice/TimesaleRequestForCustomer.java @@ -39,11 +39,11 @@ public ProductTimesale toEntity(Product product, ServiceStatus serviceStatus) { .build(); } - public TimesaleEventMessage toEventMessage() { + public TimesaleEventMessage toEventMessage(Long id) { return TimesaleEventMessage.builder() .startDateTime(this.getStartTime()) .endDateTime(this.getEndTime()) - .productId(this.getProductId()) + .productId(id) .build(); } } diff --git a/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/AdvertisementManagementService.java b/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/AdvertisementManagementService.java index 71acae8..f84bb7d 100644 --- a/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/AdvertisementManagementService.java +++ b/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/AdvertisementManagementService.java @@ -35,7 +35,6 @@ public class AdvertisementManagementService { private final ProductRepository productRepository; private final ProductAdvertisementServiceRepository productAdvertisementServiceRepository; private final ServiceStatusRepository serviceStatusRepository; - private final ProductEventProducer productEventProducer; /** * 상당노출신청상품리스트 조회 @@ -59,7 +58,7 @@ public List retrieveAppliedProduct(Long custom * @return */ @Transactional - public void registerAdvertisement(Long customerId, AdvertisementRequest.OfRegister registerRequest) throws JsonProcessingException { + public Long registerAdvertisement(Long customerId, AdvertisementRequest.OfRegister registerRequest) throws JsonProcessingException { Product product = productRepository.findByProductIdAndCustomer_CustomerId(registerRequest.getProductId(), customerId); if(product == null) { throw new ProductException(PRODUCT_NOT_FOUND, HttpStatus.NOT_FOUND); @@ -67,10 +66,9 @@ public void registerAdvertisement(Long customerId, AdvertisementRequest.OfRegist ServiceStatus status = serviceStatusRepository.findByStatusName(ServiceStatusCode.PENDING.getCode()); ProductAdvertisementService productAdvertisement = registerRequest.toEntity(product, status); - productAdvertisementServiceRepository.save(productAdvertisement); + ProductAdvertisementService savedEntity = productAdvertisementServiceRepository.save(productAdvertisement); - AdvertisementEventMessage advertisementEventMessage = registerRequest.toEventMessage(); - productEventProducer.sendMessage(advertisementEventMessage); + return savedEntity.getProductAdvertisementServiceId(); } /** diff --git a/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/TimesaleManagementService.java b/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/TimesaleManagementService.java index 3e4ee46..690396e 100644 --- a/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/TimesaleManagementService.java +++ b/src/main/java/com/yeonieum/productservice/domain/product/service/customerservice/TimesaleManagementService.java @@ -38,7 +38,6 @@ public class TimesaleManagementService { private final ProductRepository productRepository; private final ProductTimesaleRepository productTimesaleRepository; private final ServiceStatusRepository serviceStatusRepository; - private final ProductEventProducer productEventProducer; /** * 고객의 등록타임세일 목록 조회 @@ -83,7 +82,7 @@ public TimesaleResponseForCustomer.OfRetrieve retrieveCustomersTimesale(Long cus * @return */ @Transactional - public void registerTimesale(Long customerId, TimesaleRequestForCustomer.OfRegister registerRequest) throws JsonProcessingException { + public Long registerTimesale(Long customerId, TimesaleRequestForCustomer.OfRegister registerRequest) throws JsonProcessingException { Product product = productRepository.findByProductIdAndCustomer_CustomerId(registerRequest.getProductId(), customerId); if(product == null) { throw new ProductException(PRODUCT_NOT_FOUND, HttpStatus.NOT_FOUND); @@ -91,10 +90,9 @@ public void registerTimesale(Long customerId, TimesaleRequestForCustomer.OfRegis ServiceStatus status = serviceStatusRepository.findByStatusName(ServiceStatusCode.PENDING.getCode()); ProductTimesale productTimesale = registerRequest.toEntity(product, status); - productTimesaleRepository.save(productTimesale); + ProductTimesale savedEntity = productTimesaleRepository.save(productTimesale); - TimesaleEventMessage timesaleEventMessage = registerRequest.toEventMessage(); - productEventProducer.sendMessage(timesaleEventMessage); + return savedEntity.getProductTimesaleId(); } /** diff --git a/src/main/java/com/yeonieum/productservice/web/controller/AdvertisementController.java b/src/main/java/com/yeonieum/productservice/web/controller/AdvertisementController.java index 6dd1bfa..6a74357 100644 --- a/src/main/java/com/yeonieum/productservice/web/controller/AdvertisementController.java +++ b/src/main/java/com/yeonieum/productservice/web/controller/AdvertisementController.java @@ -9,6 +9,8 @@ import com.yeonieum.productservice.global.responses.ApiResponse; import com.yeonieum.productservice.global.responses.code.SuccessCode; import com.yeonieum.productservice.global.usercontext.UserContextHolder; +import com.yeonieum.productservice.infrastructure.messaging.ProductEventProducer; +import com.yeonieum.productservice.infrastructure.messaging.message.AdvertisementEventMessage; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.validation.Valid; @@ -26,6 +28,8 @@ public class AdvertisementController { private final AdvertisementManagementService advertisementManagementService; private final AdvertisementService advertisementService; + private final ProductEventProducer productEventProducer; + /** * 상품광고서비스 신청 @@ -61,8 +65,10 @@ public ResponseEntity getAdvertisement(@RequestParam int startPage, @PostMapping("/product") public ResponseEntity registerAdvertisement(@Valid @RequestBody AdvertisementRequest.OfRegister registerRequest) throws JsonProcessingException { Long customer = Long.valueOf(UserContextHolder.getContext().getUniqueId()); - advertisementManagementService.registerAdvertisement(customer, registerRequest); + Long id= advertisementManagementService.registerAdvertisement(customer, registerRequest); + AdvertisementEventMessage advertisementEventMessage = registerRequest.toEventMessage(id); + productEventProducer.sendMessage(advertisementEventMessage); return new ResponseEntity(ApiResponse.builder() .result(null) .successCode(SuccessCode.INSERT_SUCCESS) diff --git a/src/main/java/com/yeonieum/productservice/web/controller/TimesaleController.java b/src/main/java/com/yeonieum/productservice/web/controller/TimesaleController.java index 37d01b0..7b23dba 100644 --- a/src/main/java/com/yeonieum/productservice/web/controller/TimesaleController.java +++ b/src/main/java/com/yeonieum/productservice/web/controller/TimesaleController.java @@ -10,6 +10,8 @@ import com.yeonieum.productservice.global.responses.ApiResponse; import com.yeonieum.productservice.global.responses.code.SuccessCode; import com.yeonieum.productservice.global.usercontext.UserContextHolder; +import com.yeonieum.productservice.infrastructure.messaging.ProductEventProducer; +import com.yeonieum.productservice.infrastructure.messaging.message.TimesaleEventMessage; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponses; import jakarta.validation.Valid; @@ -29,6 +31,8 @@ public class TimesaleController { private final TimesaleManagementService timesaleManagementService; private final TimesaleManagementFacade timesaleManagementFacade; + private final ProductEventProducer productEventProducer; + // TimesaleService의 메서드를 바탕으로 타임세일 조회, 등록, 타임세일 상품 조회를 구현해주세요. // 타임세일 조회, 등록, 타임세일 상품 조회를 위한 API를 구현해주세요. @@ -59,8 +63,9 @@ public ResponseEntity getTimesale() { @PostMapping public ResponseEntity registerTimesale(@Valid @RequestBody TimesaleRequestForCustomer.OfRegister registerRequest) throws JsonProcessingException { Long customer = Long.valueOf(UserContextHolder.getContext().getUserId()); - timesaleManagementService.registerTimesale(customer, registerRequest); - + Long id = timesaleManagementService.registerTimesale(customer, registerRequest); + TimesaleEventMessage timesaleEventMessage = registerRequest.toEventMessage(id); + productEventProducer.sendMessage(timesaleEventMessage); return new ResponseEntity<>(ApiResponse.builder() .result(null) .successCode(SuccessCode.INSERT_SUCCESS)