remove CheckValidSagaId replicated method

This commit is contained in:
Christian Arenas 2017-05-16 10:18:57 +02:00
parent ea1c50db7b
commit e6c59f093c
4 changed files with 8 additions and 32 deletions

View File

@ -3,6 +3,7 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Ordering.API.Application.IntegrationEvents.Events; using Ordering.API.Application.IntegrationEvents.Events;
using Ordering.Domain.Exceptions;
using System.Threading.Tasks; using System.Threading.Tasks;
public class OrderPaymentFailedIntegrationEventHandler : public class OrderPaymentFailedIntegrationEventHandler :
@ -17,7 +18,9 @@
public async Task Handle(OrderPaymentFailedIntegrationEvent @event) public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
{ {
//TODO: Cancel Order var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
orderToUpdate.SetCancelledStatus();
} }
} }
} }

View File

@ -18,18 +18,9 @@
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event) public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
{ {
var order = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
CheckValidSagaId(order);
order.SetPaidStatus(); orderToUpdate.SetPaidStatus();
}
private void CheckValidSagaId(Order orderSaga)
{
if (orderSaga is null)
{
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
}
} }
} }
} }

View File

@ -19,18 +19,9 @@
public async Task Handle(OrderStockConfirmedIntegrationEvent @event) public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
{ {
var order = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
CheckValidSagaId(order);
order.SetStockConfirmedStatus(); orderToUpdate.SetStockConfirmedStatus();
}
private void CheckValidSagaId(Order orderSaga)
{
if (orderSaga is null)
{
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
}
} }
} }
} }

View File

@ -22,7 +22,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event) public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
CheckValidSagaId(orderToUpdate);
var orderStockNotConfirmedItems = @event.OrderStockItems var orderStockNotConfirmedItems = @event.OrderStockItems
.FindAll(c => !c.Confirmed) .FindAll(c => !c.Confirmed)
@ -30,13 +29,5 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems); orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
} }
private void CheckValidSagaId(Order orderSaga)
{
if (orderSaga is null)
{
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
}
}
} }
} }