From 58b4ed4dc0810473ca68f9e1e4fa75a98786b806 Mon Sep 17 00:00:00 2001 From: kimscott Date: Fri, 22 Nov 2019 13:42:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20=EC=B7=A8=EC=86=8C=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/template/OrderCancelled.java | 69 +++++++++++++++++++ .../com/example/template/OrderPlaced.java | 2 - .../com/example/template/ProductService.java | 11 +++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/template/OrderCancelled.java 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){ }