event 추가

This commit is contained in:
kimscott
2019-09-02 14:03:14 +09:00
parent 1582193da0
commit 8d25923887
5 changed files with 35 additions and 35 deletions

View File

@@ -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());
}
}

View File

@@ -2,9 +2,7 @@ package com.example.template;
import java.io.Serializable; import java.io.Serializable;
public class OrderPlaced implements Serializable { public class OrderPlaced extends AbstractEvent {
private String type;
private Long productId; private Long productId;
private Long orderId; private Long orderId;
@@ -14,14 +12,6 @@ public class OrderPlaced implements Serializable {
private String customerName; private String customerName;
private String customerAddr; private String customerAddr;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Long getProductId() { public Long getProductId() {
return productId; return productId;

View File

@@ -1,8 +1,7 @@
package com.example.template; package com.example.template;
public class ProductChanged { public class ProductChanged extends AbstractEvent{
private String type ;
private String stateMessage = "상품 변경이 발생함"; private String stateMessage = "상품 변경이 발생함";
private Long productId; private Long productId;
@@ -12,16 +11,7 @@ public class ProductChanged {
private int productStock; private int productStock;
public ProductChanged(){ public ProductChanged(){
this.setType(this.getClass().getSimpleName()); this.setEventType(this.getClass().getSimpleName());
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
} }
public String getStateMessage() { public String getStateMessage() {

View File

@@ -1,19 +1,10 @@
package com.example.template; package com.example.template;
public class ProductRequired { public class ProductRequired extends AbstractEvent{
private String type ;
private String stateMessage; private String stateMessage;
private String productName ; private String productName ;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getStateMessage() { public String getStateMessage() {
return stateMessage; return stateMessage;
} }

View File

@@ -32,7 +32,7 @@ public class ProductService {
/** /**
* 상품 추가 요청이 왔을때 해당 상품을 찾아서 재고를 늘린다. * 상품 추가 요청이 왔을때 해당 상품을 찾아서 재고를 늘린다.
*/ */
if( productRequired.getType().equals(ProductRequired.class.getSimpleName())){ if( productRequired.getEventType().equals(ProductRequired.class.getSimpleName())){
List<Product> productList = productRepository.findByName(productRequired.getProductName()); List<Product> productList = productRepository.findByName(productRequired.getProductName());
Product product = null; 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); OrderPlaced orderPlaced = objectMapper.readValue(message, OrderPlaced.class);
Optional<Product> productOptional = productRepository.findById(orderPlaced.getProductId()); Optional<Product> productOptional = productRepository.findById(orderPlaced.getProductId());