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;
|
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;
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|||||||
Reference in New Issue
Block a user