Skip to content

Commit d043e10

Browse files
committed
Merge branch 'order-processflow-redesign' of https://github.com/dotnet-architecture/eShopOnContainers into order-processflow-redesign
2 parents bc1c376 + ca56f63 commit d043e10

12 files changed

Lines changed: 73 additions & 57 deletions

File tree

src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,11 @@ public async Task Handle(DecrementOrderStockCommandMsg @event)
2323
foreach (var orderStockItem in @event.OrderStockItems)
2424
{
2525
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
26-
CheckValidcatalogItemId(catalogItem);
2726

2827
catalogItem.RemoveStock(orderStockItem.Units);
2928
}
3029

3130
await _catalogContext.SaveChangesAsync();
3231
}
33-
34-
private void CheckValidcatalogItemId(CatalogItem catalogItem)
35-
{
36-
if (catalogItem is null)
37-
{
38-
throw new CatalogDomainException("Not able to process catalog event. Reason: no valid catalogItemId");
39-
}
40-
}
4132
}
4233
}

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

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

1818
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
1919
{
20-
//TODO: Cancel Order
20+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
21+
22+
orderToUpdate.SetCancelledStatus();
2123
}
2224
}
2325
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
44
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
55
using Ordering.API.Application.IntegrationEvents.Events;
6-
using Ordering.Domain.Exceptions;
76
using System.Threading.Tasks;
87

98
public class OrderPaymentSuccededIntegrationEventHandler :
@@ -18,18 +17,9 @@ public OrderPaymentSuccededIntegrationEventHandler(IOrderRepository orderReposit
1817

1918
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
2019
{
21-
var order = await _orderRepository.GetAsync(@event.OrderId);
22-
CheckValidSagaId(order);
20+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2321

24-
order.SetPaidStatus();
25-
}
26-
27-
private void CheckValidSagaId(Order orderSaga)
28-
{
29-
if (orderSaga is null)
30-
{
31-
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
32-
}
22+
orderToUpdate.SetPaidStatus();
3323
}
3424
}
3525
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
using System.Threading.Tasks;
55
using Events;
66
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
7-
using Ordering.API.Application.IntegrationCommands.Commands;
8-
using Ordering.Domain.Exceptions;
97

108
public class OrderStockConfirmedIntegrationEventHandler :
119
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
@@ -19,18 +17,9 @@ public OrderStockConfirmedIntegrationEventHandler(IOrderRepository orderReposito
1917

2018
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
2119
{
22-
var order = await _orderRepository.GetAsync(@event.OrderId);
23-
CheckValidSagaId(order);
20+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2421

25-
order.SetStockConfirmedStatus();
26-
}
27-
28-
private void CheckValidSagaId(Order orderSaga)
29-
{
30-
if (orderSaga is null)
31-
{
32-
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
33-
}
22+
orderToUpdate.SetStockConfirmedStatus();
3423
}
3524
}
3625
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
namespace Ordering.API.Application.IntegrationEvents.EventHandling
55
{
66
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
7-
using System;
87
using System.Threading.Tasks;
98
using Events;
109
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
11-
using Domain.Exceptions;
1210

1311
public class OrderStockNotConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>
1412
{
@@ -22,21 +20,12 @@ public OrderStockNotConfirmedIntegrationEventHandler(IOrderRepository orderRepos
2220
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
2321
{
2422
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
25-
CheckValidSagaId(orderToUpdate);
2623

2724
var orderStockNotConfirmedItems = @event.OrderStockItems
2825
.FindAll(c => !c.Confirmed)
2926
.Select(c => c.ProductId);
3027

3128
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
3229
}
33-
34-
private void CheckValidSagaId(Order orderSaga)
35-
{
36-
if (orderSaga is null)
37-
{
38-
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
39-
}
40-
}
4130
}
4231
}

src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public async Task<bool> Handle(CancelOrderCommand command)
7373
if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id
7474
|| orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id)
7575
{
76-
orderSaga.SetCancelStatus();
76+
orderSaga.SetCancelledStatus();
7777
result = await SaveChangesAsync();
7878
}
7979
return result;

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,31 @@ public void SetShippedStatus()
166166
//Call Domain Event
167167
}
168168

169-
public void SetCancelStatus()
169+
public void SetCancelledStatus()
170170
{
171-
if (_orderStatusId == OrderStatus.Shipped.Id)
171+
if (_orderStatusId == OrderStatus.Submited.Id)
172172
{
173-
throw new OrderingDomainException("Not possible to change order status. Reason: cannot cancel order it is already shipped");
173+
_description = "The order was cancelled before the grace period was confirm.";
174174
}
175+
else if (_orderStatusId == OrderStatus.AwaitingValidation.Id)
176+
{
177+
_description = "The order was cancelled before to check the order stock items.";
178+
}
179+
else if (_orderStatusId == OrderStatus.StockConfirmed.Id)
180+
{
181+
_description = "The order was cancelled before to pay the order.";
182+
}
183+
else if (_orderStatusId == OrderStatus.Paid.Id)
184+
{
185+
_description = "The order was cancelled before to ship the order.";
186+
}
187+
else if(_orderStatusId == OrderStatus.Shipped.Id)
188+
{
189+
throw new OrderingDomainException("Not possible to change order status. Reason: cannot cancel order it is already shipped.");
190+
}
191+
175192
_orderStatusId = OrderStatus.Cancelled.Id;
176-
}
193+
}
177194

178195
#endregion
179196

src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.EntityFrameworkCore;
22
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
33
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
4+
using Ordering.Domain.Exceptions;
45
using System;
56
using System.Threading.Tasks;
67

src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44
using Payment.API.IntegrationCommands.Commands;
55
using System.Threading.Tasks;
66
using System;
7+
using Payment.API.IntegrationEvents;
8+
using Payment.API.IntegrationEvents.Events;
79

810
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
911
{
10-
public PayOrderCommandMsgHandler()
11-
{
12-
}
12+
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService;
13+
14+
public PayOrderCommandMsgHandler(IPaymentIntegrationEventService paymentIntegrationEventService)
15+
=> _paymentIntegrationEventService = paymentIntegrationEventService;
1316

1417
public async Task Handle(PayOrderCommandMsg @event)
1518
{
16-
throw new NotImplementedException();
19+
//PAYMENT SUCCESSED
20+
var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
21+
_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentSuccededIntegrationEvent);
22+
23+
//PAYMENT FAILED
24+
//var orderPaymentFailedIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
25+
//_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent);
1726
}
1827
}
1928
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Payment.API.IntegrationEvents
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
5+
public interface IPaymentIntegrationEventService
6+
{
7+
void PublishThroughEventBus(IntegrationEvent evt);
8+
}
9+
}

0 commit comments

Comments
 (0)