Skip to content

Commit 2228ca3

Browse files
committed
- Change Integration Command to Integration Events
- Refactor PublishThroughEventBusAsync methods from OrderingIntegrationEventService - Add private empty Address constructor. - Modify order aggregate methods. - Remove GetWithDependenciesAsync methods and modify GetAsync with entity framework Explicit loading.
1 parent 31bdcd0 commit 2228ca3

28 files changed

Lines changed: 142 additions & 183 deletions

src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ public async Task Handle(BuyerAndPaymentMethodVerifiedDomainEvent buyerPaymentMe
3636

3737
var orderStartedIntegrationEvent = new OrderStartedIntegrationEvent(buyerPaymentMethodVerifiedEvent.Buyer.IdentityGuid);
3838

39-
await _orderingIntegrationEventService
40-
.SaveEventAndOrderingContextChangesAsync(orderStartedIntegrationEvent);
41-
42-
await _orderingIntegrationEventService
43-
.PublishThroughEventBusAsync(orderStartedIntegrationEvent);
39+
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStartedIntegrationEvent);
4440

4541
_logger.CreateLogger(nameof(UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler))
4642
.LogTrace($"Order with Id: {buyerPaymentMethodVerifiedEvent.OrderId} has been successfully updated with a payment method id: { buyerPaymentMethodVerifiedEvent.Payment.Id }");

src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using Domain.Events;
77
using System;
88
using System.Threading.Tasks;
9-
using Ordering.API.Application.IntegrationCommands.Commands;
109
using Ordering.API.Application.IntegrationEvents;
1110
using System.Linq;
11+
using Ordering.API.Application.IntegrationEvents.Events;
1212

1313
public class OrderStatusChangedToAwaitingValidationDomainEventHandler
1414
: IAsyncNotificationHandler<OrderStatusChangedToAwaitingValidationDomainEvent>
@@ -35,10 +35,9 @@ public async Task Handle(OrderStatusChangedToAwaitingValidationDomainEvent order
3535
var orderStockList = orderStatusChangedToAwaitingValidationDomainEvent.OrderItems
3636
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
3737

38-
var confirmOrderStockCommand = new ConfirmOrderStockCommand(orderStatusChangedToAwaitingValidationDomainEvent.OrderId,
39-
orderStockList);
40-
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(confirmOrderStockCommand);
41-
await _orderingIntegrationEventService.PublishThroughEventBusAsync(confirmOrderStockCommand);
38+
var orderStatusChangedToAwaitingValidationIntegrationEvent = new OrderStatusChangedToAwaitingValidationIntegrationEvent(
39+
orderStatusChangedToAwaitingValidationDomainEvent.OrderId, orderStockList);
40+
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToAwaitingValidationIntegrationEvent);
4241
}
4342
}
4443
}

src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using Domain.Events;
77
using System;
88
using System.Threading.Tasks;
9-
using Ordering.API.Application.IntegrationCommands.Commands;
109
using Ordering.API.Application.IntegrationEvents;
1110
using System.Linq;
11+
using Ordering.API.Application.IntegrationEvents.Events;
1212

1313
public class OrderStatusChangedToPaidDomainEventHandler
1414
: IAsyncNotificationHandler<OrderStatusChangedToPaidDomainEvent>
@@ -35,10 +35,9 @@ public async Task Handle(OrderStatusChangedToPaidDomainEvent orderStatusChangedT
3535
var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems
3636
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
3737

38-
var decrementOrderStockCommand = new DecrementOrderStockCommand(orderStatusChangedToPaidDomainEvent.OrderId,
38+
var orderStatusChangedToPaidIntegrationEvent = new OrderStatusChangedToPaidIntegrationEvent(orderStatusChangedToPaidDomainEvent.OrderId,
3939
orderStockList);
40-
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommand);
41-
await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommand);
40+
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToPaidIntegrationEvent);
4241
}
4342
}
4443
}

src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using Domain.Events;
77
using System;
88
using System.Threading.Tasks;
9-
using Ordering.API.Application.IntegrationCommands.Commands;
109
using Ordering.API.Application.IntegrationEvents;
10+
using Ordering.API.Application.IntegrationEvents.Events;
1111

1212
public class OrderStatusChangedToStockConfirmedDomainEventHandler
1313
: IAsyncNotificationHandler<OrderStatusChangedToStockConfirmedDomainEvent>
@@ -31,9 +31,8 @@ public async Task Handle(OrderStatusChangedToStockConfirmedDomainEvent orderStat
3131
.LogTrace($"Order with Id: {orderStatusChangedToStockConfirmedDomainEvent.OrderId} has been successfully updated with " +
3232
$"a status order id: {OrderStatus.StockConfirmed.Id}");
3333

34-
var payOrderCommand = new PayOrderCommand(orderStatusChangedToStockConfirmedDomainEvent.OrderId);
35-
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommand);
36-
await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommand);
34+
var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(orderStatusChangedToStockConfirmedDomainEvent.OrderId);
35+
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStatusChangedToStockConfirmedIntegrationEvent);
3736
}
3837
}
3938
}

src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommand.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommand.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public OrderPaymentFailedIntegrationEventHandler(IOrderRepository orderRepositor
1717

1818
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
1919
{
20-
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
20+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2121

2222
orderToUpdate.SetCancelledStatus();
2323

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public OrderPaymentSuccededIntegrationEventHandler(IOrderRepository orderReposit
1717

1818
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
1919
{
20-
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
20+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2121

2222
orderToUpdate.SetPaidStatus();
2323

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public OrderStockConfirmedIntegrationEventHandler(IOrderRepository orderReposito
1717

1818
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
1919
{
20-
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
20+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2121

2222
orderToUpdate.SetStockConfirmedStatus();
2323

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)