Search in sources :

Example 1 with ProductAddedToOrderEvent

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));
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Product(pl.com.bottega.erp.sales.domain.Product) ProductAddedToOrderEvent(pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent)

Example 2 with ProductAddedToOrderEvent

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();
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) ProductAddedToOrderEvent(pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent) Client(pl.com.bottega.erp.sales.domain.Client) Map(java.util.Map)

Aggregations

ProductAddedToOrderEvent (pl.com.bottega.erp.sales.application.events.ProductAddedToOrderEvent)2 Order (pl.com.bottega.erp.sales.domain.Order)2 Map (java.util.Map)1 Client (pl.com.bottega.erp.sales.domain.Client)1 Product (pl.com.bottega.erp.sales.domain.Product)1