Search in sources :

Example 1 with Product

use of pl.com.bottega.erp.sales.domain.Product in project ddd-cqrs-sample by BottegaIT.

the class AddProductToOrderCommandHandler method handle.

@Override
public Void handle(AddProductToOrderCommand command) {
    Product product = productRepository.load(command.getProductId());
    Order order = orderRepository.load(command.getOrderId());
    order.addProduct(product, command.getQuantity());
    orderRepository.save(order);
    return null;
}
Also used : Order(pl.com.bottega.erp.sales.domain.Order) Product(pl.com.bottega.erp.sales.domain.Product)

Example 2 with Product

use of pl.com.bottega.erp.sales.domain.Product 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)

Aggregations

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