주문 취소 이벤트 발생
This commit is contained in:
69
src/main/java/com/example/template/OrderCancelled.java
Normal file
69
src/main/java/com/example/template/OrderCancelled.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user