Skip to content

Commit 87201a3

Browse files
committed
Merge branch 'order-processflow-redesign' of https://github.com/dotnet-architecture/eShopOnContainers into order-processflow-redesign
2 parents 1df3dc7 + 689096f commit 87201a3

53 files changed

Lines changed: 273 additions & 357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docker-compose.override.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ services:
1111
environment:
1212
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
1313
- EventBusConnection=rabbitmq
14-
- GracePeriod=15 #In minutes
1514

1615
basket.api:
1716
environment:

src/Services/Basket/Basket.API/Controllers/BasketController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public async Task<IActionResult> Post([FromBody]CustomerBasket value)
5353

5454
[Route("checkout")]
5555
[HttpPost]
56-
public async Task<IActionResult> Checkout([FromBody]BasketCheckout value, [FromHeader(Name = "x-requestid")] string requestId)
56+
public async Task<IActionResult> Checkout([FromBody]BasketCheckout basketCheckout, [FromHeader(Name = "x-requestid")] string requestId)
5757
{
5858
var userId = _identitySvc.GetUserIdentity();
59-
value.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
60-
guid : value.RequestId;
59+
basketCheckout.RequestId = (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty) ?
60+
guid : basketCheckout.RequestId;
6161

6262
var basket = await _repository.GetBasketAsync(userId);
63-
var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, value.City, value.Street,
64-
value.State, value.Country, value.ZipCode, value.CardNumber, value.CardHolderName,
65-
value.CardExpiration, value.CardSecurityNumber, value.CardTypeId, value.Buyer, value.RequestId, basket);
63+
var eventMessage = new UserCheckoutAcceptedIntegrationEvent(userId, basketCheckout.City, basketCheckout.Street,
64+
basketCheckout.State, basketCheckout.Country, basketCheckout.ZipCode, basketCheckout.CardNumber, basketCheckout.CardHolderName,
65+
basketCheckout.CardExpiration, basketCheckout.CardSecurityNumber, basketCheckout.CardTypeId, basketCheckout.Buyer, basketCheckout.RequestId, basket);
6666

6767
// Once basket is checkout, sends an integration event to
6868
// ordering.api to convert basket to order and proceeds with

src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs renamed to src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,46 @@
1-
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers
1+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
22
{
33
using BuildingBlocks.EventBus.Abstractions;
44
using System.Threading.Tasks;
55
using BuildingBlocks.EventBus.Events;
66
using Infrastructure;
77
using System.Collections.Generic;
88
using System.Linq;
9-
using global::Catalog.API.Infrastructure.Exceptions;
109
using global::Catalog.API.IntegrationEvents;
11-
using Model;
12-
using Commands;
1310
using IntegrationEvents.Events;
1411

15-
public class ConfirmOrderStockCommandHandler : IIntegrationEventHandler<ConfirmOrderStockCommand>
12+
public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
13+
IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>
1614
{
1715
private readonly CatalogContext _catalogContext;
1816
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
1917

20-
public ConfirmOrderStockCommandHandler(CatalogContext catalogContext,
18+
public OrderStatusChangedToAwaitingValidationIntegrationEventHandler(CatalogContext catalogContext,
2119
ICatalogIntegrationEventService catalogIntegrationEventService)
2220
{
2321
_catalogContext = catalogContext;
2422
_catalogIntegrationEventService = catalogIntegrationEventService;
2523
}
2624

27-
public async Task Handle(ConfirmOrderStockCommand command)
25+
public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent command)
2826
{
2927
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();
3028

3129
foreach (var orderStockItem in command.OrderStockItems)
3230
{
3331
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
34-
CheckValidcatalogItemId(catalogItem);
35-
36-
var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id,
37-
catalogItem.AvailableStock >= orderStockItem.Units);
32+
var hasStock = catalogItem.AvailableStock >= orderStockItem.Units;
33+
var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id, hasStock);
3834

3935
confirmedOrderStockItems.Add(confirmedOrderStockItem);
4036
}
4137

4238
var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.HasStock)
43-
? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(command.OrderId, confirmedOrderStockItems)
39+
? (IntegrationEvent) new OrderStockRejectedIntegrationEvent(command.OrderId, confirmedOrderStockItems)
4440
: new OrderStockConfirmedIntegrationEvent(command.OrderId);
4541

4642
await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent);
4743
await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent);
4844
}
49-
50-
private void CheckValidcatalogItemId(CatalogItem catalogItem)
51-
{
52-
if (catalogItem is null)
53-
{
54-
throw new CatalogDomainException("Not able to process catalog event. Reason: no valid catalogItemId");
55-
}
56-
}
5745
}
5846
}

src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs renamed to src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers
1+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
22
{
33
using BuildingBlocks.EventBus.Abstractions;
44
using System.Threading.Tasks;
55
using Infrastructure;
6-
using Commands;
6+
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
77

8-
public class DecrementOrderStockCommandHandler : IIntegrationEventHandler<DecrementOrderStockCommand>
8+
public class OrderStatusChangedToPaidIntegrationEventHandler :
9+
IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
910
{
1011
private readonly CatalogContext _catalogContext;
1112

12-
public DecrementOrderStockCommandHandler(CatalogContext catalogContext)
13+
public OrderStatusChangedToPaidIntegrationEventHandler(CatalogContext catalogContext)
1314
{
1415
_catalogContext = catalogContext;
1516
}
1617

17-
public async Task Handle(DecrementOrderStockCommand command)
18+
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
1819
{
1920
//we're not blocking stock/inventory
2021
foreach (var orderStockItem in command.OrderStockItems)

src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs renamed to src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands
1+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
22
{
33
using BuildingBlocks.EventBus.Events;
44
using System.Collections.Generic;
55

6-
public class ConfirmOrderStockCommand : IntegrationEvent
6+
public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent
77
{
88
public int OrderId { get; }
99
public IEnumerable<OrderStockItem> OrderStockItems { get; }
1010

11-
public ConfirmOrderStockCommand(int orderId,
11+
public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId,
1212
IEnumerable<OrderStockItem> orderStockItems)
1313
{
1414
OrderId = orderId;

src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs renamed to src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands
1+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
22
{
33
using System.Collections.Generic;
44
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
55

6-
public class DecrementOrderStockCommand : IntegrationEvent
6+
public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent
77
{
88
public int OrderId { get; }
99
public IEnumerable<OrderStockItem> OrderStockItems { get; }
1010

11-
public DecrementOrderStockCommand(int orderId,
11+
public OrderStatusChangedToPaidIntegrationEvent(int orderId,
1212
IEnumerable<OrderStockItem> orderStockItems)
1313
{
1414
OrderId = orderId;

src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs renamed to src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockRejectedIntegrationEvent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
using BuildingBlocks.EventBus.Events;
44
using System.Collections.Generic;
55

6-
public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
6+
public class OrderStockRejectedIntegrationEvent : IntegrationEvent
77
{
88
public int OrderId { get; }
99

1010
public List<ConfirmedOrderStockItem> OrderStockItems { get; }
1111

12-
public OrderStockNotConfirmedIntegrationEvent(int orderId,
12+
public OrderStockRejectedIntegrationEvent(int orderId,
1313
List<ConfirmedOrderStockItem> orderStockItems)
1414
{
1515
OrderId = orderId;

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
1515
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
1616
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
17-
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands;
18-
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
19-
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers;
17+
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
18+
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
2019
using Microsoft.Extensions.Configuration;
2120
using Microsoft.Extensions.DependencyInjection;
2221
using Microsoft.Extensions.HealthChecks;
@@ -27,7 +26,7 @@
2726
using System.Data.Common;
2827
using System.Data.SqlClient;
2928
using System.Reflection;
30-
29+
3130
public class Startup
3231
{
3332
public IConfigurationRoot Configuration { get; }
@@ -190,19 +189,20 @@ private void RegisterServiceBus(IServiceCollection services)
190189
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
191190
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
192191

193-
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommand>,
194-
ConfirmOrderStockCommandHandler>();
195-
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommand>,
196-
DecrementOrderStockCommandHandler>();
197-
192+
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>,
193+
OrderStatusChangedToAwaitingValidationIntegrationEventHandler>();
194+
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>,
195+
OrderStatusChangedToPaidIntegrationEventHandler>();
198196
}
199197

200198
private void ConfigureEventBus(IApplicationBuilder app)
201199
{
202200
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
203201

204-
eventBus.Subscribe<ConfirmOrderStockCommand, IIntegrationEventHandler<ConfirmOrderStockCommand>>();
205-
eventBus.Subscribe<DecrementOrderStockCommand, IIntegrationEventHandler<DecrementOrderStockCommand>>();
202+
eventBus.Subscribe<OrderStatusChangedToAwaitingValidationIntegrationEvent,
203+
IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent>>();
204+
eventBus.Subscribe<OrderStatusChangedToPaidIntegrationEvent,
205+
IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>>();
206206
}
207207
}
208208
}

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
}

0 commit comments

Comments
 (0)