주문 취소 이벤트 발생

This commit is contained in:
kimscott
2019-11-22 13:42:04 +09:00
parent fce1853a00
commit 58b4ed4dc0
3 changed files with 80 additions and 2 deletions

View File

@@ -0,0 +1,69 @@
package com.example.template;
public class OrderCancelled extends AbstractEvent{
private Long productId;
private Long orderId;
private String productName;
private int quantity;
private int price;
private String customerId;
private String customerName;
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;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
}

View File

@@ -1,7 +1,5 @@
package com.example.template; package com.example.template;
import java.io.Serializable;
public class OrderPlaced extends AbstractEvent { public class OrderPlaced extends AbstractEvent {
private Long productId; private Long productId;

View File

@@ -42,6 +42,17 @@ public class ProductService {
} }
/**
* 주문 취소시, 수량을 늘인다
*/
if( orderPlaced.getEventType().equals(OrderCancelled.class.getSimpleName())){
Optional<Product> productOptional = productRepository.findById(orderPlaced.getProductId());
Product product = productOptional.get();
product.setStock(product.getStock() + orderPlaced.getQuantity());
productRepository.save(product);
}
}catch (Exception e){ }catch (Exception e){
} }