Merge branch 'order-processflow-redesign' of https://github.com/dotnet-architecture/eShopOnContainers into order-processflow-redesign

This commit is contained in:
Ramón Tomás 2017-05-16 15:33:02 +02:00
commit 5276d9d354
12 changed files with 73 additions and 57 deletions

View File

@ -23,20 +23,11 @@
foreach (var orderStockItem in @event.OrderStockItems)
{
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
CheckValidcatalogItemId(catalogItem);
catalogItem.RemoveStock(orderStockItem.Units);
}
await _catalogContext.SaveChangesAsync();
}
private void CheckValidcatalogItemId(CatalogItem catalogItem)
{
if (catalogItem is null)
{
throw new CatalogDomainException("Not able to process catalog event. Reason: no valid catalogItemId");
}
}
}
}

View File

@ -17,7 +17,9 @@
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
{
//TODO: Cancel Order
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
orderToUpdate.SetCancelledStatus();
}
}
}

View File

@ -3,7 +3,6 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Ordering.API.Application.IntegrationEvents.Events;
using Ordering.Domain.Exceptions;
using System.Threading.Tasks;
public class OrderPaymentSuccededIntegrationEventHandler :
@ -18,18 +17,9 @@
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
{
var order = await _orderRepository.GetAsync(@event.OrderId);
CheckValidSagaId(order);
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
order.SetPaidStatus();
}
private void CheckValidSagaId(Order orderSaga)
{
if (orderSaga is null)
{
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
}
orderToUpdate.SetPaidStatus();
}
}
}

View File

@ -4,8 +4,6 @@
using System.Threading.Tasks;
using Events;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Ordering.API.Application.IntegrationCommands.Commands;
using Ordering.Domain.Exceptions;
public class OrderStockConfirmedIntegrationEventHandler :
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
@ -19,18 +17,9 @@
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
{
var order = await _orderRepository.GetAsync(@event.OrderId);
CheckValidSagaId(order);
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
order.SetStockConfirmedStatus();
}
private void CheckValidSagaId(Order orderSaga)
{
if (orderSaga is null)
{
throw new OrderingDomainException("Not able to process order saga event. Reason: no valid orderId");
}
orderToUpdate.SetStockConfirmedStatus();
}
}
}

View File

@ -4,11 +4,9 @@ using Ordering.API.Application.IntegrationCommands.Commands;
namespace Ordering.API.Application.IntegrationEvents.EventHandling
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using System;
using System.Threading.Tasks;
using Events;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Domain.Exceptions;
public class OrderStockNotConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>
{
@ -22,7 +20,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
{
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
CheckValidSagaId(orderToUpdate);
var orderStockNotConfirmedItems = @event.OrderStockItems
.FindAll(c => !c.Confirmed)
@ -30,13 +27,5 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
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");
}
}
}
}

View File

@ -73,7 +73,7 @@ namespace Ordering.API.Application.Sagas
if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id
|| orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id)
{
orderSaga.SetCancelStatus();
orderSaga.SetCancelledStatus();
result = await SaveChangesAsync();
}
return result;

View File

@ -166,14 +166,31 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
//Call Domain Event
}
public void SetCancelStatus()
public void SetCancelledStatus()
{
if (_orderStatusId == OrderStatus.Shipped.Id)
if (_orderStatusId == OrderStatus.Submited.Id)
{
throw new OrderingDomainException("Not possible to change order status. Reason: cannot cancel order it is already shipped");
_description = "The order was cancelled before the grace period was confirm.";
}
else if (_orderStatusId == OrderStatus.AwaitingValidation.Id)
{
_description = "The order was cancelled before to check the order stock items.";
}
else if (_orderStatusId == OrderStatus.StockConfirmed.Id)
{
_description = "The order was cancelled before to pay the order.";
}
else if (_orderStatusId == OrderStatus.Paid.Id)
{
_description = "The order was cancelled before to ship the order.";
}
else if(_orderStatusId == OrderStatus.Shipped.Id)
{
throw new OrderingDomainException("Not possible to change order status. Reason: cannot cancel order it is already shipped.");
}
_orderStatusId = OrderStatus.Cancelled.Id;
}
}
#endregion

View File

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
using Ordering.Domain.Exceptions;
using System;
using System.Threading.Tasks;

View File

@ -4,16 +4,25 @@
using Payment.API.IntegrationCommands.Commands;
using System.Threading.Tasks;
using System;
using Payment.API.IntegrationEvents;
using Payment.API.IntegrationEvents.Events;
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
{
public PayOrderCommandMsgHandler()
{
}
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService;
public PayOrderCommandMsgHandler(IPaymentIntegrationEventService paymentIntegrationEventService)
=> _paymentIntegrationEventService = paymentIntegrationEventService;
public async Task Handle(PayOrderCommandMsg @event)
{
throw new NotImplementedException();
//PAYMENT SUCCESSED
var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentSuccededIntegrationEvent);
//PAYMENT FAILED
//var orderPaymentFailedIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
//_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent);
}
}
}

View File

@ -0,0 +1,9 @@
namespace Payment.API.IntegrationEvents
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public interface IPaymentIntegrationEventService
{
void PublishThroughEventBus(IntegrationEvent evt);
}
}

View File

@ -0,0 +1,21 @@
namespace Payment.API.IntegrationEvents
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System;
public class PaymentIntegrationEventService : IPaymentIntegrationEventService
{
private readonly IEventBus _eventBus;
public PaymentIntegrationEventService(IEventBus eventBus)
{
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
}
public void PublishThroughEventBus(IntegrationEvent evt)
{
_eventBus.Publish(evt); ;
}
}
}

View File

@ -67,8 +67,6 @@ namespace Payment.API
return new AutofacServiceProvider(container.Build());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{