Skip to content

Commit c7e88d4

Browse files
committed
Merge
2 parents d9d26be + 9b44946 commit c7e88d4

39 files changed

Lines changed: 202 additions & 223 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ services:
9090
build:
9191
context: ./src/Services/Payment/Payment.API
9292
dockerfile: Dockerfile
93+
depends_on:
94+
- rabbitmq

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,6 @@ protected virtual void ConfigureAuth(IApplicationBuilder app)
165165

166166
protected virtual void ConfigureEventBus(IApplicationBuilder app)
167167
{
168-
//var catalogPriceHandler = app.ApplicationServices
169-
// .GetService<IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>>();
170-
171-
//var orderStartedHandler = app.ApplicationServices
172-
// .GetService<IIntegrationEventHandler<OrderStartedIntegrationEvent>>();
173-
174168
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
175169
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
176170
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();

src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ static IEnumerable<CatalogItem> GetPreconfiguredItems()
7070
{
7171
return new List<CatalogItem>()
7272
{
73-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1" },
74-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2" },
75-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3" },
76-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4" },
77-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5" },
78-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6" },
79-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7" },
80-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8" },
81-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9" },
82-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10" },
83-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11" },
84-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12" }
73+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1", AvailableStock = 1},
74+
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2", AvailableStock = 1 },
75+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3", AvailableStock = 1 },
76+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4", AvailableStock = 1 },
77+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5", AvailableStock = 1 },
78+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6", AvailableStock = 1 },
79+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7", AvailableStock = 1 },
80+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8", AvailableStock = 1 },
81+
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9", AvailableStock = 1 },
82+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10", AvailableStock = 1 },
83+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11", AvailableStock = 1 },
84+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12", AvailableStock = 1 }
8585
};
8686
}
8787
}

src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandMsgHandler.cs renamed to src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
using Commands;
1313
using IntegrationEvents.Events;
1414

15-
public class ConfirmOrderStockCommandMsgHandler : IIntegrationEventHandler<ConfirmOrderStockCommandMsg>
15+
public class ConfirmOrderStockCommandHandler : IIntegrationEventHandler<ConfirmOrderStockCommand>
1616
{
1717
private readonly CatalogContext _catalogContext;
1818
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
1919

20-
public ConfirmOrderStockCommandMsgHandler(CatalogContext catalogContext,
20+
public ConfirmOrderStockCommandHandler(CatalogContext catalogContext,
2121
ICatalogIntegrationEventService catalogIntegrationEventService)
2222
{
2323
_catalogContext = catalogContext;
2424
_catalogIntegrationEventService = catalogIntegrationEventService;
2525
}
2626

27-
public async Task Handle(ConfirmOrderStockCommandMsg @event)
27+
public async Task Handle(ConfirmOrderStockCommand command)
2828
{
2929
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();
3030

31-
foreach (var orderStockItem in @event.OrderStockItems)
31+
foreach (var orderStockItem in command.OrderStockItems)
3232
{
3333
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
3434
CheckValidcatalogItemId(catalogItem);
@@ -39,9 +39,9 @@ public async Task Handle(ConfirmOrderStockCommandMsg @event)
3939
confirmedOrderStockItems.Add(confirmedOrderStockItem);
4040
}
4141

42-
var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.Confirmed)
43-
? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(@event.OrderId, confirmedOrderStockItems)
44-
: new OrderStockConfirmedIntegrationEvent(@event.OrderId);
42+
var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.HasStock)
43+
? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(command.OrderId, confirmedOrderStockItems)
44+
: new OrderStockConfirmedIntegrationEvent(command.OrderId);
4545

4646
await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent);
4747
await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent);

src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs renamed to src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33
using BuildingBlocks.EventBus.Abstractions;
44
using System.Threading.Tasks;
55
using Infrastructure;
6-
using global::Catalog.API.Infrastructure.Exceptions;
7-
using global::Catalog.API.IntegrationEvents;
8-
using Model;
96
using Commands;
107

11-
public class DecrementOrderStockCommandMsgHandler : IIntegrationEventHandler<DecrementOrderStockCommandMsg>
8+
public class DecrementOrderStockCommandHandler : IIntegrationEventHandler<DecrementOrderStockCommand>
129
{
1310
private readonly CatalogContext _catalogContext;
1411

15-
public DecrementOrderStockCommandMsgHandler(CatalogContext catalogContext)
12+
public DecrementOrderStockCommandHandler(CatalogContext catalogContext)
1613
{
1714
_catalogContext = catalogContext;
1815
}
1916

20-
public async Task Handle(DecrementOrderStockCommandMsg @event)
17+
public async Task Handle(DecrementOrderStockCommand command)
2118
{
2219
//we're not blocking stock/inventory
23-
foreach (var orderStockItem in @event.OrderStockItems)
20+
foreach (var orderStockItem in command.OrderStockItems)
2421
{
2522
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
2623

src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs renamed to src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using BuildingBlocks.EventBus.Events;
44
using System.Collections.Generic;
55

6-
public class ConfirmOrderStockCommandMsg : IntegrationEvent
6+
public class ConfirmOrderStockCommand : IntegrationEvent
77
{
88
public int OrderId { get; }
99
public IEnumerable<OrderStockItem> OrderStockItems { get; }
1010

11-
public ConfirmOrderStockCommandMsg(int orderId,
11+
public ConfirmOrderStockCommand(int orderId,
1212
IEnumerable<OrderStockItem> orderStockItems)
1313
{
1414
OrderId = orderId;

src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs renamed to src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using System.Collections.Generic;
44
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
55

6-
public class DecrementOrderStockCommandMsg : IntegrationEvent
6+
public class DecrementOrderStockCommand : IntegrationEvent
77
{
88
public int OrderId { get; }
99
public IEnumerable<OrderStockItem> OrderStockItems { get; }
1010

11-
public DecrementOrderStockCommandMsg(int orderId,
11+
public DecrementOrderStockCommand(int orderId,
1212
IEnumerable<OrderStockItem> orderStockItems)
1313
{
1414
OrderId = orderId;

src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent
77
{
88
public int OrderId { get; }
99

10-
public IEnumerable<ConfirmedOrderStockItem> OrderStockItem { get; }
10+
public List<ConfirmedOrderStockItem> OrderStockItems { get; }
1111

12-
public OrderStockNotConfirmedIntegrationEvent(int orderId,
13-
IEnumerable<ConfirmedOrderStockItem> orderStockItem)
12+
public OrderStockNotConfirmedIntegrationEvent(int orderId,
13+
List<ConfirmedOrderStockItem> orderStockItems)
1414
{
1515
OrderId = orderId;
16-
OrderStockItem = orderStockItem;
16+
OrderStockItems = orderStockItems;
1717
}
1818
}
1919

2020
public class ConfirmedOrderStockItem
2121
{
2222
public int ProductId { get; }
23-
public bool Confirmed { get; }
23+
public bool HasStock { get; }
2424

25-
public ConfirmedOrderStockItem(int productId, bool confirmed)
25+
public ConfirmedOrderStockItem(int productId, bool hasStock)
2626
{
2727
ProductId = productId;
28-
Confirmed = confirmed;
28+
HasStock = hasStock;
2929
}
3030
}
3131
}

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
121121
return new DefaultRabbitMQPersistentConnection(factory, logger);
122122
});
123123

124-
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
125-
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
126-
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommandMsg>, ConfirmOrderStockCommandMsgHandler>();
127-
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommandMsg>, DecrementOrderStockCommandMsgHandler>();
124+
RegisterServiceBus(services);
128125

129126
var container = new ContainerBuilder();
130127
container.Populate(services);
@@ -188,12 +185,24 @@ private void WaitForSqlAvailability(CatalogContext ctx, ILoggerFactory loggerFac
188185
}
189186
}
190187

188+
private void RegisterServiceBus(IServiceCollection services)
189+
{
190+
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
191+
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
192+
193+
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommand>,
194+
ConfirmOrderStockCommandHandler>();
195+
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommand>,
196+
DecrementOrderStockCommandHandler>();
197+
198+
}
199+
191200
private void ConfigureEventBus(IApplicationBuilder app)
192201
{
193202
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
194203

195-
eventBus.Subscribe<ConfirmOrderStockCommandMsg, IIntegrationEventHandler<ConfirmOrderStockCommandMsg>>();
196-
eventBus.Subscribe<DecrementOrderStockCommandMsg, IIntegrationEventHandler<DecrementOrderStockCommandMsg>>();
204+
eventBus.Subscribe<ConfirmOrderStockCommand, IIntegrationEventHandler<ConfirmOrderStockCommand>>();
205+
eventBus.Subscribe<DecrementOrderStockCommand, IIntegrationEventHandler<DecrementOrderStockCommand>>();
197206
}
198207
}
199208
}

src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task<bool> Handle(CreateOrderCommand message)
4343
// make sure that consistency is preserved across the whole aggregate
4444
var address = new Address(message.Street, message.City, message.State, message.Country, message.ZipCode);
4545
var order = new Order(message.UserId, address, message.CardTypeId, message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration);
46-
order.SetSubmitedStatus();
46+
4747
foreach (var item in message.OrderItems)
4848
{
4949
order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units);

0 commit comments

Comments
 (0)