event 추가
This commit is contained in:
29
src/main/java/com/example/template/AbstractEvent.java
Normal file
29
src/main/java/com/example/template/AbstractEvent.java
Normal 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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
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<Product> productOptional = productRepository.findById(orderPlaced.getProductId());
|
||||
|
||||
Reference in New Issue
Block a user