|
|
@ -6,23 +6,25 @@ |
|
|
|
using Domain.Events; |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Ordering.API.Application.IntegrationCommands.Commands; |
|
|
|
using Ordering.API.Application.IntegrationEvents; |
|
|
|
|
|
|
|
public class UpdateOrderWhenOrderStockMethodVerifiedDomainEventHandler |
|
|
|
: IAsyncNotificationHandler<OrderStockMethodVerifiedDomainEvent> |
|
|
|
{ |
|
|
|
private readonly IOrderRepository _orderRepository; |
|
|
|
private readonly ILoggerFactory _logger; |
|
|
|
private readonly ILoggerFactory _logger; |
|
|
|
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; |
|
|
|
|
|
|
|
public UpdateOrderWhenOrderStockMethodVerifiedDomainEventHandler( |
|
|
|
IOrderRepository orderRepository, ILoggerFactory logger) |
|
|
|
IOrderRepository orderRepository, ILoggerFactory logger, |
|
|
|
IOrderingIntegrationEventService orderingIntegrationEventService) |
|
|
|
{ |
|
|
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); |
|
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); |
|
|
|
_orderingIntegrationEventService = orderingIntegrationEventService; |
|
|
|
} |
|
|
|
|
|
|
|
// Domain Logic comment:
|
|
|
|
// When the Order Stock items method have been validate and confirmed,
|
|
|
|
// then we can update the original Order with the new order status
|
|
|
|
public async Task Handle(OrderStockMethodVerifiedDomainEvent orderStockMethodVerifiedDomainEvent) |
|
|
|
{ |
|
|
|
var orderToUpdate = await _orderRepository.GetAsync(orderStockMethodVerifiedDomainEvent.OrderId); |
|
|
@ -37,14 +39,9 @@ |
|
|
|
.LogTrace($"Order with Id: {orderStockMethodVerifiedDomainEvent.OrderId} has been successfully updated with " + |
|
|
|
$"a status order id: { orderStockMethodVerifiedDomainEvent.OrderStatus.Id }"); |
|
|
|
|
|
|
|
|
|
|
|
//var payOrderCommandMsg = new PayOrderCommandMsg(order.Id);
|
|
|
|
|
|
|
|
//// Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
|
|
|
|
//await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommandMsg);
|
|
|
|
|
|
|
|
//// Publish through the Event Bus and mark the saved event as published
|
|
|
|
//await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommandMsg);
|
|
|
|
var payOrderCommandMsg = new PayOrderCommandMsg(orderToUpdate.Id); |
|
|
|
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommandMsg); |
|
|
|
await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommandMsg); |
|
|
|
} |
|
|
|
} |
|
|
|
} |