Add ConfirmOrderStockIntegrationEvent implementation
This commit is contained in:
parent
83dadc878b
commit
629693043b
@ -1,4 +1,8 @@
|
||||
using Catalog.API.IntegrationEvents;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Catalog.API.Infrastructure.Exceptions;
|
||||
using Catalog.API.IntegrationEvents;
|
||||
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
|
||||
{
|
||||
@ -23,11 +27,34 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
|
||||
|
||||
public async Task Handle(ConfirmOrderStockIntegrationEvent @event)
|
||||
{
|
||||
IntegrationEvent integrationEvent = new OrderStockConfirmedIntegrationEvent(@event.OrderId);
|
||||
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();
|
||||
|
||||
//TODO: Check the stock products units
|
||||
foreach (var orderStockItem in @event.OrderStockItems)
|
||||
{
|
||||
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
||||
CheckValidcatalogItemId(catalogItem);
|
||||
|
||||
var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id,
|
||||
catalogItem.AvailableStock >= orderStockItem.Units);
|
||||
|
||||
confirmedOrderStockItems.Add(confirmedOrderStockItem);
|
||||
}
|
||||
|
||||
//Create Integration Event to be published through the Event Bus
|
||||
var integrationEvent = confirmedOrderStockItems.Any(c => !c.Confirmed)
|
||||
? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(@event.OrderId, confirmedOrderStockItems)
|
||||
: new OrderStockConfirmedIntegrationEvent(@event.OrderId);
|
||||
|
||||
// Publish through the Event Bus and mark the saved event as published
|
||||
await _catalogIntegrationEventService.PublishThroughEventBusAsync(integrationEvent);
|
||||
}
|
||||
|
||||
private void CheckValidcatalogItemId(CatalogItem catalogItem)
|
||||
{
|
||||
if (catalogItem is null)
|
||||
{
|
||||
throw new CatalogDomainException("Not able to process catalog event. Reason: no valid catalogItemId");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,13 +6,13 @@
|
||||
public class ConfirmOrderStockIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
public int OrderId { get; }
|
||||
public IEnumerable<OrderStockItem> OrderStockItem { get; }
|
||||
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
||||
|
||||
public ConfirmOrderStockIntegrationEvent(int orderId,
|
||||
IEnumerable<OrderStockItem> orderStockItem)
|
||||
IEnumerable<OrderStockItem> orderStockItems)
|
||||
{
|
||||
OrderId = orderId;
|
||||
OrderStockItem = orderStockItem;
|
||||
OrderStockItems = orderStockItems;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
|
||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
|
||||
{
|
||||
using BuildingBlocks.EventBus.Events;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
@ -16,19 +15,17 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
|
||||
OrderId = orderId;
|
||||
OrderStockItem = orderStockItem;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmedOrderStockItem
|
||||
public class ConfirmedOrderStockItem
|
||||
{
|
||||
public int ProductId { get; }
|
||||
public bool Confirmed { get; }
|
||||
|
||||
public ConfirmedOrderStockItem(int productId, bool confirmed)
|
||||
{
|
||||
public int ProductId { get; }
|
||||
public int Units { get; }
|
||||
public bool Confirmed { get; }
|
||||
|
||||
public ConfirmedOrderStockItem(int productId, int units, bool confirmed)
|
||||
{
|
||||
ProductId = productId;
|
||||
Units = units;
|
||||
Confirmed = confirmed;
|
||||
}
|
||||
ProductId = productId;
|
||||
Confirmed = confirmed;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,9 @@
|
||||
{
|
||||
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
|
||||
{
|
||||
//TODO: 1) Updates the state to "StockValidated" and any meaningful OrderContextDescription message saying that all the items were confirmed with available stock, etc
|
||||
//TODO: 2) Sends a Command-message (PayOrderCommand msg/bus) to the Payment svc. from Ordering micro (thru Command Bus, as a message, NOT http)
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,9 @@
|
||||
{
|
||||
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
|
||||
{
|
||||
//TODO: must update the order state to cancelled and the CurrentOrderStateContextDescription with the reasons of no-stock confirm
|
||||
//TODO: for this/that articles which is info coming in that integration event. --> ORDER PROCESS
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Ordering.API.Application.IntegrationEvents.Events
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ordering.API.Application.IntegrationEvents.Events
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
@ -6,11 +8,25 @@
|
||||
{
|
||||
public int OrderId { get; }
|
||||
|
||||
//public IEnumerable<Item> { get; }
|
||||
public IEnumerable<ConfirmedOrderStockItem> OrderStockItem { get; }
|
||||
|
||||
public OrderStockNotConfirmedIntegrationEvent(int orderId)
|
||||
public OrderStockNotConfirmedIntegrationEvent(int orderId,
|
||||
IEnumerable<ConfirmedOrderStockItem> orderStockItem)
|
||||
{
|
||||
OrderId = orderId;
|
||||
OrderStockItem = orderStockItem;
|
||||
}
|
||||
}
|
||||
|
||||
public class ConfirmedOrderStockItem
|
||||
{
|
||||
public int ProductId { get; }
|
||||
public bool Confirmed { get; }
|
||||
|
||||
public ConfirmedOrderStockItem(int productId, bool confirmed)
|
||||
{
|
||||
ProductId = productId;
|
||||
Confirmed = confirmed;
|
||||
}
|
||||
}
|
||||
}
|
@ -79,6 +79,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Application\DomainEventHandlers\OrderStockMethodVerified\" />
|
||||
<Folder Include="Application\IntegrationCommands\CommandHandlers\" />
|
||||
<Folder Include="Infrastructure\IntegrationEventMigrations\" />
|
||||
</ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user