diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/ConfirmOrderStockIntegrationEventHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/ConfirmOrderStockIntegrationEventHandler.cs new file mode 100644 index 000000000..4bbec576d --- /dev/null +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/ConfirmOrderStockIntegrationEventHandler.cs @@ -0,0 +1,33 @@ +using Catalog.API.IntegrationEvents; + +namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling +{ + using BuildingBlocks.EventBus.Abstractions; + using System.Threading.Tasks; + using BuildingBlocks.EventBus.Events; + using Infrastructure; + + using Events; + + public class ConfirmOrderStockIntegrationEventHandler : IIntegrationEventHandler + { + private readonly CatalogContext _catalogContext; + private readonly ICatalogIntegrationEventService _catalogIntegrationEventService; + + public ConfirmOrderStockIntegrationEventHandler(CatalogContext catalogContext, + ICatalogIntegrationEventService catalogIntegrationEventService) + { + _catalogContext = catalogContext; + _catalogIntegrationEventService = catalogIntegrationEventService; + } + + public async Task Handle(ConfirmOrderStockIntegrationEvent @event) + { + IntegrationEvent integrationEvent = new OrderStockConfirmedIntegrationEvent(@event.OrderId); + + //TODO: Check the stock products units + + await _catalogIntegrationEventService.PublishThroughEventBusAsync(integrationEvent); + } + } +} \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ConfirmOrderStockIntegrationEvent.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ConfirmOrderStockIntegrationEvent.cs new file mode 100644 index 000000000..d8dc37163 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ConfirmOrderStockIntegrationEvent.cs @@ -0,0 +1,30 @@ +namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events +{ + using BuildingBlocks.EventBus.Events; + using System.Collections.Generic; + + public class ConfirmOrderStockIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + public IEnumerable OrderStockItem { get; } + + public ConfirmOrderStockIntegrationEvent(int orderId, + IEnumerable 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; + } + } +} \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockConfirmedIntegrationEvent.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockConfirmedIntegrationEvent.cs new file mode 100644 index 000000000..1ce179c3a --- /dev/null +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockConfirmedIntegrationEvent.cs @@ -0,0 +1,11 @@ +namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events +{ + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; + + public class OrderStockConfirmedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + + public OrderStockConfirmedIntegrationEvent(int orderId) => OrderId = orderId; + } +} \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs new file mode 100644 index 000000000..9af458022 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; + +namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events +{ + using BuildingBlocks.EventBus.Events; + + public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent + { + public int OrderId { get; } + + public IEnumerable OrderStockItem { get; } + + public OrderStockNotConfirmedIntegrationEvent(int orderId, + IEnumerable orderStockItem) + { + OrderId = orderId; + OrderStockItem = orderStockItem; + } + + public class ConfirmedOrderStockItem + { + 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; + } + } + } +} \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs b/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs index a232cb2fe..47cfa7c73 100644 --- a/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs +++ b/src/Services/Catalog/Catalog.API/Model/CatalogItem.cs @@ -14,6 +14,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model public string PictureUri { get; set; } + public int Stock { get; set; } + public int CatalogTypeId { get; set; } public CatalogType CatalogType { get; set; }