Commit dad95263 authored by lemin's avatar lemin

commit

parent b7e54815
...@@ -25,31 +25,31 @@ public class WMSAggregate { ...@@ -25,31 +25,31 @@ public class WMSAggregate {
@AggregateIdentifier @AggregateIdentifier
private String id; private String id;
// private int quantiy; private int quantiy;
@CommandHandler @CommandHandler
public WMSAggregate(CreateInventoryCommand command) { public WMSAggregate(CreateInventoryCommand command) {
log.info("[WMSAggregate(CreateInventoryCommand) > apply new InventoryCreatedEvent]"); log.info("[WMSAggregate(CreateInventoryCommand) > apply new InventoryCreatedEvent]");
apply(new InventoryCreatedEvent(command.getId(), command.getName(), command.getComment(), command.getPrice())); apply(new InventoryCreatedEvent(command.getWhId(), command.getProductId(), command.getWhName(), command.getQuantity()));
} }
@EventSourcingHandler @EventSourcingHandler
public void createProduct(InventoryCreatedEvent event) { public void createProduct(InventoryCreatedEvent event) {
this.id = event.getProductId(); this.id = event.getProductId();
// this.quantiy = event.getQuantity(); this.quantiy = event.getQuantity();
} }
@CommandHandler @CommandHandler
public void changeQuantity(ChangeInventoryQuantityCommand command) { public void changeQuantity(ChangeInventoryQuantityCommand command) {
log.info("[@CommandHandler ProductchangeQuantity]"); log.info("[@CommandHandler ProductchangeQuantity]");
// if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy "); if(this.quantiy < command.getQuantity()) throw new IllegalArgumentException("tfy ");
// apply(new InventoryQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity())); apply(new InventoryQuantityChangedEvent(command.getProductId(), this.quantiy - command.getQuantity()));
} }
@EventSourcingHandler @EventSourcingHandler
public void changeQuantity(InventoryQuantityChangedEvent event) { public void changeQuantity(InventoryQuantityChangedEvent event) {
// this.quantiy = event.getQuantity(); this.quantiy = event.getQuantity();
} }
} }
...@@ -11,10 +11,9 @@ import java.math.BigDecimal; ...@@ -11,10 +11,9 @@ import java.math.BigDecimal;
public class CreateInventoryCommand { public class CreateInventoryCommand {
@TargetAggregateIdentifier @TargetAggregateIdentifier
private final String id; private final String whId;
private final String name; private final String productId;
private final String comment; private final String whName;
private final BigDecimal price; private final Integer quantity;
// private final Integer quantity;
} }
...@@ -33,12 +33,11 @@ public class WMSController { ...@@ -33,12 +33,11 @@ public class WMSController {
@PostMapping("/") @PostMapping("/")
public ResponseEntity<Map<String, String>> inventoryCreate(@RequestBody InventoryCreateDto inventoryCreateDto) { public ResponseEntity<Map<String, String>> inventoryCreate(@RequestBody InventoryCreateDto inventoryCreateDto) {
String inventoryId = inventoryService.createInventory(inventoryCreateDto.getName(), String inventoryId = inventoryService.createInventory(inventoryCreateDto.getProductId(), inventoryCreateDto.getWhName(),
inventoryCreateDto.getComment(), inventoryCreateDto.getQuantity());
BigDecimal.valueOf(inventoryCreateDto.getPrice()));
HashMap<String, String> m = new HashMap<>(); HashMap<String, String> m = new HashMap<>();
m.put("inventoryId", inventoryId); m.put("inventoryId", inventoryId);
m.put("productName", inventoryCreateDto.getName()); m.put("whName", inventoryCreateDto.getWhName());
return ResponseEntity.ok(m); return ResponseEntity.ok(m);
} }
......
...@@ -6,8 +6,9 @@ import lombok.Setter; ...@@ -6,8 +6,9 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
public class InventoryCreateDto { public class InventoryCreateDto {
private String name; // private String whId;
private String comment; private String productId;
private int price; private String whName;
private Integer quantity;
} }
...@@ -16,8 +16,8 @@ import java.math.BigDecimal; ...@@ -16,8 +16,8 @@ import java.math.BigDecimal;
@NoArgsConstructor @NoArgsConstructor
public class InventoryEntity { public class InventoryEntity {
@Id @Id
private String id; private String whId;
private String name; private String productId;
private String comment; private String whName;
private BigDecimal price; private int quantity;
} }
...@@ -8,8 +8,8 @@ import java.math.BigDecimal; ...@@ -8,8 +8,8 @@ import java.math.BigDecimal;
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public class InventoryCreatedEvent { public class InventoryCreatedEvent {
private String whId;
private String productId; private String productId;
private String name; private String whName;
private String comment; private int quantity;
private BigDecimal price;
} }
...@@ -15,31 +15,31 @@ import com.showcase.synapse.wms.repository.InventoryRepository; ...@@ -15,31 +15,31 @@ import com.showcase.synapse.wms.repository.InventoryRepository;
@Slf4j @Slf4j
public class InventoryEventHandler { public class InventoryEventHandler {
private final InventoryRepository productRepository; private final InventoryRepository inventoryRepository;
@EventHandler @EventHandler
protected void saveProduct(InventoryCreatedEvent productCreatedEvent) { protected void saveProduct(InventoryCreatedEvent inventoryCreatedEvent) {
log.info("InventoryCreatedEvent 이벤트 받음?"); log.info("InventoryCreatedEvent 이벤트 받음?");
log.info("InventoryEventHandler > [InventoryCreatedEvent] productCreatedEvent"); log.info("InventoryEventHandler > [InventoryCreatedEvent] productCreatedEvent");
InventoryEntity productEntity = new InventoryEntity(); InventoryEntity inventoryEntity = new InventoryEntity();
productEntity.setId(productCreatedEvent.getProductId()); inventoryEntity.setProductId(inventoryCreatedEvent.getProductId());
productEntity.setName(productCreatedEvent.getName()); inventoryEntity.setWhId(inventoryCreatedEvent.getWhId());
productEntity.setComment(productCreatedEvent.getComment()); inventoryEntity.setWhName(inventoryCreatedEvent.getWhName());
productEntity.setPrice(productCreatedEvent.getPrice()); inventoryEntity.setQuantity(inventoryCreatedEvent.getQuantity());
productRepository.save(productEntity); inventoryRepository.save(inventoryEntity);
} }
@EventHandler @EventHandler
protected void changeQuantity(InventoryQuantityChangedEvent productQuantityChangedEvent) { protected void changeQuantity(InventoryQuantityChangedEvent inventoryQuantityChangedEvent) {
log.info("InventoryQuantityChangedEvent 이벤트 받음?"); log.info("InventoryQuantityChangedEvent 이벤트 받음?");
log.info("[InventoryQuantityChangedEvent]"); log.info("[InventoryQuantityChangedEvent]");
InventoryEntity productEntity = productRepository.findById(productQuantityChangedEvent.getProductId()).get(); InventoryEntity inventoryEntity = inventoryRepository.findById(inventoryQuantityChangedEvent.getProductId()).get();
// log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity()); // log.info("[{}] quantity:{}", productEntity.getName(), productEntity.getQuentity());
// productEntity.setQuentity(productQuantityChangedEvent.getQuantity()); // productEntity.setQuentity(productQuantityChangedEvent.getQuantity());
productRepository.save(productEntity); inventoryRepository.save(inventoryEntity);
} }
} }
...@@ -17,12 +17,12 @@ import lombok.extern.slf4j.Slf4j; ...@@ -17,12 +17,12 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class InventoryQueryHandler { public class InventoryQueryHandler {
private final InventoryRepository productRepository; private final InventoryRepository inventoryRepository;
@QueryHandler @QueryHandler
protected List<InventoryEntity> on(GetInventoryQuery query) { protected List<InventoryEntity> on(GetInventoryQuery query) {
log.info("---product query---"); log.info("---product query---");
return productRepository.findAll(); return inventoryRepository.findAll();
} }
} }
package com.showcase.synapse.wms.service; package com.showcase.synapse.wms.service;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
...@@ -28,16 +27,16 @@ public class InventoryService { ...@@ -28,16 +27,16 @@ public class InventoryService {
this.queryGateway = queryGateway; this.queryGateway = queryGateway;
} }
public String createInventory(String name, String comment, BigDecimal price) { public String createInventory(String productId, String whName, int quantity) {
log.info("[@Service createProduct] new CreateInventoryCommand"); log.info("[@Service createProduct] new CreateInventoryCommand");
// command생성 // command생성
CreateInventoryCommand createProductCommand = new CreateInventoryCommand( CreateInventoryCommand createInventoryCommand = new CreateInventoryCommand(
UUID.randomUUID().toString(), name, comment, price UUID.randomUUID().toString(), productId, whName, quantity
); );
System.out.println("test");
// 여기 // 여기
// 생성한 command전송(비동기) // 생성한 command전송(비동기)
String returnValue = commandGateway.sendAndWait(createProductCommand); log.info("[command전송] 비동기");
String returnValue = commandGateway.sendAndWait(createInventoryCommand);
System.out.printf("returnValue: %s \n", returnValue); System.out.printf("returnValue: %s \n", returnValue);
return returnValue; return returnValue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment