Skip to content

Commit 55bd3bf

Browse files
committed
remove CheckValidSagaId replicated method
1 parent 1d832a6 commit 55bd3bf

4 files changed

Lines changed: 8 additions & 32 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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;
67
using System.Threading.Tasks;
78

89
public class OrderPaymentFailedIntegrationEventHandler :
@@ -17,7 +18,9 @@ public OrderPaymentFailedIntegrationEventHandler(IOrderRepository orderRepositor
1718

1819
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
1920
{
20-
//TODO: Cancel Order
21+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
22+
23+
orderToUpdate.SetCancelledStatus();
2124
}
2225
}
2326
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,9 @@ public OrderPaymentSuccededIntegrationEventHandler(IOrderRepository orderReposit
1818

1919
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
2020
{
21-
var order = await _orderRepository.GetAsync(@event.OrderId);
22-
CheckValidSagaId(order);
21+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2322

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-
}
23+
orderToUpdate.SetPaidStatus();
3324
}
3425
}
3526
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,9 @@ public OrderStockConfirmedIntegrationEventHandler(IOrderRepository orderReposito
1919

2020
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
2121
{
22-
var order = await _orderRepository.GetAsync(@event.OrderId);
23-
CheckValidSagaId(order);
22+
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
2423

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-
}
24+
orderToUpdate.SetStockConfirmedStatus();
3425
}
3526
}
3627
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@ public OrderStockNotConfirmedIntegrationEventHandler(IOrderRepository orderRepos
2222
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
2323
{
2424
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
25-
CheckValidSagaId(orderToUpdate);
2625

2726
var orderStockNotConfirmedItems = @event.OrderStockItems
2827
.FindAll(c => !c.Confirmed)
2928
.Select(c => c.ProductId);
3029

3130
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
3231
}
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-
}
4132
}
4233
}

0 commit comments

Comments
 (0)