Skip to content

Commit a84c180

Browse files
committed
Remove PaymentIntegrationEventService and remove integration command to integration event
1 parent def828a commit a84c180

9 files changed

Lines changed: 67 additions & 77 deletions

File tree

src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandHandler.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommand.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Payment.API.IntegrationEvents.EventHandling
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
4+
using System.Threading.Tasks;
5+
using Payment.API.IntegrationEvents.Events;
6+
using Microsoft.Extensions.Options;
7+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
8+
9+
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
10+
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
11+
{
12+
private readonly IEventBus _eventBus;
13+
private readonly PaymentSettings _settings;
14+
15+
public OrderStatusChangedToStockConfirmedIntegrationEventHandler(IEventBus eventBus,
16+
IOptionsSnapshot<PaymentSettings> settings)
17+
{
18+
_eventBus = eventBus;
19+
_settings = settings.Value;
20+
}
21+
22+
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
23+
{
24+
IntegrationEvent orderPaymentIntegrationEvent;
25+
if(_settings.SuccessPayment)
26+
{
27+
orderPaymentIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
28+
}
29+
else
30+
{
31+
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
32+
}
33+
34+
_eventBus.Publish(orderPaymentIntegrationEvent);
35+
}
36+
}
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Payment.API.IntegrationEvents.Events
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
5+
public class OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent
6+
{
7+
public int OrderId { get; }
8+
9+
public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId)
10+
=> OrderId = orderId;
11+
}
12+
}

src/Services/Payment/Payment.API/IntegrationEvents/IPaymentIntegrationEventService.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Services/Payment/Payment.API/IntegrationEvents/PaymentIntegrationEventService.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Payment.API
2+
{
3+
public class PaymentSettings
4+
{
5+
public bool SuccessPayment { get; set; }
6+
public string EventBusConnection { get; set; }
7+
}
8+
}

src/Services/Payment/Payment.API/Startup.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
using Microsoft.Extensions.Logging;
88
using System;
99
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
10-
using Payment.API.IntegrationCommands.Commands;
1110
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
1211
using RabbitMQ.Client;
1312
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
14-
using Payment.API.IntegrationEvents;
15-
using Payment.API.IntegrationCommands.CommandHandlers;
13+
using Payment.API.IntegrationEvents.Events;
14+
using Payment.API.IntegrationEvents.EventHandling;
1615

1716
namespace Payment.API
1817
{
@@ -35,8 +34,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
3534
{
3635
// Add framework services.
3736
services.AddMvc();
38-
39-
services.AddTransient<IPaymentIntegrationEventService, PaymentIntegrationEventService>();
37+
services.Configure<PaymentSettings>(Configuration);
4038
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
4139
{
4240
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
@@ -88,13 +86,15 @@ private void RegisterServiceBus(IServiceCollection services)
8886
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
8987
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
9088

91-
services.AddTransient<IIntegrationEventHandler<PayOrderCommand>, PayOrderCommandHandler>();
89+
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>,
90+
OrderStatusChangedToStockConfirmedIntegrationEventHandler>();
9291
}
9392

9493
private void ConfigureEventBus(IApplicationBuilder app)
9594
{
9695
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
97-
eventBus.Subscribe<PayOrderCommand, IIntegrationEventHandler<PayOrderCommand>>();
96+
eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent,
97+
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>>();
9898
}
9999
}
100-
}
100+
}

src/Services/Payment/Payment.API/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"LogLevel": {
55
"Default": "Warning"
66
}
7-
}
7+
},
8+
"SuccessPayment": "true"
89
}

0 commit comments

Comments
 (0)