From 8d25923887decb67e7b525250e8443a886a2f35c Mon Sep 17 00:00:00 2001 From: kimscott Date: Mon, 2 Sep 2019 14:03:14 +0900 Subject: [PATCH] =?UTF-8?q?event=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/template/AbstractEvent.java | 29 +++++++++++++++++++ .../com/example/template/OrderPlaced.java | 12 +------- .../com/example/template/ProductChanged.java | 14 ++------- .../com/example/template/ProductRequired.java | 11 +------ .../com/example/template/ProductService.java | 4 +-- 5 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/example/template/AbstractEvent.java diff --git a/src/main/java/com/example/template/AbstractEvent.java b/src/main/java/com/example/template/AbstractEvent.java new file mode 100644 index 0000000..79b800c --- /dev/null +++ b/src/main/java/com/example/template/AbstractEvent.java @@ -0,0 +1,29 @@ +package com.example.template; + +import org.springframework.stereotype.Service; + +public class AbstractEvent { + + String eventType; + String timestamp; + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public boolean isMe(){ + return getEventType().equals(getClass().getSimpleName()); + } +} diff --git a/src/main/java/com/example/template/OrderPlaced.java b/src/main/java/com/example/template/OrderPlaced.java index fbfc4e0..65dbc05 100644 --- a/src/main/java/com/example/template/OrderPlaced.java +++ b/src/main/java/com/example/template/OrderPlaced.java @@ -2,9 +2,7 @@ package com.example.template; import java.io.Serializable; -public class OrderPlaced implements Serializable { - - private String type; +public class OrderPlaced extends AbstractEvent { private Long productId; private Long orderId; @@ -14,14 +12,6 @@ public class OrderPlaced implements Serializable { private String customerName; private String customerAddr; - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - public Long getProductId() { return productId; diff --git a/src/main/java/com/example/template/ProductChanged.java b/src/main/java/com/example/template/ProductChanged.java index 53c05b4..451b349 100644 --- a/src/main/java/com/example/template/ProductChanged.java +++ b/src/main/java/com/example/template/ProductChanged.java @@ -1,8 +1,7 @@ package com.example.template; -public class ProductChanged { +public class ProductChanged extends AbstractEvent{ - private String type ; private String stateMessage = "상품 변경이 발생함"; private Long productId; @@ -12,16 +11,7 @@ public class ProductChanged { private int productStock; public ProductChanged(){ - this.setType(this.getClass().getSimpleName()); - } - - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; + this.setEventType(this.getClass().getSimpleName()); } public String getStateMessage() { diff --git a/src/main/java/com/example/template/ProductRequired.java b/src/main/java/com/example/template/ProductRequired.java index e99960a..317e233 100644 --- a/src/main/java/com/example/template/ProductRequired.java +++ b/src/main/java/com/example/template/ProductRequired.java @@ -1,19 +1,10 @@ package com.example.template; -public class ProductRequired { +public class ProductRequired extends AbstractEvent{ - private String type ; private String stateMessage; private String productName ; - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - public String getStateMessage() { return stateMessage; } diff --git a/src/main/java/com/example/template/ProductService.java b/src/main/java/com/example/template/ProductService.java index 8c9aa5c..d7b44f9 100644 --- a/src/main/java/com/example/template/ProductService.java +++ b/src/main/java/com/example/template/ProductService.java @@ -32,7 +32,7 @@ public class ProductService { /** * 상품 추가 요청이 왔을때 해당 상품을 찾아서 재고를 늘린다. */ - if( productRequired.getType().equals(ProductRequired.class.getSimpleName())){ + if( productRequired.getEventType().equals(ProductRequired.class.getSimpleName())){ List productList = productRepository.findByName(productRequired.getProductName()); Product product = null; @@ -56,7 +56,7 @@ public class ProductService { /** * 주문이 발생시, 수량을 줄인다. */ - else if( productRequired.getType().equals(OrderPlaced.class.getSimpleName())){ + else if( productRequired.getEventType().equals(OrderPlaced.class.getSimpleName())){ OrderPlaced orderPlaced = objectMapper.readValue(message, OrderPlaced.class); Optional productOptional = productRepository.findById(orderPlaced.getProductId());