Browse Source

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.
pull/2110/head
Philipp Theyssen 1 year ago
committed by GitHub
parent
commit
b4b9e6c8d6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 3 deletions
  1. +3
    -1
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  2. +0
    -1
      src/Services/Catalog/Catalog.API/Infrastructure/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs
  3. +1
    -1
      src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductCreatedIntegrationEvent.cs
  4. +9
    -0
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs
  5. +13
    -0
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/ProductBoughtIntegrationEvent.cs

+ 3
- 1
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -264,11 +264,13 @@ public class CatalogController : ControllerBase
{
var item = new CatalogItem
{
Id = product.Id,
CatalogBrandId = product.CatalogBrandId,
CatalogTypeId = product.CatalogTypeId,
Description = product.Description,
Name = product.Name,
PictureFileName = product.PictureFileName,
AvailableStock = product.AvailableStock,
Price = product.Price
};
@ -285,7 +287,7 @@ public class CatalogController : ControllerBase
CatalogType = item.CatalogType,
CatalogTypeId = item.CatalogTypeId,
Description = item.Description,
Id = item.Id,
ProductId = item.Id,
MaxStockThreshold = item.MaxStockThreshold,
Name = item.Name,
OnReorder = item.OnReorder


+ 0
- 1
src/Services/Catalog/Catalog.API/Infrastructure/EntityConfigurations/CatalogItemEntityTypeConfiguration.cs View File

@ -8,7 +8,6 @@ class CatalogItemEntityTypeConfiguration
builder.ToTable("Catalog");
builder.Property(ci => ci.Id)
.UseHiLo("catalog_hilo")
.IsRequired();
builder.Property(ci => ci.Name)


+ 1
- 1
src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductCreatedIntegrationEvent.cs View File

@ -2,7 +2,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
public record ProductCreatedIntegrationEvent : IntegrationEvent
{
public int Id { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }


+ 9
- 0
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs View File

@ -39,6 +39,15 @@ public class OrderStatusChangedToPaidDomainEventHandler
buyer.Name,
orderStockList);
foreach (var orderStockItem in orderStockList)
{
var productBoughtEvent = new ProductBoughtIntegrationEvent(
orderStockItem.ProductId,
orderStockItem.Units
);
await _orderingIntegrationEventService.AddAndSaveEventAsync(productBoughtEvent);
}
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToPaidIntegrationEvent);
}
}

+ 13
- 0
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/ProductBoughtIntegrationEvent.cs View File

@ -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…
Cancel
Save