naming changes
This commit is contained in:
parent
63cba2cad9
commit
0ee173cd34
@ -12,23 +12,23 @@
|
|||||||
using Commands;
|
using Commands;
|
||||||
using IntegrationEvents.Events;
|
using IntegrationEvents.Events;
|
||||||
|
|
||||||
public class ConfirmOrderStockCommandMsgHandler : IIntegrationEventHandler<ConfirmOrderStockCommandMsg>
|
public class ConfirmOrderStockCommandHandler : IIntegrationEventHandler<ConfirmOrderStockCommand>
|
||||||
{
|
{
|
||||||
private readonly CatalogContext _catalogContext;
|
private readonly CatalogContext _catalogContext;
|
||||||
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
|
private readonly ICatalogIntegrationEventService _catalogIntegrationEventService;
|
||||||
|
|
||||||
public ConfirmOrderStockCommandMsgHandler(CatalogContext catalogContext,
|
public ConfirmOrderStockCommandHandler(CatalogContext catalogContext,
|
||||||
ICatalogIntegrationEventService catalogIntegrationEventService)
|
ICatalogIntegrationEventService catalogIntegrationEventService)
|
||||||
{
|
{
|
||||||
_catalogContext = catalogContext;
|
_catalogContext = catalogContext;
|
||||||
_catalogIntegrationEventService = catalogIntegrationEventService;
|
_catalogIntegrationEventService = catalogIntegrationEventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(ConfirmOrderStockCommandMsg @event)
|
public async Task Handle(ConfirmOrderStockCommand command)
|
||||||
{
|
{
|
||||||
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();
|
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();
|
||||||
|
|
||||||
foreach (var orderStockItem in @event.OrderStockItems)
|
foreach (var orderStockItem in command.OrderStockItems)
|
||||||
{
|
{
|
||||||
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
||||||
CheckValidcatalogItemId(catalogItem);
|
CheckValidcatalogItemId(catalogItem);
|
||||||
@ -39,9 +39,9 @@
|
|||||||
confirmedOrderStockItems.Add(confirmedOrderStockItem);
|
confirmedOrderStockItems.Add(confirmedOrderStockItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.Confirmed)
|
var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.HasStock)
|
||||||
? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(@event.OrderId, confirmedOrderStockItems)
|
? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(command.OrderId, confirmedOrderStockItems)
|
||||||
: new OrderStockConfirmedIntegrationEvent(@event.OrderId);
|
: new OrderStockConfirmedIntegrationEvent(command.OrderId);
|
||||||
|
|
||||||
await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent);
|
await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent);
|
||||||
await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent);
|
await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent);
|
@ -5,19 +5,19 @@
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Commands;
|
using Commands;
|
||||||
|
|
||||||
public class DecrementOrderStockCommandMsgHandler : IIntegrationEventHandler<DecrementOrderStockCommandMsg>
|
public class DecrementOrderStockCommandHandler : IIntegrationEventHandler<DecrementOrderStockCommand>
|
||||||
{
|
{
|
||||||
private readonly CatalogContext _catalogContext;
|
private readonly CatalogContext _catalogContext;
|
||||||
|
|
||||||
public DecrementOrderStockCommandMsgHandler(CatalogContext catalogContext)
|
public DecrementOrderStockCommandHandler(CatalogContext catalogContext)
|
||||||
{
|
{
|
||||||
_catalogContext = catalogContext;
|
_catalogContext = catalogContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(DecrementOrderStockCommandMsg @event)
|
public async Task Handle(DecrementOrderStockCommand command)
|
||||||
{
|
{
|
||||||
//we're not blocking stock/inventory
|
//we're not blocking stock/inventory
|
||||||
foreach (var orderStockItem in @event.OrderStockItems)
|
foreach (var orderStockItem in command.OrderStockItems)
|
||||||
{
|
{
|
||||||
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId);
|
||||||
|
|
@ -3,12 +3,12 @@
|
|||||||
using BuildingBlocks.EventBus.Events;
|
using BuildingBlocks.EventBus.Events;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class ConfirmOrderStockCommandMsg : IntegrationEvent
|
public class ConfirmOrderStockCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
||||||
|
|
||||||
public ConfirmOrderStockCommandMsg(int orderId,
|
public ConfirmOrderStockCommand(int orderId,
|
||||||
IEnumerable<OrderStockItem> orderStockItems)
|
IEnumerable<OrderStockItem> orderStockItems)
|
||||||
{
|
{
|
||||||
OrderId = orderId;
|
OrderId = orderId;
|
@ -3,12 +3,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
public class DecrementOrderStockCommandMsg : IntegrationEvent
|
public class DecrementOrderStockCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
||||||
|
|
||||||
public DecrementOrderStockCommandMsg(int orderId,
|
public DecrementOrderStockCommand(int orderId,
|
||||||
IEnumerable<OrderStockItem> orderStockItems)
|
IEnumerable<OrderStockItem> orderStockItems)
|
||||||
{
|
{
|
||||||
OrderId = orderId;
|
OrderId = orderId;
|
@ -20,12 +20,12 @@
|
|||||||
public class ConfirmedOrderStockItem
|
public class ConfirmedOrderStockItem
|
||||||
{
|
{
|
||||||
public int ProductId { get; }
|
public int ProductId { get; }
|
||||||
public bool Confirmed { get; }
|
public bool HasStock { get; }
|
||||||
|
|
||||||
public ConfirmedOrderStockItem(int productId, bool confirmed)
|
public ConfirmedOrderStockItem(int productId, bool hasStock)
|
||||||
{
|
{
|
||||||
ProductId = productId;
|
ProductId = productId;
|
||||||
Confirmed = confirmed;
|
HasStock = hasStock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -190,10 +190,10 @@
|
|||||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||||
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
||||||
|
|
||||||
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommandMsg>,
|
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommand>,
|
||||||
ConfirmOrderStockCommandMsgHandler>();
|
ConfirmOrderStockCommandHandler>();
|
||||||
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommandMsg>,
|
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommand>,
|
||||||
DecrementOrderStockCommandMsgHandler>();
|
DecrementOrderStockCommandHandler>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,8 +201,8 @@
|
|||||||
{
|
{
|
||||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||||
|
|
||||||
eventBus.Subscribe<ConfirmOrderStockCommandMsg, IIntegrationEventHandler<ConfirmOrderStockCommandMsg>>();
|
eventBus.Subscribe<ConfirmOrderStockCommand, IIntegrationEventHandler<ConfirmOrderStockCommand>>();
|
||||||
eventBus.Subscribe<DecrementOrderStockCommandMsg, IIntegrationEventHandler<DecrementOrderStockCommandMsg>>();
|
eventBus.Subscribe<DecrementOrderStockCommand, IIntegrationEventHandler<DecrementOrderStockCommand>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@
|
|||||||
var orderStockList = orderStatusChangedToAwaitingValidationDomainEvent.OrderItems
|
var orderStockList = orderStatusChangedToAwaitingValidationDomainEvent.OrderItems
|
||||||
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
|
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
|
||||||
|
|
||||||
var confirmOrderStockEvent = new ConfirmOrderStockCommandMsg(orderStatusChangedToAwaitingValidationDomainEvent.OrderId,
|
var confirmOrderStockCommand = new ConfirmOrderStockCommand(orderStatusChangedToAwaitingValidationDomainEvent.OrderId,
|
||||||
orderStockList);
|
orderStockList);
|
||||||
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(confirmOrderStockEvent);
|
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(confirmOrderStockCommand);
|
||||||
await _orderingIntegrationEventService.PublishThroughEventBusAsync(confirmOrderStockEvent);
|
await _orderingIntegrationEventService.PublishThroughEventBusAsync(confirmOrderStockCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,10 +35,10 @@
|
|||||||
var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems
|
var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems
|
||||||
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
|
.Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));
|
||||||
|
|
||||||
var decrementOrderStockCommandMsg = new DecrementOrderStockCommandMsg(orderStatusChangedToPaidDomainEvent.OrderId,
|
var decrementOrderStockCommand = new DecrementOrderStockCommand(orderStatusChangedToPaidDomainEvent.OrderId,
|
||||||
orderStockList);
|
orderStockList);
|
||||||
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg);
|
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommand);
|
||||||
await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommandMsg);
|
await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,9 +31,9 @@
|
|||||||
.LogTrace($"Order with Id: {orderStatusChangedToStockConfirmedDomainEvent.OrderId} has been successfully updated with " +
|
.LogTrace($"Order with Id: {orderStatusChangedToStockConfirmedDomainEvent.OrderId} has been successfully updated with " +
|
||||||
$"a status order id: {OrderStatus.StockConfirmed.Id}");
|
$"a status order id: {OrderStatus.StockConfirmed.Id}");
|
||||||
|
|
||||||
var payOrderCommandMsg = new PayOrderCommandMsg(orderStatusChangedToStockConfirmedDomainEvent.OrderId);
|
var payOrderCommand = new PayOrderCommand(orderStatusChangedToStockConfirmedDomainEvent.OrderId);
|
||||||
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommandMsg);
|
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommand);
|
||||||
await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommandMsg);
|
await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Ordering.API.Application.IntegrationCommands.Commands
|
namespace Ordering.API.Application.IntegrationCommands.Commands
|
||||||
{
|
{
|
||||||
public class ConfirmGracePeriodCommandMsg : IntegrationEvent
|
public class ConfirmGracePeriodCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
|
|
||||||
public ConfirmGracePeriodCommandMsg(int orderId) =>
|
public ConfirmGracePeriodCommand(int orderId) =>
|
||||||
OrderId = orderId;
|
OrderId = orderId;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,12 +3,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
public class ConfirmOrderStockCommandMsg : IntegrationEvent
|
public class ConfirmOrderStockCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
||||||
|
|
||||||
public ConfirmOrderStockCommandMsg(int orderId,
|
public ConfirmOrderStockCommand(int orderId,
|
||||||
IEnumerable<OrderStockItem> orderStockItems)
|
IEnumerable<OrderStockItem> orderStockItems)
|
||||||
{
|
{
|
||||||
OrderId = orderId;
|
OrderId = orderId;
|
@ -3,12 +3,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
public class DecrementOrderStockCommandMsg : IntegrationEvent
|
public class DecrementOrderStockCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
public IEnumerable<OrderStockItem> OrderStockItems { get; }
|
||||||
|
|
||||||
public DecrementOrderStockCommandMsg(int orderId,
|
public DecrementOrderStockCommand(int orderId,
|
||||||
IEnumerable<OrderStockItem> orderStockItems)
|
IEnumerable<OrderStockItem> orderStockItems)
|
||||||
{
|
{
|
||||||
OrderId = orderId;
|
OrderId = orderId;
|
@ -2,11 +2,11 @@
|
|||||||
{
|
{
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
public class PayOrderCommandMsg : IntegrationEvent
|
public class PayOrderCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
|
|
||||||
public PayOrderCommandMsg(int orderId)
|
public PayOrderCommand(int orderId)
|
||||||
{
|
{
|
||||||
OrderId = orderId;
|
OrderId = orderId;
|
||||||
}
|
}
|
@ -1,14 +0,0 @@
|
|||||||
namespace Ordering.API.Application.IntegrationCommands.Commands
|
|
||||||
{
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
|
||||||
|
|
||||||
public class ShipOrderCommandMsg : IntegrationEvent
|
|
||||||
{
|
|
||||||
public int OrderId { get; }
|
|
||||||
|
|
||||||
public ShipOrderCommandMsg(int orderId)
|
|
||||||
{
|
|
||||||
OrderId = orderId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
|||||||
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
|
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
|
||||||
|
|
||||||
var orderStockNotConfirmedItems = @event.OrderStockItems
|
var orderStockNotConfirmedItems = @event.OrderStockItems
|
||||||
.FindAll(c => !c.Confirmed)
|
.FindAll(c => !c.HasStock)
|
||||||
.Select(c => c.ProductId);
|
.Select(c => c.ProductId);
|
||||||
|
|
||||||
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
|
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
|
||||||
|
@ -21,12 +21,12 @@ namespace Ordering.API.Application.IntegrationEvents.Events
|
|||||||
public class ConfirmedOrderStockItem
|
public class ConfirmedOrderStockItem
|
||||||
{
|
{
|
||||||
public int ProductId { get; }
|
public int ProductId { get; }
|
||||||
public bool Confirmed { get; }
|
public bool HasStock { get; }
|
||||||
|
|
||||||
public ConfirmedOrderStockItem(int productId, bool confirmed)
|
public ConfirmedOrderStockItem(int productId, bool hasStock)
|
||||||
{
|
{
|
||||||
ProductId = productId;
|
ProductId = productId;
|
||||||
Confirmed = confirmed;
|
HasStock = hasStock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ namespace Ordering.API.Application.Sagas
|
|||||||
/// with the validations.
|
/// with the validations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OrderProcessSaga : OrderSaga,
|
public class OrderProcessSaga : OrderSaga,
|
||||||
IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>,
|
IIntegrationEventHandler<ConfirmGracePeriodCommand>,
|
||||||
IAsyncRequestHandler<CancelOrderCommand, bool>,
|
IAsyncRequestHandler<CancelOrderCommand, bool>,
|
||||||
IAsyncRequestHandler<ShipOrderCommand, bool>
|
IAsyncRequestHandler<ShipOrderCommand, bool>
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ namespace Ordering.API.Application.Sagas
|
|||||||
/// period has completed.
|
/// period has completed.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Handle(ConfirmGracePeriodCommandMsg command)
|
public async Task Handle(ConfirmGracePeriodCommand command)
|
||||||
{
|
{
|
||||||
var orderSaga = FindSagaById(command.OrderId);
|
var orderSaga = FindSagaById(command.OrderId);
|
||||||
CheckValidSagaId(orderSaga);
|
CheckValidSagaId(orderSaga);
|
||||||
|
@ -171,7 +171,7 @@
|
|||||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||||
|
|
||||||
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
|
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
|
||||||
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
|
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommand>, OrderProcessSaga>();
|
||||||
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
|
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
|
||||||
OrderStockConfirmedIntegrationEventHandler>();
|
OrderStockConfirmedIntegrationEventHandler>();
|
||||||
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
|
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
|
||||||
@ -187,7 +187,7 @@
|
|||||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||||
|
|
||||||
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
|
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
|
||||||
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>();
|
eventBus.Subscribe<ConfirmGracePeriodCommand, IIntegrationEventHandler<ConfirmGracePeriodCommand>>();
|
||||||
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
|
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
|
||||||
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
|
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
|
||||||
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
||||||
|
@ -3,21 +3,17 @@
|
|||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
using Payment.API.IntegrationCommands.Commands;
|
using Payment.API.IntegrationCommands.Commands;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
|
||||||
using Payment.API.IntegrationEvents;
|
using Payment.API.IntegrationEvents;
|
||||||
using Payment.API.IntegrationEvents.Events;
|
using Payment.API.IntegrationEvents.Events;
|
||||||
|
|
||||||
public class PayOrderCommandMsgHandler : IIntegrationEventHandler<PayOrderCommandMsg>
|
public class PayOrderCommandHandler : IIntegrationEventHandler<PayOrderCommand>
|
||||||
{
|
{
|
||||||
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService;
|
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService;
|
||||||
|
|
||||||
public PayOrderCommandMsgHandler(IPaymentIntegrationEventService paymentIntegrationEventService)
|
public PayOrderCommandHandler(IPaymentIntegrationEventService paymentIntegrationEventService)
|
||||||
{
|
=> _paymentIntegrationEventService = paymentIntegrationEventService;
|
||||||
_paymentIntegrationEventService = paymentIntegrationEventService;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public async Task Handle(PayOrderCommand @event)
|
||||||
public async Task Handle(PayOrderCommandMsg @event)
|
|
||||||
{
|
{
|
||||||
//PAYMENT SUCCESSED
|
//PAYMENT SUCCESSED
|
||||||
var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
|
var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
|
||||||
@ -28,4 +24,4 @@
|
|||||||
//_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent);
|
//_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,10 +2,10 @@
|
|||||||
{
|
{
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
public class PayOrderCommandMsg : IntegrationEvent
|
public class PayOrderCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get; }
|
public int OrderId { get; }
|
||||||
|
|
||||||
public PayOrderCommandMsg(int orderId) => OrderId = orderId;
|
public PayOrderCommand(int orderId) => OrderId = orderId;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,10 +48,8 @@ namespace Payment.API
|
|||||||
|
|
||||||
return new DefaultRabbitMQPersistentConnection(factory, logger);
|
return new DefaultRabbitMQPersistentConnection(factory, logger);
|
||||||
});
|
});
|
||||||
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
|
||||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
RegisterServiceBus(services);
|
||||||
services.AddTransient<IIntegrationEventHandler<PayOrderCommandMsg>, PayOrderCommandMsgHandler>();
|
|
||||||
|
|
||||||
|
|
||||||
services.AddSwaggerGen();
|
services.AddSwaggerGen();
|
||||||
services.ConfigureSwaggerGen(options =>
|
services.ConfigureSwaggerGen(options =>
|
||||||
@ -85,10 +83,18 @@ namespace Payment.API
|
|||||||
ConfigureEventBus(app);
|
ConfigureEventBus(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RegisterServiceBus(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
||||||
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||||
|
|
||||||
|
services.AddTransient<IIntegrationEventHandler<PayOrderCommand>, PayOrderCommandHandler>();
|
||||||
|
}
|
||||||
|
|
||||||
private void ConfigureEventBus(IApplicationBuilder app)
|
private void ConfigureEventBus(IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||||
eventBus.Subscribe<PayOrderCommandMsg, IIntegrationEventHandler<PayOrderCommandMsg>>();
|
eventBus.Subscribe<PayOrderCommand, IIntegrationEventHandler<PayOrderCommand>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
{
|
{
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
public class ConfirmGracePeriodCommandMsg : IntegrationEvent
|
public class ConfirmGracePeriodCommand : IntegrationEvent
|
||||||
{
|
{
|
||||||
public int OrderId { get;}
|
public int OrderId { get;}
|
||||||
|
|
||||||
public ConfirmGracePeriodCommandMsg(int orderId) => OrderId = orderId;
|
public ConfirmGracePeriodCommand(int orderId) => OrderId = orderId;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
sagaManagerService.CheckFinishedGracePeriodOrders();
|
sagaManagerService.CheckConfirmedGracePeriodOrders();
|
||||||
await Task.Delay(90000);
|
await Task.Delay(90000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
{
|
{
|
||||||
public interface ISagaManagerService
|
public interface ISagaManagerService
|
||||||
{
|
{
|
||||||
void CheckFinishedGracePeriodOrders();
|
void CheckConfirmedGracePeriodOrders();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,19 +23,18 @@
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckFinishedGracePeriodOrders()
|
public void CheckConfirmedGracePeriodOrders()
|
||||||
{
|
{
|
||||||
var orderIds = GetFinishedGracePeriodOrders();
|
var orderIds = GetConfirmedGracePeriodOrders();
|
||||||
|
|
||||||
foreach (var orderId in orderIds)
|
foreach (var orderId in orderIds)
|
||||||
{
|
{
|
||||||
var confirmGracePeriodEvent = new ConfirmGracePeriodCommandMsg(orderId);
|
var confirmGracePeriodEvent = new ConfirmGracePeriodCommand(orderId);
|
||||||
|
|
||||||
_sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent);
|
_sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<int> GetFinishedGracePeriodOrders()
|
private IEnumerable<int> GetConfirmedGracePeriodOrders()
|
||||||
{
|
{
|
||||||
IEnumerable<int> orderIds = new List<int>();
|
IEnumerable<int> orderIds = new List<int>();
|
||||||
using (var conn = new SqlConnection(_settings.ConnectionString))
|
using (var conn = new SqlConnection(_settings.ConnectionString))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user