Compare commits
1 Commits
master
...
saga-rollb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b76e9f3abd |
@@ -49,7 +49,7 @@ public class Order {
|
||||
price = jsonObject.get("price").getAsInt();
|
||||
productName = jsonObject.get("name").getAsString();
|
||||
if( jsonObject.get("stock").getAsInt() < getQuantity()){
|
||||
throw new OrderException("No Available stock!");
|
||||
// throw new OrderException("No Available stock!");
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Order {
|
||||
price = product.getPrice();
|
||||
productName = product.getName();
|
||||
if( product.getStock() < getQuantity()){
|
||||
throw new OrderException("No Available stock!");
|
||||
// throw new OrderException("No Available stock!");
|
||||
}
|
||||
}
|
||||
this.setPrice(price);
|
||||
|
||||
@@ -20,6 +20,8 @@ public class OrderService {
|
||||
|
||||
@Autowired
|
||||
private ProductRepository productRepository;
|
||||
@Autowired
|
||||
private OrderRepository orderRepository;
|
||||
|
||||
/**
|
||||
* 상품 변경이 발생할때마다, 상품정보를 저장해 놓음
|
||||
@@ -41,4 +43,19 @@ public class OrderService {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@StreamListener(KafkaProcessor.INPUT)
|
||||
public void onProductOutOfStock(@Payload ProductOutOfStock productOutOfStock) {
|
||||
try {
|
||||
if (productOutOfStock.isMe()) {
|
||||
System.out.println("##### listener : " + productOutOfStock.toJson());
|
||||
Optional<Order> orderOptional = orderRepository.findById(productOutOfStock.getOrderId());
|
||||
Order order = orderOptional.get();
|
||||
order.setState("OrderCancelled");
|
||||
orderRepository.save(order);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
src/main/java/com/example/template/ProductOutOfStock.java
Normal file
32
src/main/java/com/example/template/ProductOutOfStock.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.example.template;
|
||||
|
||||
public class ProductOutOfStock extends AbstractEvent {
|
||||
|
||||
private String stateMessage = "재고량 바닥";
|
||||
private Long productId;
|
||||
private Long orderId;
|
||||
|
||||
public String getStateMessage() {
|
||||
return stateMessage;
|
||||
}
|
||||
|
||||
public void setStateMessage(String stateMessage) {
|
||||
this.stateMessage = stateMessage;
|
||||
}
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Long productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Long getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(Long orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user