Make all catalog product events have same name id. (#10)
* Make all catalog product events have same name id. This should be useful for stream processing in flink, because we can then key a stream with these events on the productId more easily. * Add product bought event, which is published for each product. This makes it easier to check whether a product is being oversold. * Allow for setting the catalog item id through API call. Previously the entity framework API did have a counter in place, ignoring the id that was send in the catalog api request.
This commit is contained in:
parent
2ad9ec2a92
commit
b4b9e6c8d6
@ -264,11 +264,13 @@ public class CatalogController : ControllerBase
|
|||||||
{
|
{
|
||||||
var item = new CatalogItem
|
var item = new CatalogItem
|
||||||
{
|
{
|
||||||
|
Id = product.Id,
|
||||||
CatalogBrandId = product.CatalogBrandId,
|
CatalogBrandId = product.CatalogBrandId,
|
||||||
CatalogTypeId = product.CatalogTypeId,
|
CatalogTypeId = product.CatalogTypeId,
|
||||||
Description = product.Description,
|
Description = product.Description,
|
||||||
Name = product.Name,
|
Name = product.Name,
|
||||||
PictureFileName = product.PictureFileName,
|
PictureFileName = product.PictureFileName,
|
||||||
|
AvailableStock = product.AvailableStock,
|
||||||
Price = product.Price
|
Price = product.Price
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -285,7 +287,7 @@ public class CatalogController : ControllerBase
|
|||||||
CatalogType = item.CatalogType,
|
CatalogType = item.CatalogType,
|
||||||
CatalogTypeId = item.CatalogTypeId,
|
CatalogTypeId = item.CatalogTypeId,
|
||||||
Description = item.Description,
|
Description = item.Description,
|
||||||
Id = item.Id,
|
ProductId = item.Id,
|
||||||
MaxStockThreshold = item.MaxStockThreshold,
|
MaxStockThreshold = item.MaxStockThreshold,
|
||||||
Name = item.Name,
|
Name = item.Name,
|
||||||
OnReorder = item.OnReorder
|
OnReorder = item.OnReorder
|
||||||
|
@ -8,7 +8,6 @@ class CatalogItemEntityTypeConfiguration
|
|||||||
builder.ToTable("Catalog");
|
builder.ToTable("Catalog");
|
||||||
|
|
||||||
builder.Property(ci => ci.Id)
|
builder.Property(ci => ci.Id)
|
||||||
.UseHiLo("catalog_hilo")
|
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
builder.Property(ci => ci.Name)
|
builder.Property(ci => ci.Name)
|
||||||
|
@ -2,7 +2,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
|
|||||||
|
|
||||||
public record ProductCreatedIntegrationEvent : IntegrationEvent
|
public record ProductCreatedIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
@ -39,6 +39,15 @@ public class OrderStatusChangedToPaidDomainEventHandler
|
|||||||
buyer.Name,
|
buyer.Name,
|
||||||
orderStockList);
|
orderStockList);
|
||||||
|
|
||||||
|
foreach (var orderStockItem in orderStockList)
|
||||||
|
{
|
||||||
|
var productBoughtEvent = new ProductBoughtIntegrationEvent(
|
||||||
|
orderStockItem.ProductId,
|
||||||
|
orderStockItem.Units
|
||||||
|
);
|
||||||
|
await _orderingIntegrationEventService.AddAndSaveEventAsync(productBoughtEvent);
|
||||||
|
}
|
||||||
|
|
||||||
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToPaidIntegrationEvent);
|
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToPaidIntegrationEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
|
||||||
|
|
||||||
|
public record ProductBoughtIntegrationEvent : IntegrationEvent
|
||||||
|
{
|
||||||
|
public int ProductId { get; }
|
||||||
|
public int Units { get; }
|
||||||
|
|
||||||
|
public ProductBoughtIntegrationEvent(int productId, int units)
|
||||||
|
{
|
||||||
|
ProductId = productId;
|
||||||
|
Units = units;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user