diff --git a/src/main/java/com/example/template/OrderCancelled.java b/src/main/java/com/example/template/OrderCancelled.java new file mode 100644 index 0000000..ebe5052 --- /dev/null +++ b/src/main/java/com/example/template/OrderCancelled.java @@ -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; + } + +} diff --git a/src/main/java/com/example/template/OrderPlaced.java b/src/main/java/com/example/template/OrderPlaced.java index 65dbc05..73cbda9 100644 --- a/src/main/java/com/example/template/OrderPlaced.java +++ b/src/main/java/com/example/template/OrderPlaced.java @@ -1,7 +1,5 @@ package com.example.template; -import java.io.Serializable; - public class OrderPlaced extends AbstractEvent { private Long productId; diff --git a/src/main/java/com/example/template/ProductService.java b/src/main/java/com/example/template/ProductService.java index be80be6..807464d 100644 --- a/src/main/java/com/example/template/ProductService.java +++ b/src/main/java/com/example/template/ProductService.java @@ -42,6 +42,17 @@ public class ProductService { } + /** + * 주문 취소시, 수량을 늘인다 + */ + if( orderPlaced.getEventType().equals(OrderCancelled.class.getSimpleName())){ + Optional productOptional = productRepository.findById(orderPlaced.getProductId()); + Product product = productOptional.get(); + product.setStock(product.getStock() + orderPlaced.getQuantity()); + + productRepository.save(product); + } + }catch (Exception e){ }