diff --git a/src/Services/Catalog/Catalog.API/Catalog.API.csproj b/src/Services/Catalog/Catalog.API/Catalog.API.csproj
index 3c2686278..2f0a0d20a 100644
--- a/src/Services/Catalog/Catalog.API/Catalog.API.csproj
+++ b/src/Services/Catalog/Catalog.API/Catalog.API.csproj
@@ -74,4 +74,9 @@
+
+
+
+
+
diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs
similarity index 62%
rename from src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs
rename to src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs
index 7edfd5cf7..0f30a3e0a 100644
--- a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs
+++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs
@@ -1,4 +1,4 @@
-namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers
+namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
{
using BuildingBlocks.EventBus.Abstractions;
using System.Threading.Tasks;
@@ -6,53 +6,41 @@
using Infrastructure;
using System.Collections.Generic;
using System.Linq;
- using global::Catalog.API.Infrastructure.Exceptions;
using global::Catalog.API.IntegrationEvents;
- using Model;
- using Commands;
using IntegrationEvents.Events;
- public class ConfirmOrderStockCommandHandler : IIntegrationEventHandler
+ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
+ IIntegrationEventHandler
{
private readonly CatalogContext _catalogContext;
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
- public ConfirmOrderStockCommandHandler(CatalogContext catalogContext,
+ public OrderStatusChangedToAwaitingValidationIntegrationEventHandler(CatalogContext catalogContext,
ICatalogIntegrationEventService catalogIntegrationEventService)
{
_catalogContext = catalogContext;
_catalogIntegrationEventService = catalogIntegrationEventService;
}
- public async Task Handle(ConfirmOrderStockCommand command)
+ public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent command)
{
var confirmedOrderStockItems = new List();
foreach (var orderStockItem in command.OrderStockItems)
{
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
- CheckValidcatalogItemId(catalogItem);
-
- var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id,
- catalogItem.AvailableStock >= orderStockItem.Units);
+ var hasStock = catalogItem.AvailableStock >= orderStockItem.Units;
+ var confirmedOrderStockItem = new ConfirmedOrderStockItem(catalogItem.Id, hasStock);
confirmedOrderStockItems.Add(confirmedOrderStockItem);
}
var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.HasStock)
- ? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(command.OrderId, confirmedOrderStockItems)
+ ? (IntegrationEvent) new OrderStockRejectedIntegrationEvent(command.OrderId, confirmedOrderStockItems)
: new OrderStockConfirmedIntegrationEvent(command.OrderId);
await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent);
await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent);
}
-
- private void CheckValidcatalogItemId(CatalogItem catalogItem)
- {
- if (catalogItem is null)
- {
- throw new CatalogDomainException("Not able to process catalog event. Reason: no valid catalogItemId");
- }
- }
}
}
\ No newline at end of file
diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs
similarity index 61%
rename from src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs
rename to src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs
index 1c7d1b9a3..0a45547f9 100644
--- a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs
+++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs
@@ -1,20 +1,21 @@
-namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers
+namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
{
using BuildingBlocks.EventBus.Abstractions;
using System.Threading.Tasks;
using Infrastructure;
- using Commands;
+ using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
- public class DecrementOrderStockCommandHandler : IIntegrationEventHandler
+ public class OrderStatusChangedToPaidIntegrationEventHandler :
+ IIntegrationEventHandler
{
private readonly CatalogContext _catalogContext;
- public DecrementOrderStockCommandHandler(CatalogContext catalogContext)
+ public OrderStatusChangedToPaidIntegrationEventHandler(CatalogContext catalogContext)
{
_catalogContext = catalogContext;
}
- public async Task Handle(DecrementOrderStockCommand command)
+ public async Task Handle(OrderStatusChangedToPaidIntegrationEvent command)
{
//we're not blocking stock/inventory
foreach (var orderStockItem in command.OrderStockItems)
diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs
similarity index 77%
rename from src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs
rename to src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs
index 2c5296776..9787aaedd 100644
--- a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs
+++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToAwaitingValidationIntegrationEvent.cs
@@ -1,14 +1,14 @@
-namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands
+namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
{
using BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
- public class ConfirmOrderStockCommand : IntegrationEvent
+ public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public IEnumerable OrderStockItems { get; }
- public ConfirmOrderStockCommand(int orderId,
+ public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId,
IEnumerable orderStockItems)
{
OrderId = orderId;
diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs
similarity index 72%
rename from src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs
rename to src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs
index ca241d6fd..881aa21fe 100644
--- a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs
+++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStatusChangedToPaidIntegrationEvent.cs
@@ -1,14 +1,14 @@
-namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands
+namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
{
using System.Collections.Generic;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
- public class DecrementOrderStockCommand : IntegrationEvent
+ public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public IEnumerable OrderStockItems { get; }
- public DecrementOrderStockCommand(int orderId,
+ public OrderStatusChangedToPaidIntegrationEvent(int orderId,
IEnumerable orderStockItems)
{
OrderId = orderId;
diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockRejectedIntegrationEvent.cs
similarity index 83%
rename from src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs
rename to src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockRejectedIntegrationEvent.cs
index b32b0dff5..eb74af8dd 100644
--- a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs
+++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockRejectedIntegrationEvent.cs
@@ -3,13 +3,13 @@
using BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
- public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
+ public class OrderStockRejectedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
public List OrderStockItems { get; }
- public OrderStockNotConfirmedIntegrationEvent(int orderId,
+ public OrderStockRejectedIntegrationEvent(int orderId,
List orderStockItems)
{
OrderId = orderId;
diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs
index 1f65e6a91..15a385867 100644
--- a/src/Services/Catalog/Catalog.API/Startup.cs
+++ b/src/Services/Catalog/Catalog.API/Startup.cs
@@ -14,9 +14,8 @@
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
- using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands;
- using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents;
- using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers;
+ using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling;
+ using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.HealthChecks;
@@ -27,7 +26,7 @@
using System.Data.Common;
using System.Data.SqlClient;
using System.Reflection;
-
+
public class Startup
{
public IConfigurationRoot Configuration { get; }
@@ -190,19 +189,20 @@
services.AddSingleton();
services.AddSingleton();
- services.AddTransient,
- ConfirmOrderStockCommandHandler>();
- services.AddTransient,
- DecrementOrderStockCommandHandler>();
-
+ services.AddTransient,
+ OrderStatusChangedToAwaitingValidationIntegrationEventHandler>();
+ services.AddTransient,
+ OrderStatusChangedToPaidIntegrationEventHandler>();
}
private void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService();
- eventBus.Subscribe>();
- eventBus.Subscribe>();
+ eventBus.Subscribe>();
+ eventBus.Subscribe>();
}
}
}