use of pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent in project ddd-cqrs-sample by BottegaIT.
the class PurchaseApplicationService method addProductToOrder.
/**
* Sample call of the domain logic<br>
* Sample publishing Application (not Domain) Event
*
* @param productId
* @param orderId
* @param quantity
*/
public void addProductToOrder(Long productId, Long orderId, int quantity) {
Order order = orderRepository.load(orderId);
Product product = productRepository.load(productId);
// Domain logic
order.addProduct(product, quantity);
orderRepository.save(order);
// if we want to Spy Clients:)
eventPublisher.publish(new ProductAddedToOrderEvent(product.getEntityId(), systemUser.getUserId(), quantity));
}
use of pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent in project ddd-cqrs-sample by BottegaIT.
the class CreateOrderCommandHandler method handle.
@Override
public Long handle(CreateOrderCommand command) {
Client currentClient = clientRepository.load(systemUser.getUserId());
Order order = orderFactory.crateOrder(currentClient);
for (Map.Entry<Long, Integer> productIdWithCount : command.getProductIdsWithCounts().entrySet()) {
Long productId = productIdWithCount.getKey();
Integer count = productIdWithCount.getValue();
order.addProduct(productRepository.load(productId), count);
applicationEventPublisher.publish(new ProductAddedToOrderEvent(productId, systemUser.getUserId(), 1));
}
orderRepository.persist(order);
return order.getEntityId();
}
Aggregations