Merge branch 'order-processflow-redesign' of https://github.com/dotnet-architecture/eShopOnContainers into order-processflow-redesign
This commit is contained in:
commit
5276d9d354
@ -23,20 +23,11 @@
|
|||||||
foreach (var orderStockItem in @event.OrderStockItems)
|
foreach (var orderStockItem in @event.OrderStockItems)
|
||||||
{
|
{
|
||||||
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
||||||
CheckValidcatalogItemId(catalogItem);
|
|
||||||
|
|
||||||
catalogItem.RemoveStock(orderStockItem.Units);
|
catalogItem.RemoveStock(orderStockItem.Units);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _catalogContext.SaveChangesAsync();
|
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
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 OrderPaymentSuccededIntegrationEventHandler :
|
public class OrderPaymentSuccededIntegrationEventHandler :
|
||||||
@ -18,18 +17,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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,8 +4,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Events;
|
using Events;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
using Ordering.API.Application.IntegrationCommands.Commands;
|
|
||||||
using Ordering.Domain.Exceptions;
|
|
||||||
|
|
||||||
public class OrderStockConfirmedIntegrationEventHandler :
|
public class OrderStockConfirmedIntegrationEventHandler :
|
||||||
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
|
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
|
||||||
@ -19,18 +17,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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,11 +4,9 @@ using Ordering.API.Application.IntegrationCommands.Commands;
|
|||||||
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||||
{
|
{
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Events;
|
using Events;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
using Domain.Exceptions;
|
|
||||||
|
|
||||||
public class OrderStockNotConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>
|
public class OrderStockNotConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>
|
||||||
{
|
{
|
||||||
@ -22,7 +20,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 +27,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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,7 +73,7 @@ namespace Ordering.API.Application.Sagas
|
|||||||
if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id
|
if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id
|
||||||
|| orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id)
|
|| orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id)
|
||||||
{
|
{
|
||||||
orderSaga.SetCancelStatus();
|
orderSaga.SetCancelledStatus();
|
||||||
result = await SaveChangesAsync();
|
result = await SaveChangesAsync();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -166,14 +166,31 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
//Call Domain Event
|
//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;
|
_orderStatusId = OrderStatus.Cancelled.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
||||||
|
using Ordering.Domain.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -4,16 +4,25 @@
|
|||||||
using Payment.API.IntegrationCommands.Commands;
|
using Payment.API.IntegrationCommands.Commands;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
using System;
|
||||||
|
using Payment.API.IntegrationEvents;
|
||||||
|
using Payment.API.IntegrationEvents.Events;
|
||||||
|
|
||||||
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
|
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
|
||||||
{
|
{
|
||||||
public PayOrderCommandMsgHandler()
|
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService;
|
||||||
{
|
|
||||||
}
|
public PayOrderCommandMsgHandler(IPaymentIntegrationEventService paymentIntegrationEventService)
|
||||||
|
=> _paymentIntegrationEventService = paymentIntegrationEventService;
|
||||||
|
|
||||||
public async Task Handle(PayOrderCommandMsg @event)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace Payment.API.IntegrationEvents
|
||||||
|
{
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
|
public interface IPaymentIntegrationEventService
|
||||||
|
{
|
||||||
|
void PublishThroughEventBus(IntegrationEvent evt);
|
||||||
|
}
|
||||||
|
}
|
@ -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); ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -67,8 +67,6 @@ namespace Payment.API
|
|||||||
return new AutofacServiceProvider(container.Build());
|
return new AutofacServiceProvider(container.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// 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)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user