Commit dad95263 authored by lemin's avatar lemin

commit

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