2017-03-31 10:30:56 +02:00
|
|
|
|
using Basket.API.IntegrationEvents.Events;
|
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
2019-02-18 19:33:04 +00:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API;
|
2019-05-05 15:22:11 +03:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Infrastructure.Repositories;
|
2019-02-18 19:33:04 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Serilog.Context;
|
2017-03-31 10:30:56 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Basket.API.IntegrationEvents.EventHandling
|
|
|
|
|
{
|
|
|
|
|
public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<OrderStartedIntegrationEvent>
|
|
|
|
|
{
|
|
|
|
|
private readonly IBasketRepository _repository;
|
2019-02-18 19:33:04 +00:00
|
|
|
|
private readonly ILogger<OrderStartedIntegrationEventHandler> _logger;
|
2017-04-17 12:28:12 +02:00
|
|
|
|
|
2019-02-18 19:33:04 +00:00
|
|
|
|
public OrderStartedIntegrationEventHandler(
|
|
|
|
|
IBasketRepository repository,
|
|
|
|
|
ILogger<OrderStartedIntegrationEventHandler> logger)
|
2017-03-31 10:30:56 +02:00
|
|
|
|
{
|
2017-04-17 12:28:12 +02:00
|
|
|
|
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
|
2019-02-18 19:33:04 +00:00
|
|
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
2017-03-31 10:30:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Handle(OrderStartedIntegrationEvent @event)
|
|
|
|
|
{
|
2019-02-26 21:55:04 +00:00
|
|
|
|
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
|
2019-02-18 19:33:04 +00:00
|
|
|
|
{
|
2019-02-26 21:55:04 +00:00
|
|
|
|
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
|
2019-02-18 19:33:04 +00:00
|
|
|
|
|
|
|
|
|
await _repository.DeleteBasketAsync(@event.UserId.ToString());
|
|
|
|
|
}
|
2017-03-31 10:30:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|