@ -0,0 +1,46 @@ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using Microsoft.Extensions.Logging; | |||
using Ordering.API.Application.IntegrationEvents.Events; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using TenantACustomisations.Services; | |||
namespace TenantACustomisations.IntegrationEvents.EventHandling | |||
{ | |||
public class CustomisationEventHandler : IIntegrationEventHandler<CustomisationEvent> | |||
{ | |||
private readonly ILogger<CustomisationEventHandler> _logger; | |||
private readonly IEventBus _eventBus; | |||
private readonly IValidationService validationService; | |||
public CustomisationEventHandler(ILogger<CustomisationEventHandler> logger, IEventBus eventBus) | |||
{ | |||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | |||
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); | |||
validationService = new ValidationService(); | |||
} | |||
public async Task Handle(CustomisationEvent @event) | |||
{ | |||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); | |||
IntegrationEvent integrationEvent = @event.@event; | |||
switch (integrationEvent.GetType().Name) | |||
{ | |||
case "UserCheckoutAcceptedIntegrationEvent": | |||
if (validationService.Validate((UserCheckoutAcceptedIntegrationEvent)integrationEvent)) | |||
{ | |||
integrationEvent.CheckForCustomisation = false; | |||
_eventBus.Publish(integrationEvent); | |||
} | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
} | |||
} |
@ -0,0 +1,14 @@ | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using Ordering.API.Application.IntegrationEvents.Events; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
namespace TenantACustomisations.Services | |||
{ | |||
interface IValidationService | |||
{ | |||
Boolean Validate(UserCheckoutAcceptedIntegrationEvent @event); | |||
} | |||
} |
@ -0,0 +1,17 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | |||
using Ordering.API.Application.IntegrationEvents.Events; | |||
namespace TenantACustomisations.Services | |||
{ | |||
public class ValidationService : IValidationService | |||
{ | |||
public bool Validate(UserCheckoutAcceptedIntegrationEvent @event) | |||
{ | |||
return @event.State == "Oslo"; | |||
} | |||
} | |||
} |
@ -1,8 +1,28 @@ | |||
{ | |||
"Logging": { | |||
"LogLevel": { | |||
"Default": "Warning" | |||
"Serilog": { | |||
"SeqServerUrl": null, | |||
"LogstashgUrl": null, | |||
"MinimumLevel": { | |||
"Default": "Information", | |||
"Override": { | |||
"Microsoft": "Warning", | |||
"Microsoft.eShopOnContainers": "Information", | |||
"System": "Warning" | |||
} | |||
} | |||
}, | |||
"AllowedHosts": "*" | |||
} | |||
"IdentityUrl": "http://localhost:5105", | |||
"ConnectionString": "127.0.0.1", | |||
"AzureServiceBusEnabled": false, | |||
"SubscriptionClientName": "TenantACustomisation", | |||
"ApplicationInsights": { | |||
"InstrumentationKey": "" | |||
}, | |||
"EventBusRetryCount": 5, | |||
"UseVault": false, | |||
"Vault": { | |||
"Name": "eshop", | |||
"ClientId": "your-clien-id", | |||
"ClientSecret": "your-client-secret" | |||
} | |||
} |