Clean Basket event is launched once basket is converted to order and before starting creating order.
Change grace period time to 1 minute Remove unecessary clean basket methods on client
This commit is contained in:
parent
1218069eaf
commit
889d3c86e7
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26403.3
|
VisualStudioVersion = 15.0.26430.6
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -80,9 +80,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Health
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBus.Tests", "src\BuildingBlocks\EventBus\EventBus.Tests\EventBus.Tests.csproj", "{4A980AC4-7205-46BF-8CCB-09E44D700FD4}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBus.Tests", "src\BuildingBlocks\EventBus\EventBus.Tests\EventBus.Tests.csproj", "{4A980AC4-7205-46BF-8CCB-09E44D700FD4}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SagaManager", "SagaManager", "{F38B4FF0-0B49-405A-B1B4-F7A5E3BC4C4E}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GracePeriod", "GracePeriod", "{F38B4FF0-0B49-405A-B1B4-F7A5E3BC4C4E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SagaManager", "src\Services\SagaManager\SagaManager\SagaManager.csproj", "{F6E0F0DD-1400-43C3-B5E0-7CC325728C47}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GracePeriodManager", "src\Services\SagaManager\SagaManager\GracePeriodManager.csproj", "{F6E0F0DD-1400-43C3-B5E0-7CC325728C47}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -13,15 +13,12 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri
|
|||||||
: IAsyncNotificationHandler<BuyerAndPaymentMethodVerifiedDomainEvent>
|
: IAsyncNotificationHandler<BuyerAndPaymentMethodVerifiedDomainEvent>
|
||||||
{
|
{
|
||||||
private readonly IOrderRepository _orderRepository;
|
private readonly IOrderRepository _orderRepository;
|
||||||
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
|
|
||||||
private readonly ILoggerFactory _logger;
|
private readonly ILoggerFactory _logger;
|
||||||
|
|
||||||
public UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler(
|
public UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler(
|
||||||
IOrderRepository orderRepository, ILoggerFactory logger,
|
IOrderRepository orderRepository, ILoggerFactory logger)
|
||||||
IOrderingIntegrationEventService orderingIntegrationEventService)
|
|
||||||
{
|
{
|
||||||
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
|
||||||
_orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService));
|
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,10 +31,6 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri
|
|||||||
orderToUpdate.SetBuyerId(buyerPaymentMethodVerifiedEvent.Buyer.Id);
|
orderToUpdate.SetBuyerId(buyerPaymentMethodVerifiedEvent.Buyer.Id);
|
||||||
orderToUpdate.SetPaymentId(buyerPaymentMethodVerifiedEvent.Payment.Id);
|
orderToUpdate.SetPaymentId(buyerPaymentMethodVerifiedEvent.Payment.Id);
|
||||||
|
|
||||||
var orderStartedIntegrationEvent = new OrderStartedIntegrationEvent(buyerPaymentMethodVerifiedEvent.Buyer.IdentityGuid);
|
|
||||||
|
|
||||||
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStartedIntegrationEvent);
|
|
||||||
|
|
||||||
_logger.CreateLogger(nameof(UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler))
|
_logger.CreateLogger(nameof(UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler))
|
||||||
.LogTrace($"Order with Id: {buyerPaymentMethodVerifiedEvent.OrderId} has been successfully updated with a payment method id: { buyerPaymentMethodVerifiedEvent.Payment.Id }");
|
.LogTrace($"Order with Id: {buyerPaymentMethodVerifiedEvent.OrderId} has been successfully updated with a payment method id: { buyerPaymentMethodVerifiedEvent.Payment.Id }");
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,14 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
|||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly ILoggerFactory _logger;
|
private readonly ILoggerFactory _logger;
|
||||||
|
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
|
||||||
|
|
||||||
public UserCheckoutAcceptedIntegrationEventHandler(IMediator mediator,
|
public UserCheckoutAcceptedIntegrationEventHandler(IMediator mediator,
|
||||||
ILoggerFactory logger)
|
ILoggerFactory logger, IOrderingIntegrationEventService orderingIntegrationEventService)
|
||||||
{
|
{
|
||||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
|
_orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -32,6 +34,11 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
|||||||
public async Task Handle(UserCheckoutAcceptedIntegrationEvent eventMsg)
|
public async Task Handle(UserCheckoutAcceptedIntegrationEvent eventMsg)
|
||||||
{
|
{
|
||||||
var result = false;
|
var result = false;
|
||||||
|
|
||||||
|
// Send Integration event to clean basket once basket is converted to Order and before starting with the order creation process
|
||||||
|
var orderStartedIntegrationEvent = new OrderStartedIntegrationEvent(eventMsg.UserId);
|
||||||
|
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStartedIntegrationEvent);
|
||||||
|
|
||||||
if (eventMsg.RequestId != Guid.Empty)
|
if (eventMsg.RequestId != Guid.Empty)
|
||||||
{
|
{
|
||||||
var createOrderCommand = new CreateOrderCommand(eventMsg.Basket.Items, eventMsg.UserId, eventMsg.City, eventMsg.Street,
|
var createOrderCommand = new CreateOrderCommand(eventMsg.Basket.Items, eventMsg.UserId, eventMsg.City, eventMsg.Street,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace SagaManager.IntegrationEvents.Events
|
namespace GracePeriodManager.IntegrationEvents.Events
|
||||||
{
|
{
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace SagaManager
|
namespace GracePeriodManager
|
||||||
{
|
{
|
||||||
public class SagaManagerSettings
|
public class ManagerSettings
|
||||||
{
|
{
|
||||||
public string ConnectionString { get; set; }
|
public string ConnectionString { get; set; }
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
namespace SagaManager
|
namespace GracePeriodManager
|
||||||
{
|
{
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System;
|
using System;
|
||||||
@ -31,14 +31,14 @@
|
|||||||
var logger = serviceProvider.GetService<ILoggerFactory>();
|
var logger = serviceProvider.GetService<ILoggerFactory>();
|
||||||
Configure(logger);
|
Configure(logger);
|
||||||
|
|
||||||
var sagaManagerService = serviceProvider
|
var gracePeriodManagerService = serviceProvider
|
||||||
.GetRequiredService<ISagaManagerService>();
|
.GetRequiredService<IManagerService>();
|
||||||
var checkUpdateTime = serviceProvider
|
var checkUpdateTime = serviceProvider
|
||||||
.GetRequiredService<IOptions<SagaManagerSettings>>().Value.CheckUpdateTime;
|
.GetRequiredService<IOptions<ManagerSettings>>().Value.CheckUpdateTime;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
sagaManagerService.CheckConfirmedGracePeriodOrders();
|
gracePeriodManagerService.CheckConfirmedGracePeriodOrders();
|
||||||
await Task.Delay(checkUpdateTime);
|
await Task.Delay(checkUpdateTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,11 +57,11 @@
|
|||||||
{
|
{
|
||||||
services.AddLogging()
|
services.AddLogging()
|
||||||
.AddOptions()
|
.AddOptions()
|
||||||
.Configure<SagaManagerSettings>(Configuration)
|
.Configure<ManagerSettings>(Configuration)
|
||||||
.AddSingleton<ISagaManagerService, SagaManagerService>()
|
.AddSingleton<IManagerService, ManagerService>()
|
||||||
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
||||||
{
|
{
|
||||||
var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value;
|
var settings = sp.GetRequiredService<IOptions<ManagerSettings>>().Value;
|
||||||
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
||||||
var factory = new ConnectionFactory()
|
var factory = new ConnectionFactory()
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace GracePeriodManager.Services
|
||||||
|
{
|
||||||
|
public interface IManagerService
|
||||||
|
{
|
||||||
|
void CheckConfirmedGracePeriodOrders();
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
namespace SagaManager.Services
|
|
||||||
{
|
|
||||||
public interface ISagaManagerService
|
|
||||||
{
|
|
||||||
void CheckConfirmedGracePeriodOrders();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,22 @@
|
|||||||
namespace SagaManager.Services
|
namespace GracePeriodManager.Services
|
||||||
{
|
{
|
||||||
|
using Dapper;
|
||||||
|
using GracePeriodManager.IntegrationEvents.Events;
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Dapper;
|
|
||||||
using IntegrationEvents.Events;
|
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
|
||||||
|
|
||||||
public class SagaManagerService : ISagaManagerService
|
public class ManagerService : IManagerService
|
||||||
{
|
{
|
||||||
private readonly SagaManagerSettings _settings;
|
private readonly ManagerSettings _settings;
|
||||||
private readonly IEventBus _eventBus;
|
private readonly IEventBus _eventBus;
|
||||||
private readonly ILogger<SagaManagerService> _logger;
|
private readonly ILogger<ManagerService> _logger;
|
||||||
|
|
||||||
public SagaManagerService(IOptions<SagaManagerSettings> settings,
|
public ManagerService(IOptions<ManagerSettings> settings,
|
||||||
IEventBus eventBus,
|
IEventBus eventBus,
|
||||||
ILogger<SagaManagerService> logger)
|
ILogger<ManagerService> logger)
|
||||||
{
|
{
|
||||||
_settings = settings.Value;
|
_settings = settings.Value;
|
||||||
_eventBus = eventBus;
|
_eventBus = eventBus;
|
||||||
@ -41,11 +41,11 @@
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.LogInformation("SagaManager Client is trying to connect to database server");
|
_logger.LogInformation("Grace Period Manager Client is trying to connect to database server");
|
||||||
conn.Open();
|
conn.Open();
|
||||||
orderIds = conn.Query<int>(
|
orderIds = conn.Query<int>(
|
||||||
@"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders]
|
@"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders]
|
||||||
WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriodTime
|
WHERE DATEDIFF(minute, [OrderDate], GETDATE()) >= @GracePeriodTime
|
||||||
AND [OrderStatusId] = 1",
|
AND [OrderStatusId] = 1",
|
||||||
new { GracePeriodTime = _settings.GracePeriodTime });
|
new { GracePeriodTime = _settings.GracePeriodTime });
|
||||||
}
|
}
|
@ -8,6 +8,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
||||||
"GracePeriodTime": "15",
|
"GracePeriodTime": "1",
|
||||||
"CheckUpdateTime": "30000"
|
"CheckUpdateTime": "30000"
|
||||||
}
|
}
|
||||||
|
@ -122,17 +122,6 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
|||||||
await UpdateBasket(basket);
|
await UpdateBasket(basket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CleanBasket(ApplicationUser user)
|
|
||||||
{
|
|
||||||
var token = await GetUserTokenAsync();
|
|
||||||
var cleanBasketUri = API.Basket.CleanBasket(_remoteServiceBaseUrl, user.Id);
|
|
||||||
|
|
||||||
var response = await _apiClient.DeleteAsync(cleanBasketUri, token);
|
|
||||||
|
|
||||||
//CCE: response status code...
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task<string> GetUserTokenAsync()
|
async Task<string> GetUserTokenAsync()
|
||||||
{
|
{
|
||||||
var context = _httpContextAccesor.HttpContext;
|
var context = _httpContextAccesor.HttpContext;
|
||||||
|
@ -15,6 +15,5 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
|
|||||||
Task Checkout(BasketDTO basket);
|
Task Checkout(BasketDTO basket);
|
||||||
Task<Basket> SetQuantities(ApplicationUser user, Dictionary<string, int> quantities);
|
Task<Basket> SetQuantities(ApplicationUser user, Dictionary<string, int> quantities);
|
||||||
Order MapBasketToOrder(Basket basket);
|
Order MapBasketToOrder(Basket basket);
|
||||||
Task CleanBasket(ApplicationUser user);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,6 @@ export class BasketService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.basketEvents.orderCreated$.subscribe(x => {
|
|
||||||
this.dropBasket();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addItemToBasket(item): Observable<boolean> {
|
addItemToBasket(item): Observable<boolean> {
|
||||||
@ -85,12 +81,6 @@ export class BasketService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dropBasket() {
|
|
||||||
this.basket.items = [];
|
|
||||||
this.service.delete(this.basketUrl + '/' + this.basket.buyerId);
|
|
||||||
this.basketDropedSource.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
mapBasketInfoCheckout(order: IOrder): IBasketCheckout {
|
mapBasketInfoCheckout(order: IOrder): IBasketCheckout {
|
||||||
let basketCheckout = <IBasketCheckout>{};
|
let basketCheckout = <IBasketCheckout>{};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user