|
|
@ -0,0 +1,47 @@ |
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; |
|
|
|
|
|
|
|
// Regular CommandHandler
|
|
|
|
public class CompleteOrderCommandHandler : IRequestHandler<CompleteOrderCommand, bool> |
|
|
|
{ |
|
|
|
private readonly IOrderRepository _orderRepository; |
|
|
|
|
|
|
|
public CompleteOrderCommandHandler(IOrderRepository orderRepository) |
|
|
|
{ |
|
|
|
_orderRepository = orderRepository; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handler which processes the command when
|
|
|
|
/// shipment company requests to complete order from API
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="command"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<bool> Handle(CompleteOrderCommand command, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber); |
|
|
|
|
|
|
|
if (orderToUpdate == null) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
orderToUpdate.SetCompletedStatus(); |
|
|
|
|
|
|
|
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Use for Idempotency in Command process
|
|
|
|
public class CompleteOrderIdentifiedCommandHandler : IdentifiedCommandHandler<CompleteOrderCommand, bool> |
|
|
|
{ |
|
|
|
public CompleteOrderIdentifiedCommandHandler(IMediator mediator, IRequestManager requestManager, ILogger<IdentifiedCommandHandler<CompleteOrderCommand, bool>> logger) |
|
|
|
: base(mediator, requestManager, logger) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
protected override bool CreateResultForDuplicateRequest() |
|
|
|
{ |
|
|
|
return true; // Ignore duplicate requests for processing order.
|
|
|
|
} |
|
|
|
} |