8000 Merge branch 'order-processflow-redesign' of https://github.com/dotne… · ITCSsDeveloper/eShopOnContainers@8045d63 · GitHub
Skip to content

Commit 8045d63

Browse files
committed
Merge branch 'order-processflow-redesign' of https://github.com/dotnet-architecture/eShopOnContainers into order-processflow-redesign
2 parents f302316 + 2f41736 commit 8045d63

22 files changed

Lines changed: 396 additions & 45 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ public async Task Handle(BuyerAndPaymentMethodVerifiedDomainEvent buyerPaymentMe
3636

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

39-
// Using a local transaction to achieve atomicity between original Ordering database operation and
40-
// the IntegrationEventLog. Only saving event if order has been successfully persisted to db
4139
await _orderingIntegrationEventService
4240
.SaveEventAndOrderingContextChangesAsync(orderStartedIntegrationEvent);
4341

44-
// Publish ordering integration event and mark it as published
4542
await _orderingIntegrationEventService
4643
.PublishThroughEventBusAsync(orderStartedIntegrationEvent);
4744

src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmation/UpdateOrderWhenOrderStockMethodVerifiedDomainEventHandler.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66
using Domain.Events;
77
using System;
88
using System.Threading.Tasks;
9+
using Ordering.API.Application.IntegrationCommands.Commands;
10+
using Ordering.API.Application.IntegrationEvents;
911

1012
public class UpdateOrderWhenOrderStockMethodVerifiedDomainEventHandler
1113
: IAsyncNotificationHandler<OrderStockMethodVerifiedDomainEvent>
1214
{
1315
private readonly IOrderRepository _orderRepository;
14-
private readonly ILoggerFactory _logger;
16+
private readonly ILoggerFactory _logger;
17+
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
1518

1619
public UpdateOrderWhenOrderStockMethodVerifiedDomainEventHandler(
17-
IOrderRepository orderRepository, ILoggerFactory logger)
20+
IOrderRepository orderRepository, ILoggerFactory logger,
21+
IOrderingIntegrationEventService orderingIntegrationEventService)
1822
{
1923
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
2024
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
25+
_orderingIntegrationEventService = orderingIntegrationEventService;
2126
}
2227

23-
// Domain Logic comment:
24-
// When the Order Stock items method have been validate and confirmed,
25-
// then we can update the original Order with the new order status
2628
public async Task Handle(OrderStockMethodVerifiedDomainEvent orderStockMethodVerifiedDomainEvent)
2729
{
2830
var orderToUpdate = await _orderRepository.GetAsync(orderStockMethodVerifiedDomainEvent.OrderId);
@@ -37,14 +39,9 @@ await _orderRepository.UnitOfWork
3739
.LogTrace($"Order with Id: {orderStockMethodVerifiedDomainEvent.OrderId} has been successfully updated with " +
3840
$"a status order id: { orderStockMethodVerifiedDomainEvent.OrderStatus.Id }");
3941

40-
41-
//var payOrderCommandMsg = new PayOrderCommandMsg(order.Id);
42-
43-
//// Achieving atomicity between original Catalog database operation and the IntegrationEventLog thanks to a local transaction
44-
//await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommandMsg);
45-
46-
//// Publish through the Event Bus and mark the saved event as published
47-
//await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommandMsg);
42+
var payOrderCommandMsg = new PayOrderCommandMsg(orderToUpdate.Id);
43+
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommandMsg);
44+
await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommandMsg);
4845
}
4946
}
5047
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Ordering.API.Application.IntegrationEvents.EventHandling
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
4+
using Ordering.API.Application.IntegrationEvents.Events;
5+
using System.Threading.Tasks;
6+
7+
public class OrderPaymentFailedIntegrationEventHandler :
8+
IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>
9+
{
10+
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
11+
{
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Ordering.API.Application.IntegrationEvents.EventHandling
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
4+
using Ordering.API.Application.IntegrationEvents.Events;
5+
using System.Threading.Tasks;
6+
7+
public class OrderPaymentSuccededIntegrationEventHandler :
8+
IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>
9+
{
10+
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
11+
{
12+
}
13+
}
14+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
using Ordering.API.Application.IntegrationCommands.Commands;
88
using Ordering.Domain.Exceptions;
99

10-
public class OrderStockConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
10+
public class OrderStockConfirmedIntegrationEventHandler :
11+
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
1112
{
1213
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
1314
private readonly IOrderRepository _orderRepository;
@@ -25,7 +26,7 @@ public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
2526
var order = await _orderRepository.GetAsync(@event.OrderId);
2627
CheckValidSagaId(order);
2728

28-
order.SetOrderStockConfirmed(true);
29+
order.SetOrderStockConfirmed();
2930

3031
//Create Integration Event to be published through the Event Bus
3132
var payOrderCommandMsg = new PayOrderCommandMsg(order.Id);

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Ordering.API.Application.IntegrationEvents.EventHandling
1+
using System.Linq;
2+
3+
namespace Ordering.API.Application.IntegrationEvents.EventHandling
24
{
35
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
46
using System;
@@ -27,14 +29,11 @@ public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
2729
var order = await _orderRepository.GetAsync(@event.OrderId);
2830
CheckValidSagaId(order);
2931

30-
order.SetOrderStockConfirmed(false);
31-
32-
var orderStockNotConfirmedItems = @event.OrderStockItems.FindAll(c => !c.Confirmed);
32+
var orderStockNotConfirmedItems = @event.OrderStockItems
33+
.FindAll(c => !c.Confirmed)
34+
.Select(c => c.ProductId);
3335

34-
foreach (var orderStockNotConfirmedItem in orderStockNotConfirmedItems)
35-
{
36-
//TODO: Add messages
37-
}
36+
order.SetOrderStockConfirmed(orderStockNotConfirmedItems);
3837
}
3938

4039
private void CheckValidSagaId(Order orderSaga)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using MediatR;
1+
using System;
2+
using MediatR;
23
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
4+
using System.Threading.Tasks;
35
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
46
using Microsoft.Extensions.Logging;
57
using Ordering.API.Application.IntegrationEvents.Events;
6-
using System;
7-
using System.Threading.Tasks;
88

99
namespace Ordering.API.Application.IntegrationEvents.EventHandling
1010
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
2+
3+
namespace Ordering.API.Application.IntegrationEvents.Events
4+
{
5+
public class OrderPaymentFailedIntegrationEvent : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public OrderPaymentFailedIntegrationEvent(int orderId) => OrderId = orderId;
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
2+
3+
namespace Ordering.API.Application.IntegrationEvents.Events
4+
{
5+
public class OrderPaymentSuccededIntegrationEvent : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public OrderPaymentSuccededIntegrationEvent(int orderId) => OrderId = orderId;
10+
}
11+
}

src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task<dynamic> GetOrderAsync(int id)
2626
connection.Open();
2727

2828
var result = await connection.QueryAsync<dynamic>(
29-
@"select o.[Id] as ordernumber,o.OrderDate as date, os.Name as status,
29+
@"select o.[Id] as ordernumber,o.OrderDate as date, o.Description as description, os.Name as status,
3030
oi.ProductName as productname, oi.Units as units, oi.UnitPrice as unitprice, oi.PictureUrl as pictureurl,
3131
a.Street as street, a.City as city, a.Country as country, a.State as state, a.ZipCode as zipcode
3232
FROM ordering.Orders o
@@ -75,6 +75,7 @@ private dynamic MapOrderItems(dynamic result)
7575
order.ordernumber = result[0].ordernumber;
7676
order.date = result[0].date;
7777
order.status = result[0].status;
78+
order.description = result[0].description;
7879
order.street = result[0].street;
7980
order.city = result[0].city;
8081
order.zipcode = result[0].zipcode;

0 commit comments

Comments
 (0)