Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

주문서버에 사전예약 리스너 빈 등록 #131

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions service/order/dto/src/main/java/dto/OrderCreateRequest.java
Original file line number Diff line number Diff line change
@@ -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<OrderProductInfo> orderProductInfos = new ArrayList<>();
private BigDecimal pointPrice;
private Long addressId;
}
34 changes: 0 additions & 34 deletions service/order/dto/src/main/java/dto/OrderDto.java

This file was deleted.

14 changes: 14 additions & 0 deletions service/order/dto/src/main/java/dto/OrderProductInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions service/order/server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,8 +10,10 @@
public class PreOrderProducer {
private final KafkaTemplate<String, Object> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +46,6 @@ private ProductSearchDto(
BigDecimal originalPrice,
BigDecimal discountedPrice,
Double discountPercent,
Integer stock,
String description,
String thumbnailImgUrl,
double averageRating,
Expand All @@ -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;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -33,6 +31,4 @@ public class ProductSearchDto {
private Long salesCount;
private boolean isDeleted;
private String createdAt;


}
Loading