@ -1,20 +1,21 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.CommandHandlers | |||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.EventHandling | |||
{ | |||
using BuildingBlocks.EventBus.Abstractions; | |||
using System.Threading.Tasks; | |||
using Infrastructure; | |||
using Commands; | |||
using Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events; | |||
public class DecrementOrderStockCommandHandler : IIntegrationEventHandler<DecrementOrderStockCommand> | |||
public class OrderStatusChangedToPaidIntegrationEventHandler : | |||
IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent> | |||
{ | |||
private readonly CatalogContext _catalogContext; | |||
public DecrementOrderStockCommandHandler(CatalogContext catalogContext) | |||
public OrderStatusChangedToPaidIntegrationEventHandler(CatalogContext catalogContext) | |||
{ | |||
_catalogContext = catalogContext; | |||
} | |||
public async Task Handle(DecrementOrderStockCommand command) | |||
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent command) | |||
{ | |||
//we're not blocking stock/inventory | |||
foreach (var orderStockItem in command.OrderStockItems) |
@ -1,14 +1,14 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands | |||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events | |||
{ | |||
using BuildingBlocks.EventBus.Events; | |||
using System.Collections.Generic; | |||
public class ConfirmOrderStockCommand : IntegrationEvent | |||
public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public IEnumerable<OrderStockItem> OrderStockItems { get; } | |||
public ConfirmOrderStockCommand(int orderId, | |||
public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, | |||
IEnumerable<OrderStockItem> orderStockItems) | |||
{ | |||
OrderId = orderId; |
@ -1,14 +1,14 @@ | |||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationCommands.Commands | |||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Events | |||
{ | |||
using System.Collections.Generic; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class DecrementOrderStockCommand : IntegrationEvent | |||
public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public IEnumerable<OrderStockItem> OrderStockItems { get; } | |||
public DecrementOrderStockCommand(int orderId, | |||
public OrderStatusChangedToPaidIntegrationEvent(int orderId, | |||
IEnumerable<OrderStockItem> orderStockItems) | |||
{ | |||
OrderId = orderId; |
@ -1,12 +0,0 @@ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
namespace Ordering.API.Application.IntegrationCommands.Commands | |||
{ | |||
public class ConfirmGracePeriodCommand : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public ConfirmGracePeriodCommand(int orderId) => | |||
OrderId = orderId; | |||
} | |||
} |
@ -1,14 +0,0 @@ | |||
namespace Ordering.API.Application.IntegrationCommands.Commands | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class PayOrderCommand : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public PayOrderCommand(int orderId) | |||
{ | |||
OrderId = orderId; | |||
} | |||
} | |||
} |
@ -1,33 +0,0 @@ | |||
using System.Linq; | |||
using Ordering.API.Application.IntegrationCommands.Commands; | |||
namespace Ordering.API.Application.IntegrationEvents.EventHandling | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using System.Threading.Tasks; | |||
using Events; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; | |||
public class OrderStockNotConfirmedIntegrationEventHandler : IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent> | |||
{ | |||
private readonly IOrderRepository _orderRepository; | |||
public OrderStockNotConfirmedIntegrationEventHandler(IOrderRepository orderRepository) | |||
{ | |||
_orderRepository = orderRepository; | |||
} | |||
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event) | |||
{ | |||
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId); | |||
var orderStockNotConfirmedItems = @event.OrderStockItems | |||
.FindAll(c => !c.HasStock) | |||
.Select(c => c.ProductId); | |||
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems); | |||
await _orderRepository.UnitOfWork.SaveEntitiesAsync(); | |||
} | |||
} | |||
} |
@ -0,0 +1,31 @@ | |||
namespace Ordering.API.Application.IntegrationEvents.EventHandling | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using System.Threading.Tasks; | |||
using Events; | |||
using System.Linq; | |||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; | |||
public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandler<OrderStockRejectedIntegrationEvent> | |||
{ | |||
private readonly IOrderRepository _orderRepository; | |||
public OrderStockRejectedIntegrationEventHandler(IOrderRepository orderRepository) | |||
{ | |||
_orderRepository = orderRepository; | |||
} | |||
public async Task Handle(OrderStockRejectedIntegrationEvent @event) | |||
{ | |||
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); | |||
var orderStockRejectedItems = @event.OrderStockItems | |||
.FindAll(c => !c.HasStock) | |||
.Select(c => c.ProductId); | |||
orderToUpdate.SetCancelledStatusWhenStockIsRejected(orderStockRejectedItems); | |||
await _orderRepository.UnitOfWork.SaveEntitiesAsync(); | |||
} | |||
} | |||
} |
@ -0,0 +1,12 @@ | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class GracePeriodConfirmedIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public GracePeriodConfirmedIntegrationEvent(int orderId) => | |||
OrderId = orderId; | |||
} | |||
} |
@ -1,11 +1,11 @@ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class OrderPaymentFailedIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public OrderPaymentFailedIntegrationEvent(int orderId) => OrderId = orderId; | |||
} | |||
} | |||
} |
@ -1,11 +1,11 @@ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class OrderPaymentSuccededIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public OrderPaymentSuccededIntegrationEvent(int orderId) => OrderId = orderId; | |||
} | |||
} | |||
} |
@ -1,14 +1,14 @@ | |||
namespace Ordering.API.Application.IntegrationCommands.Commands | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using System.Collections.Generic; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class ConfirmOrderStockCommand : IntegrationEvent | |||
public class OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public IEnumerable<OrderStockItem> OrderStockItems { get; } | |||
public ConfirmOrderStockCommand(int orderId, | |||
public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, | |||
IEnumerable<OrderStockItem> orderStockItems) | |||
{ | |||
OrderId = orderId; |
@ -1,14 +1,14 @@ | |||
namespace Ordering.API.Application.IntegrationCommands.Commands | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using System.Collections.Generic; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class DecrementOrderStockCommand : IntegrationEvent | |||
public class OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public IEnumerable<OrderStockItem> OrderStockItems { get; } | |||
public DecrementOrderStockCommand(int orderId, | |||
public OrderStatusChangedToPaidIntegrationEvent(int orderId, | |||
IEnumerable<OrderStockItem> orderStockItems) | |||
{ | |||
OrderId = orderId; |
@ -0,0 +1,12 @@ | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId) | |||
=> OrderId = orderId; | |||
} | |||
} |
@ -1,16 +1,15 @@ | |||
using System.Collections.Generic; | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
namespace Ordering.API.Application.IntegrationEvents.Events | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using System.Collections.Generic; | |||
public class OrderStockNotConfirmedIntegrationEvent : IntegrationEvent | |||
public class OrderStockRejectedIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public List<ConfirmedOrderStockItem> OrderStockItems { get; } | |||
public OrderStockNotConfirmedIntegrationEvent(int orderId, | |||
public OrderStockRejectedIntegrationEvent(int orderId, | |||
List<ConfirmedOrderStockItem> orderStockItems) | |||
{ | |||
OrderId = orderId; |
@ -1,27 +0,0 @@ | |||
namespace Payment.API.IntegrationCommands.CommandHandlers | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using Payment.API.IntegrationCommands.Commands; | |||
using System.Threading.Tasks; | |||
using Payment.API.IntegrationEvents; | |||
using Payment.API.IntegrationEvents.Events; | |||
public class PayOrderCommandHandler : IIntegrationEventHandler<PayOrderCommand> | |||
{ | |||
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService; | |||
public PayOrderCommandHandler(IPaymentIntegrationEventService paymentIntegrationEventService) | |||
=> _paymentIntegrationEventService = paymentIntegrationEventService; | |||
public async Task Handle(PayOrderCommand @event) | |||
{ | |||
//PAYMENT SUCCESSED | |||
var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId); | |||
_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentSuccededIntegrationEvent); | |||
//PAYMENT FAILED | |||
//var orderPaymentFailedIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); | |||
//_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent); | |||
} | |||
} | |||
} |
@ -1,11 +0,0 @@ | |||
namespace Payment.API.IntegrationCommands.Commands | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class PayOrderCommand : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public PayOrderCommand(int orderId) => OrderId = orderId; | |||
} | |||
} |
@ -0,0 +1,37 @@ | |||
namespace Payment.API.IntegrationEvents.EventHandling | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using System.Threading.Tasks; | |||
using Payment.API.IntegrationEvents.Events; | |||
using Microsoft.Extensions.Options; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler : | |||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent> | |||
{ | |||
private readonly IEventBus _eventBus; | |||
private readonly PaymentSettings _settings; | |||
public OrderStatusChangedToStockConfirmedIntegrationEventHandler(IEventBus eventBus, | |||
IOptionsSnapshot<PaymentSettings> settings) | |||
{ | |||
_eventBus = eventBus; | |||
_settings = settings.Value; | |||
} | |||
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event) | |||
{ | |||
IntegrationEvent orderPaymentIntegrationEvent; | |||
if(_settings.SuccessPayment) | |||
{ | |||
orderPaymentIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId); | |||
} | |||
else | |||
{ | |||
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); | |||
} | |||
_eventBus.Publish(orderPaymentIntegrationEvent); | |||
} | |||
} | |||
} |
@ -0,0 +1,12 @@ | |||
namespace Payment.API.IntegrationEvents.Events | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public class OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent | |||
{ | |||
public int OrderId { get; } | |||
public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId) | |||
=> OrderId = orderId; | |||
} | |||
} |
@ -1,9 +0,0 @@ | |||
namespace Payment.API.IntegrationEvents | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public interface IPaymentIntegrationEventService | |||
{ | |||
void PublishThroughEventBus(IntegrationEvent evt); | |||
} | |||
} |
@ -1,21 +0,0 @@ | |||
namespace Payment.API.IntegrationEvents | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using System; | |||
public class PaymentIntegrationEventService : IPaymentIntegrationEventService | |||
{ | |||
private readonly IEventBus _eventBus; | |||
public PaymentIntegrationEventService(IEventBus eventBus) | |||
{ | |||
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); | |||
} | |||
public void PublishThroughEventBus(IntegrationEvent evt) | |||
{ | |||
_eventBus.Publish(evt); ; | |||
} | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
namespace Payment.API | |||
{ | |||
public class PaymentSettings | |||
{ | |||
public bool SuccessPayment { get; set; } | |||
public string EventBusConnection { get; set; } | |||
} | |||
} |
@ -1,9 +0,0 @@ | |||
namespace SagaManager.IntegrationEvents | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
public interface ISagaManagerIntegrationEventService | |||
{ | |||
void PublishThroughEventBus(IntegrationEvent evt); | |||
} | |||
} |
@ -1,17 +0,0 @@ | |||
namespace SagaManager.IntegrationEvents | |||
{ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using System; | |||
public class SagaManagerIntegrationEventService : ISagaManagerIntegrationEventService | |||
{ | |||
private readonly IEventBus _eventBus; | |||
public SagaManagerIntegrationEventService(IEventBus eventBus) | |||
=> _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); | |||
public void PublishThroughEventBus(IntegrationEvent evt) => _eventBus.Publish(evt); | |||
} | |||
} |