From 8f16c28fd7e74eaeecdc75d99836c8befea98269 Mon Sep 17 00:00:00 2001 From: harper <35358294+yooyouny@users.noreply.github.com> Date: Wed, 16 Oct 2024 00:41:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat(#128):=20elastic=20search=20dto?= =?UTF-8?q?=EB=93=A4=EC=97=90=EC=84=9C=20stock=EA=B0=92=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/infrastructure/utils/ProductSearchDto.java | 4 ---- .../java/com/sparta/server/domain/ProductSearchDto.java | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/service/product/server/src/main/java/com/sparta/product/infrastructure/utils/ProductSearchDto.java b/service/product/server/src/main/java/com/sparta/product/infrastructure/utils/ProductSearchDto.java index 949d2e2f..a7b19426 100644 --- a/service/product/server/src/main/java/com/sparta/product/infrastructure/utils/ProductSearchDto.java +++ b/service/product/server/src/main/java/com/sparta/product/infrastructure/utils/ProductSearchDto.java @@ -24,7 +24,6 @@ public class ProductSearchDto { private BigDecimal originalPrice; private BigDecimal discountedPrice; private Double discountPercent; - private Integer stock; private String description; private String thumbnailImgUrl; private double averageRating; @@ -47,7 +46,6 @@ private ProductSearchDto( BigDecimal originalPrice, BigDecimal discountedPrice, Double discountPercent, - Integer stock, String description, String thumbnailImgUrl, double averageRating, @@ -67,7 +65,6 @@ private ProductSearchDto( this.originalPrice = originalPrice; this.discountedPrice = discountedPrice; this.discountPercent = discountPercent; - this.stock = stock; this.description = description; this.thumbnailImgUrl = thumbnailImgUrl; this.averageRating = averageRating; @@ -91,7 +88,6 @@ public static ProductSearchDto toDto(ProductResponse product) { .originalPrice(product.getOriginalPrice()) .discountedPrice(product.getDiscountedPrice()) .discountPercent(product.getDiscountPercent()) - .stock(product.getStock()) .description(product.getDescription()) .thumbnailImgUrl(product.getThumbnailImgUrl()) .averageRating(product.getAverageRating()) diff --git a/service/search/server/src/main/java/com/sparta/server/domain/ProductSearchDto.java b/service/search/server/src/main/java/com/sparta/server/domain/ProductSearchDto.java index 4429d51f..0e2d7077 100644 --- a/service/search/server/src/main/java/com/sparta/server/domain/ProductSearchDto.java +++ b/service/search/server/src/main/java/com/sparta/server/domain/ProductSearchDto.java @@ -12,8 +12,7 @@ @Document(indexName = "sasaping-ecommerce-products") public class ProductSearchDto { - @Id - private String productId; + @Id private String productId; private Long categoryId; private String productName; private String brandName; @@ -22,7 +21,6 @@ public class ProductSearchDto { private BigDecimal originalPrice; private BigDecimal discountedPrice; private Double discountPercent; - private Integer stock; private String description; private String thumbnailImgUrl; private double averageRating; @@ -33,6 +31,4 @@ public class ProductSearchDto { private Long salesCount; private boolean isDeleted; private String createdAt; - - } From bf1941ad7f5cbca85aed5255b51f3947024ba16c Mon Sep 17 00:00:00 2001 From: harper <35358294+yooyouny@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:52:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat(#128):=20order=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=EC=97=90=20=EC=82=AC=EC=A0=84=EC=A3=BC=EB=AC=B8=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=9D=84=20=EB=B0=9B=EB=8A=94=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=EB=84=88=20=EB=B9=88=20=EB=93=B1=EB=A1=9D=20-=20OrderCreateSer?= =?UTF-8?q?vice=EC=9D=98=20createOrder=EC=97=90=EC=84=9C=20dto=20import=20?= =?UTF-8?q?=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/dto/OrderCreateRequest.java | 18 ++++++++++ .../order/dto/src/main/java/dto/OrderDto.java | 34 ------------------- .../src/main/java/dto/OrderProductInfo.java | 14 ++++++++ service/order/server/build.gradle | 1 + .../messaging/PreOrderConsumer.java | 29 ++++++++++++++++ .../preorder/PreOrderFacadeService.java | 8 +++-- .../application/preorder/PreOrderMapper.java | 8 ++--- .../messaging/PreOrderProducer.java | 10 +++--- 8 files changed, 77 insertions(+), 45 deletions(-) create mode 100644 service/order/dto/src/main/java/dto/OrderCreateRequest.java delete mode 100644 service/order/dto/src/main/java/dto/OrderDto.java create mode 100644 service/order/dto/src/main/java/dto/OrderProductInfo.java create mode 100644 service/order/server/src/main/java/com/sparta/order/server/infrastructure/messaging/PreOrderConsumer.java diff --git a/service/order/dto/src/main/java/dto/OrderCreateRequest.java b/service/order/dto/src/main/java/dto/OrderCreateRequest.java new file mode 100644 index 00000000..ac9801d9 --- /dev/null +++ b/service/order/dto/src/main/java/dto/OrderCreateRequest.java @@ -0,0 +1,18 @@ +package dto; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class OrderCreateRequest { + private String orderType; + private List orderProductInfos = new ArrayList<>(); + private BigDecimal pointPrice; + private Long addressId; +} diff --git a/service/order/dto/src/main/java/dto/OrderDto.java b/service/order/dto/src/main/java/dto/OrderDto.java deleted file mode 100644 index d85d3a5e..00000000 --- a/service/order/dto/src/main/java/dto/OrderDto.java +++ /dev/null @@ -1,34 +0,0 @@ -package dto; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -public class OrderDto { - - @Getter - @AllArgsConstructor - @NoArgsConstructor - public static class OrderCreateRequest { - - private String orderType; - private List orderProductInfos = new ArrayList<>(); - private BigDecimal pointPrice; - private Long addressId; - } - - @Getter - @AllArgsConstructor - @NoArgsConstructor - public static class OrderProductInfo { - - private String productId; - private int quantity; - private Long userCouponId; - - } - -} diff --git a/service/order/dto/src/main/java/dto/OrderProductInfo.java b/service/order/dto/src/main/java/dto/OrderProductInfo.java new file mode 100644 index 00000000..260742a1 --- /dev/null +++ b/service/order/dto/src/main/java/dto/OrderProductInfo.java @@ -0,0 +1,14 @@ +package dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class OrderProductInfo { + private String productId; + private int quantity; + private Long userCouponId; +} diff --git a/service/order/server/build.gradle b/service/order/server/build.gradle index dfafbb42..1cc68978 100644 --- a/service/order/server/build.gradle +++ b/service/order/server/build.gradle @@ -34,6 +34,7 @@ dependencies { implementation project(':service:product:product_dto') implementation project(':service:auth:auth_dto') implementation project(':service:payment:payment_dto') + implementation project(':service:order:dto') implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'mysql:mysql-connector-java:8.0.33' diff --git a/service/order/server/src/main/java/com/sparta/order/server/infrastructure/messaging/PreOrderConsumer.java b/service/order/server/src/main/java/com/sparta/order/server/infrastructure/messaging/PreOrderConsumer.java new file mode 100644 index 00000000..ef599739 --- /dev/null +++ b/service/order/server/src/main/java/com/sparta/order/server/infrastructure/messaging/PreOrderConsumer.java @@ -0,0 +1,29 @@ +package com.sparta.order.server.infrastructure.messaging; + +import com.sparta.common.domain.entity.KafkaTopicConstant; +import com.sparta.order.server.application.service.OrderCreateService; +import dto.OrderCreateRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +@Slf4j(topic = "PreOrderConsumer") +public class PreOrderConsumer { + public final OrderCreateService orderCreateService; + + @KafkaListener(topics = KafkaTopicConstant.PROCESS_PREORDER, groupId = "product") + public void consume( + @Payload OrderCreateRequest request, + @Header(name = "kafka_receivedMessageKey") String userId) { + log.info("preorder by {}", userId); + orderCreateService.createOrder(Long.parseLong(userId), request); + log.info("process preorder : {}", request.getOrderProductInfos().get(0).getProductId()); + } +} diff --git a/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderFacadeService.java b/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderFacadeService.java index 0f998445..e8e23b8e 100644 --- a/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderFacadeService.java +++ b/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderFacadeService.java @@ -6,7 +6,7 @@ import com.sparta.product.infrastructure.messaging.PreOrderProducer; import com.sparta.product.presentation.exception.ProductErrorCode; import com.sparta.product.presentation.exception.ProductServerException; -import dto.OrderDto.OrderCreateRequest; +import dto.OrderCreateRequest; import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,8 +23,10 @@ public class PreOrderFacadeService { public void preOrder(Long preOrderId, Long addressId, Long userId) { PreOrder preOrder = preOrderService.findPreOrderByPreOrderId(preOrderId); preOrderLockService.reservation(preOrderId, userId); - OrderCreateRequest createRequest = PreOrderMapper.toDto(preOrderId, addressId); - preOrderProducer.send(KafkaTopicConstant.PROCESS_PREORDER, preOrderId, createRequest); + OrderCreateRequest createRequest = + PreOrderMapper.toDto(preOrder.getProductId().toString(), addressId); + preOrderProducer.send( + KafkaTopicConstant.PROCESS_PREORDER, Long.toString(userId), createRequest); } private void validatePreOrder(PreOrder preOrder) { diff --git a/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderMapper.java b/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderMapper.java index 08b82002..e24ba1e3 100644 --- a/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderMapper.java +++ b/service/product/server/src/main/java/com/sparta/product/application/preorder/PreOrderMapper.java @@ -2,8 +2,8 @@ import com.sparta.product.domain.model.PreOrder; import com.sparta.product.presentation.request.PreOrderCreateRequest; -import dto.OrderDto.OrderCreateRequest; -import dto.OrderDto.OrderProductInfo; +import dto.OrderCreateRequest; +import dto.OrderProductInfo; import java.util.List; public class PreOrderMapper { @@ -18,8 +18,8 @@ public static PreOrder toEntity(PreOrderCreateRequest request) { .build(); } - public static OrderCreateRequest toDto(Long preOrderId, Long addressId) { - OrderProductInfo orderProduct = new OrderProductInfo(preOrderId.toString(), 1, null); + public static OrderCreateRequest toDto(String productId, Long addressId) { + OrderProductInfo orderProduct = new OrderProductInfo(productId, 1, null); return new OrderCreateRequest("PREORDER", List.of(orderProduct), null, addressId); } } diff --git a/service/product/server/src/main/java/com/sparta/product/infrastructure/messaging/PreOrderProducer.java b/service/product/server/src/main/java/com/sparta/product/infrastructure/messaging/PreOrderProducer.java index 334a2946..f7562bcb 100644 --- a/service/product/server/src/main/java/com/sparta/product/infrastructure/messaging/PreOrderProducer.java +++ b/service/product/server/src/main/java/com/sparta/product/infrastructure/messaging/PreOrderProducer.java @@ -1,6 +1,6 @@ package com.sparta.product.infrastructure.messaging; -import dto.OrderDto.OrderCreateRequest; +import dto.OrderCreateRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.core.KafkaTemplate; @@ -10,8 +10,10 @@ public class PreOrderProducer { private final KafkaTemplate kafkaTemplate; - public void send(String topic, Long preOrderId, OrderCreateRequest request) { - kafkaTemplate.send(topic, preOrderId.toString(), request); - log.info("send preorderRequest of {} to order server", preOrderId); + public void send(String topic, String userId, OrderCreateRequest request) { + kafkaTemplate.send(topic, userId, request); + log.info( + "send preorderRequest of {} to order server", + request.getOrderProductInfos().get(0).getProductId()); } }