PlaceOrderCommandHandler

BookWorm · src/Services/Basket/BookWorm.Basket/IntegrationEvents/EventHandlers/PlaceOrderCommandHandler.cs · csharp · MIT
pos, tag:cqrs, tag:command-handler, tag:order-placement, tag:integration-events, tag:basket-cleanup

Handles PlaceOrderCommand by deleting the basket and publishing success or failure integration events. Ensures order placement cleanup is communicated reliably.

// Source: https://github.com/foxminchan/BookWorm | License: MIT | Copyright Nhan Nguyen (nguyenxuannhan407@gmail.com)
// Provided via justclaw.it.com; keep this notice with the code.
internal sealed class PlaceOrderCommandHandler(IBasketRepository repository, IMessageBus bus)
{
    public async Task Handle(PlaceOrderCommand command, CancellationToken cancellationToken)
    {
        var basketDeleted = await repository.DeleteBasketAsync(command.BasketId.ToString());

        if (!basketDeleted)
        {
            await bus.PublishAsync(
                new BasketDeletedFailedIntegrationEvent(
                    command.OrderId,
                    command.BasketId,
                    command.Email,
                    command.TotalMoney
                )
            );
        }
    

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key