Browse Source

Add ConfirmOrderStockIntegrationEvent implementation

pull/223/head
Christian Arenas 7 years ago
parent
commit
629693043b
7 changed files with 70 additions and 23 deletions
  1. +30
    -3
      src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/ConfirmOrderStockIntegrationEventHandler.cs
  2. +3
    -3
      src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ConfirmOrderStockIntegrationEvent.cs
  3. +11
    -14
      src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs
  4. +3
    -0
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs
  5. +3
    -0
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs
  6. +19
    -3
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs
  7. +1
    -0
      src/Services/Ordering/Ordering.API/Ordering.API.csproj

+ 30
- 3
src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/ConfirmOrderStockIntegrationEventHandler.cs View File

@ -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 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) 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); 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");
}
}
} }
} }

+ 3
- 3
src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ConfirmOrderStockIntegrationEvent.cs View File

@ -6,13 +6,13 @@
public class ConfirmOrderStockIntegrationEvent : IntegrationEvent public class ConfirmOrderStockIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public IEnumerable<OrderStockItem> OrderStockItem { get; }
public IEnumerable<OrderStockItem> OrderStockItems { get; }
public ConfirmOrderStockIntegrationEvent(int orderId, public ConfirmOrderStockIntegrationEvent(int orderId,
IEnumerable<OrderStockItem> orderStockItem)
IEnumerable<OrderStockItem> orderStockItems)
{ {
OrderId = orderId; OrderId = orderId;
OrderStockItem = orderStockItem;
OrderStockItems = orderStockItems;
} }
} }


+ 11
- 14
src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs View File

@ -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 BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
{ {
@ -16,19 +15,17 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
OrderId = orderId; OrderId = orderId;
OrderStockItem = orderStockItem; OrderStockItem = orderStockItem;
} }
}
public class ConfirmedOrderStockItem
{
public int ProductId { get; }
public int Units { get; }
public bool Confirmed { get; }
public class ConfirmedOrderStockItem
{
public int ProductId { get; }
public bool Confirmed { get; }
public ConfirmedOrderStockItem(int productId, int units, bool confirmed)
{
ProductId = productId;
Units = units;
Confirmed = confirmed;
}
public ConfirmedOrderStockItem(int productId, bool confirmed)
{
ProductId = productId;
Confirmed = confirmed;
} }
} }
} }

+ 3
- 0
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs View File

@ -9,6 +9,9 @@
{ {
public async Task Handle(OrderStockConfirmedIntegrationEvent @event) 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(); throw new NotImplementedException();
} }
} }

+ 3
- 0
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs View File

@ -9,6 +9,9 @@
{ {
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event) 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(); throw new NotImplementedException();
} }
} }

+ 19
- 3
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs View File

@ -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; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
@ -6,11 +8,25 @@
{ {
public int OrderId { get; } 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; 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;
} }
} }
} }

+ 1
- 0
src/Services/Ordering/Ordering.API/Ordering.API.csproj View File

@ -79,6 +79,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Application\DomainEventHandlers\OrderStockMethodVerified\" />
<Folder Include="Application\IntegrationCommands\CommandHandlers\" /> <Folder Include="Application\IntegrationCommands\CommandHandlers\" />
<Folder Include="Infrastructure\IntegrationEventMigrations\" /> <Folder Include="Infrastructure\IntegrationEventMigrations\" />
</ItemGroup> </ItemGroup>


Loading…
Cancel
Save