이벤트 프로세스 수정
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
package com.example.template;
|
||||
|
||||
public class ProductRequired extends AbstractEvent{
|
||||
|
||||
private String stateMessage;
|
||||
private String productName ;
|
||||
|
||||
public String getStateMessage() {
|
||||
return stateMessage;
|
||||
}
|
||||
|
||||
public void setStateMessage(String stateMessage) {
|
||||
this.stateMessage = stateMessage;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
}
|
||||
@@ -26,39 +26,14 @@ public class ProductService {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
ProductRequired productRequired = null;
|
||||
OrderPlaced orderPlaced = null;
|
||||
try {
|
||||
productRequired = objectMapper.readValue(message, ProductRequired.class);
|
||||
orderPlaced = objectMapper.readValue(message, OrderPlaced.class);
|
||||
|
||||
/**
|
||||
* 상품 추가 요청이 왔을때 해당 상품을 찾아서 재고를 늘린다.
|
||||
*/
|
||||
if( productRequired.getEventType().equals(ProductRequired.class.getSimpleName())){
|
||||
|
||||
List<Product> productList = productRepository.findByName(productRequired.getProductName());
|
||||
Product product = null;
|
||||
if( productList != null && productList.size() > 0 ){
|
||||
product = productList.get(0);
|
||||
}
|
||||
|
||||
if( product == null ) {
|
||||
product = new Product();
|
||||
product.setName(productRequired.getProductName());
|
||||
product.setPrice(10000);
|
||||
product.setStock(1);
|
||||
}
|
||||
|
||||
// product 의 수량을 10개씩 늘린다
|
||||
product.setStock(product.getStock() + 10);
|
||||
|
||||
productRepository.save(product);
|
||||
|
||||
}
|
||||
/**
|
||||
* 주문이 발생시, 수량을 줄인다.
|
||||
*/
|
||||
else if( productRequired.getEventType().equals(OrderPlaced.class.getSimpleName())){
|
||||
OrderPlaced orderPlaced = objectMapper.readValue(message, OrderPlaced.class);
|
||||
if( orderPlaced.getEventType().equals(OrderPlaced.class.getSimpleName())){
|
||||
|
||||
Optional<Product> productOptional = productRepository.findById(orderPlaced.getProductId());
|
||||
Product product = productOptional.get();
|
||||
|
||||
Reference in New Issue
Block a user