Skip to content

Commit fbfe287

Browse files
committed
Add ConfirmOrderStockIntegrationEventHandler and OrderStockConfirmedIntegrationEvent/OrderStockNotConfirmedIntegrationEvent
1 parent 870ae0d commit fbfe287

5 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Catalog.API.IntegrationEvents;
2+
3+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling
4+
{
5+
using BuildingBlocks.EventBus.Abstractions;
6+
using System.Threading.Tasks;
7+
using BuildingBlocks.EventBus.Events;
8+
using Infrastructure;
9+
10+
using Events;
11+
12+
public class ConfirmOrderStockIntegrationEventHandler : IIntegrationEventHandler<ConfirmOrderStockIntegrationEvent>
13+
{
14+
private readonly CatalogContext _catalogContext;
15+
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
16+
17+
public ConfirmOrderStockIntegrationEventHandler(CatalogContext catalogContext,
18+
ICatalogIntegrationEventService catalogIntegrationEventService)
19+
{
20+
_catalogContext = catalogContext;
21+
_catalogIntegrationEventService = catalogIntegrationEventService;
22+
}
23+
24+
public async Task Handle(ConfirmOrderStockIntegrationEvent @event)
25+
{
26+
IntegrationEvent integrationEvent = new OrderStockConfirmedIntegrationEvent(@event.OrderId);
27+
28+
//TODO: Check the stock products units
29+
30+
await _catalogIntegrationEventService.PublishThroughEventBusAsync(integrationEvent);
31+
}
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
2+
{
3+
using BuildingBlocks.EventBus.Events;
4+
using System.Collections.Generic;
5+
6+
public class ConfirmOrderStockIntegrationEvent : IntegrationEvent
7+
{
8+
public int OrderId { get; }
9+
public IEnumerable<OrderStockItem> OrderStockItem { get; }
10+
11+
public ConfirmOrderStockIntegrationEvent(int orderId,
12+
IEnumerable<OrderStockItem> orderStockItem)
13+
{
14+
OrderId = orderId;
15+
OrderStockItem = orderStockItem;
16+
}
17+
}
18+
19+
public class OrderStockItem
20+
{
21+
public int ProductId { get; }
22+
public int Units { get; }
23+
24+
public OrderStockItem(int productId, int units)
25+
{
26+
ProductId = productId;
27+
Units = units;
28+
}
29+
}
30+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
5+
public class OrderStockConfirmedIntegrationEvent : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public OrderStockConfirmedIntegrationEvent(int orderId) => OrderId = orderId;
10+
}
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
3+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events
4+
{
5+
using BuildingBlocks.EventBus.Events;
6+
7+
public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
8+
{
9+
public int OrderId { get; }
10+
11+
public IEnumerable<ConfirmedOrderStockItem> OrderStockItem { get; }
12+
13+
public OrderStockNotConfirmedIntegrationEvent(int orderId,
14+
IEnumerable<ConfirmedOrderStockItem> orderStockItem)
15+
{
16+
OrderId = orderId;
17+
OrderStockItem = orderStockItem;
18+
}
19+
20+
public class ConfirmedOrderStockItem
21+
{
22+
public int ProductId { get; }
23+
public int Units { get; }
24+
public bool Confirmed { get; }
25+
26+
public ConfirmedOrderStockItem(int productId, int units, bool confirmed)
27+
{
28+
ProductId = productId;
29+
Units = units;
30+
Confirmed = confirmed;
31+
}
32+
}
33+
}
34+
}

src/Services/Catalog/Catalog.API/Model/CatalogItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class CatalogItem
1414

1515
public string PictureUri { get; set; }
1616

17+
public int Stock { get; set; }
18+
1719
public int CatalogTypeId { get; set; }
1820

1921
public CatalogType CatalogType { get; set; }

0 commit comments

Comments
 (0)