Add Confirm Grade period Handler and add new items to Orders status
This commit is contained in:
parent
d7bf2c9d7b
commit
870ae0dabd
@ -0,0 +1,30 @@
|
|||||||
|
namespace Ordering.API.Application.IntegrationCommands.Commands
|
||||||
|
{
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
|
public class ConfirmOrderStockCommandMsg : IntegrationEvent
|
||||||
|
{
|
||||||
|
public int OrderId { get; }
|
||||||
|
public IEnumerable<OrderStockItem> OrderStockItem { get; }
|
||||||
|
|
||||||
|
public ConfirmOrderStockCommandMsg(int orderId,
|
||||||
|
IEnumerable<OrderStockItem> orderStockItem)
|
||||||
|
{
|
||||||
|
OrderId = orderId;
|
||||||
|
OrderStockItem = orderStockItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OrderStockItem
|
||||||
|
{
|
||||||
|
public int ProductId { get; }
|
||||||
|
public int Units { get; }
|
||||||
|
|
||||||
|
public OrderStockItem(int productId, int units)
|
||||||
|
{
|
||||||
|
ProductId = productId;
|
||||||
|
Units = units;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||||
|
{
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Events;
|
||||||
|
|
||||||
|
public class OrderStockConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
|
||||||
|
{
|
||||||
|
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||||
|
{
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Events;
|
||||||
|
|
||||||
|
public class OrderStockNotConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>
|
||||||
|
{
|
||||||
|
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
namespace Ordering.API.Application.IntegrationEvents.Events
|
||||||
|
{
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
|
public class OrderStockConfirmedIntegrationEvent : IntegrationEvent
|
||||||
|
{
|
||||||
|
public int OrderId { get; }
|
||||||
|
|
||||||
|
public OrderStockConfirmedIntegrationEvent(int orderId) => OrderId = orderId;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
namespace Ordering.API.Application.IntegrationEvents.Events
|
||||||
|
{
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
|
public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
|
||||||
|
{
|
||||||
|
public int OrderId { get; }
|
||||||
|
|
||||||
|
//public IEnumerable<Item> { get; }
|
||||||
|
|
||||||
|
public OrderStockNotConfirmedIntegrationEvent(int orderId)
|
||||||
|
{
|
||||||
|
OrderId = orderId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,11 @@ using Ordering.API.Application.Commands;
|
|||||||
using Ordering.API.Application.IntegrationCommands.Commands;
|
using Ordering.API.Application.IntegrationCommands.Commands;
|
||||||
using Ordering.Domain.Exceptions;
|
using Ordering.Domain.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Ordering.API.Application.IntegrationEvents;
|
||||||
using Ordering.API.Application.IntegrationEvents.Events;
|
using Ordering.API.Application.IntegrationEvents.Events;
|
||||||
|
|
||||||
namespace Ordering.API.Application.Sagas
|
namespace Ordering.API.Application.Sagas
|
||||||
@ -29,14 +33,16 @@ namespace Ordering.API.Application.Sagas
|
|||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly Func<Owned<OrderingContext>> _dbContextFactory;
|
private readonly Func<Owned<OrderingContext>> _dbContextFactory;
|
||||||
|
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
|
||||||
|
|
||||||
public OrderProcessSaga(
|
public OrderProcessSaga(
|
||||||
Func<Owned<OrderingContext>> dbContextFactory, OrderingContext orderingContext,
|
Func<Owned<OrderingContext>> dbContextFactory, OrderingContext orderingContext,
|
||||||
IMediator mediator)
|
IMediator mediator, IOrderingIntegrationEventService orderingIntegrationEventService)
|
||||||
: base(orderingContext)
|
: base(orderingContext)
|
||||||
{
|
{
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
|
_orderingIntegrationEventService = orderingIntegrationEventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -77,13 +83,21 @@ namespace Ordering.API.Application.Sagas
|
|||||||
var orderSaga = FindSagaById(command.OrderId);
|
var orderSaga = FindSagaById(command.OrderId);
|
||||||
CheckValidSagaId(orderSaga);
|
CheckValidSagaId(orderSaga);
|
||||||
|
|
||||||
// TODO: This handler should change to Integration command handler type once command bus is implemented
|
if (orderSaga.OrderStatus != OrderStatus.Cancelled)
|
||||||
|
{
|
||||||
|
orderSaga.SetOrderStatusId(OrderStatus.AwaitingValidation.Id);
|
||||||
|
await SaveChangesAsync();
|
||||||
|
|
||||||
// TODO: If order status is not cancelled, change state to awaitingValidation and
|
var orderStockList = orderSaga.OrderItems
|
||||||
// send ConfirmOrderStockCommandMsg to Inventory api
|
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
|
||||||
|
|
||||||
|
//Create Integration Event to be published through the Event Bus
|
||||||
|
var confirmOrderStockEvent = new ConfirmOrderStockCommandMsg(orderSaga.Id, orderStockList);
|
||||||
|
|
||||||
|
// Publish through the Event Bus and mark the saved event as published
|
||||||
|
await _orderingIntegrationEventService.PublishThroughEventBusAsync(confirmOrderStockEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler which processes the command when
|
/// Handler which processes the command when
|
||||||
|
@ -31,9 +31,12 @@
|
|||||||
|
|
||||||
if (!context.OrderStatus.Any())
|
if (!context.OrderStatus.Any())
|
||||||
{
|
{
|
||||||
context.OrderStatus.Add(OrderStatus.Canceled);
|
context.OrderStatus.Add(OrderStatus.Submited);
|
||||||
context.OrderStatus.Add(OrderStatus.InProcess);
|
context.OrderStatus.Add(OrderStatus.AwaitingValidation);
|
||||||
|
context.OrderStatus.Add(OrderStatus.StockValidated);
|
||||||
|
context.OrderStatus.Add(OrderStatus.Paid);
|
||||||
context.OrderStatus.Add(OrderStatus.Shipped);
|
context.OrderStatus.Add(OrderStatus.Shipped);
|
||||||
|
context.OrderStatus.Add(OrderStatus.Cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
||||||
|
|
||||||
using Ordering.API.Application.IntegrationCommands.Commands;
|
|
||||||
using Ordering.API.Application.IntegrationEvents.EventHandling;
|
|
||||||
using Ordering.API.Application.Sagas;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
|
||||||
{
|
{
|
||||||
using AspNetCore.Http;
|
using AspNetCore.Http;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
@ -12,6 +6,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
|||||||
using global::Ordering.API.Application.IntegrationEvents;
|
using global::Ordering.API.Application.IntegrationEvents;
|
||||||
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
|
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
|
||||||
using global::Ordering.API.Infrastructure.Middlewares;
|
using global::Ordering.API.Infrastructure.Middlewares;
|
||||||
|
using global::Ordering.API.Application.IntegrationCommands.Commands;
|
||||||
|
using global::Ordering.API.Application.IntegrationEvents.Events;
|
||||||
|
using global::Ordering.API.Application.Sagas;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Auth;
|
using Infrastructure.Auth;
|
||||||
using Infrastructure.AutofacModules;
|
using Infrastructure.AutofacModules;
|
||||||
@ -131,6 +128,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
|||||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||||
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
||||||
services.AddTransient<UserCheckoutAcceptedIntegrationEventHandler>();
|
services.AddTransient<UserCheckoutAcceptedIntegrationEventHandler>();
|
||||||
|
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
|
||||||
|
services.AddTransient<IIntegrationEventHandler<SubmitOrderCommandMsg>, OrderProcessSaga>();
|
||||||
|
services.AddTransient<OrderStockConfirmedIntegrationEventHandler>();
|
||||||
|
services.AddTransient<OrderStockNotConfirmedIntegrationEventHandler>();
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
|
|
||||||
//configure autofac
|
//configure autofac
|
||||||
@ -179,11 +180,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
|||||||
"UserCheckoutAccepted",
|
"UserCheckoutAccepted",
|
||||||
() => app.ApplicationServices.GetRequiredService<UserCheckoutAcceptedIntegrationEventHandler>());
|
() => app.ApplicationServices.GetRequiredService<UserCheckoutAcceptedIntegrationEventHandler>());
|
||||||
|
|
||||||
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>(
|
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>
|
||||||
() => app.ApplicationServices
|
(() => app.ApplicationServices.GetRequiredService<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>());
|
||||||
.GetService<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>()
|
|
||||||
);
|
|
||||||
|
|
||||||
|
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, OrderStockConfirmedIntegrationEventHandler>
|
||||||
|
(() => app.ApplicationServices.GetRequiredService<OrderStockConfirmedIntegrationEventHandler>());
|
||||||
|
|
||||||
|
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, OrderStockNotConfirmedIntegrationEventHandler>
|
||||||
|
(() => app.ApplicationServices.GetRequiredService<OrderStockNotConfirmedIntegrationEventHandler>());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
||||||
|
@ -46,7 +46,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
_orderItems = new List<OrderItem>();
|
_orderItems = new List<OrderItem>();
|
||||||
_buyerId = buyerId;
|
_buyerId = buyerId;
|
||||||
_paymentMethodId = paymentMethodId;
|
_paymentMethodId = paymentMethodId;
|
||||||
_orderStatusId = OrderStatus.InProcess.Id;
|
_orderStatusId = OrderStatus.Submited.Id;
|
||||||
_orderDate = DateTime.UtcNow;
|
_orderDate = DateTime.UtcNow;
|
||||||
Address = address;
|
Address = address;
|
||||||
|
|
||||||
@ -94,6 +94,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
_buyerId = id;
|
_buyerId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetOrderStatusId(int id)
|
||||||
|
{
|
||||||
|
_orderStatusId = id;
|
||||||
|
}
|
||||||
|
|
||||||
private void AddOrderStartedDomainEvent(int cardTypeId, string cardNumber,
|
private void AddOrderStartedDomainEvent(int cardTypeId, string cardNumber,
|
||||||
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
|
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
|
||||||
{
|
{
|
||||||
|
@ -54,6 +54,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
return _discount;
|
return _discount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetUnits()
|
||||||
|
{
|
||||||
|
return _units;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetNewDiscount(decimal discount)
|
public void SetNewDiscount(decimal discount)
|
||||||
{
|
{
|
||||||
if (discount < 0)
|
if (discount < 0)
|
||||||
|
@ -10,9 +10,12 @@
|
|||||||
public class OrderStatus
|
public class OrderStatus
|
||||||
: Enumeration
|
: Enumeration
|
||||||
{
|
{
|
||||||
public static OrderStatus InProcess = new OrderStatus(1, nameof(InProcess).ToLowerInvariant());
|
public static OrderStatus Submited = new OrderStatus(1, nameof(Submited).ToLowerInvariant());
|
||||||
public static OrderStatus Shipped = new OrderStatus(2, nameof(Shipped).ToLowerInvariant());
|
public static OrderStatus AwaitingValidation = new OrderStatus(2, nameof(AwaitingValidation).ToLowerInvariant());
|
||||||
public static OrderStatus Canceled = new OrderStatus(3, nameof(Canceled).ToLowerInvariant());
|
public static OrderStatus StockValidated = new OrderStatus(3, nameof(StockValidated).ToLowerInvariant());
|
||||||
|
public static OrderStatus Paid = new OrderStatus(4, nameof(Paid).ToLowerInvariant());
|
||||||
|
public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant());
|
||||||
|
public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant());
|
||||||
|
|
||||||
protected OrderStatus()
|
protected OrderStatus()
|
||||||
{
|
{
|
||||||
@ -23,10 +26,8 @@
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<OrderStatus> List()
|
public static IEnumerable<OrderStatus> List() =>
|
||||||
{
|
new[] { Submited, AwaitingValidation, StockValidated, Paid, Shipped, Cancelled };
|
||||||
return new[] { InProcess, Shipped, Canceled };
|
|
||||||
}
|
|
||||||
|
|
||||||
public static OrderStatus FromName(string name)
|
public static OrderStatus FromName(string name)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user