Browse Source

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
pull/809/head
Ramón Tomás 7 years ago
parent
commit
8c2af8c048
14 changed files with 50 additions and 72 deletions
  1. +3
    -3
      eShopOnContainers-ServicesAndWebApps.sln
  2. +4
    -11
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs
  3. +9
    -2
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs
  4. +0
    -0
      src/Services/SagaManager/SagaManager/GracePeriodManager.csproj
  5. +1
    -1
      src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs
  6. +2
    -2
      src/Services/SagaManager/SagaManager/ManagerSettings.cs
  7. +8
    -8
      src/Services/SagaManager/SagaManager/Program.cs
  8. +7
    -0
      src/Services/SagaManager/SagaManager/Services/IManagerService.cs
  9. +0
    -7
      src/Services/SagaManager/SagaManager/Services/ISagaManagerService.cs
  10. +13
    -13
      src/Services/SagaManager/SagaManager/Services/ManagerService.cs
  11. +1
    -1
      src/Services/SagaManager/SagaManager/appsettings.json
  12. +1
    -12
      src/Web/WebMVC/Services/BasketService.cs
  13. +0
    -1
      src/Web/WebMVC/Services/IBasketService.cs
  14. +1
    -11
      src/Web/WebSPA/Client/modules/basket/basket.service.ts

+ 3
- 3
eShopOnContainers-ServicesAndWebApps.sln View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.3
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
EndProject
@ -80,9 +80,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Health
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventBus.Tests", "src\BuildingBlocks\EventBus\EventBus.Tests\EventBus.Tests.csproj", "{4A980AC4-7205-46BF-8CCB-09E44D700FD4}"
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
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution


+ 4
- 11
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs View File

@ -12,16 +12,13 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri
public class UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler
: IAsyncNotificationHandler<BuyerAndPaymentMethodVerifiedDomainEvent>
{
private readonly IOrderRepository _orderRepository;
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
private readonly IOrderRepository _orderRepository;
private readonly ILoggerFactory _logger;
public UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler(
IOrderRepository orderRepository, ILoggerFactory logger,
IOrderingIntegrationEventService orderingIntegrationEventService)
IOrderRepository orderRepository, ILoggerFactory logger)
{
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
_orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService));
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@ -32,11 +29,7 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri
{
var orderToUpdate = await _orderRepository.GetAsync(buyerPaymentMethodVerifiedEvent.OrderId);
orderToUpdate.SetBuyerId(buyerPaymentMethodVerifiedEvent.Buyer.Id);
orderToUpdate.SetPaymentId(buyerPaymentMethodVerifiedEvent.Payment.Id);
var orderStartedIntegrationEvent = new OrderStartedIntegrationEvent(buyerPaymentMethodVerifiedEvent.Buyer.IdentityGuid);
await _orderingIntegrationEventService.PublishThroughEventBusAsync(orderStartedIntegrationEvent);
orderToUpdate.SetPaymentId(buyerPaymentMethodVerifiedEvent.Payment.Id);
_logger.CreateLogger(nameof(UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler))
.LogTrace($"Order with Id: {buyerPaymentMethodVerifiedEvent.OrderId} has been successfully updated with a payment method id: { buyerPaymentMethodVerifiedEvent.Payment.Id }");


+ 9
- 2
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs View File

@ -12,12 +12,14 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
{
private readonly IMediator _mediator;
private readonly ILoggerFactory _logger;
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
public UserCheckoutAcceptedIntegrationEventHandler(IMediator mediator,
ILoggerFactory logger)
ILoggerFactory logger, IOrderingIntegrationEventService orderingIntegrationEventService)
{
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService));
}
/// <summary>
@ -32,6 +34,11 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public async Task Handle(UserCheckoutAcceptedIntegrationEvent eventMsg)
{
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)
{
var createOrderCommand = new CreateOrderCommand(eventMsg.Basket.Items, eventMsg.UserId, eventMsg.City, eventMsg.Street,
@ -41,7 +48,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, eventMsg.RequestId);
result = await _mediator.SendAsync(requestCreateOrder);
}
}
_logger.CreateLogger(nameof(UserCheckoutAcceptedIntegrationEventHandler))
.LogTrace(result ? $"UserCheckoutAccepted integration event has been received and a create new order process is started with requestId: {eventMsg.RequestId}" :


src/Services/SagaManager/SagaManager/SagaManager.csproj → src/Services/SagaManager/SagaManager/GracePeriodManager.csproj View File


+ 1
- 1
src/Services/SagaManager/SagaManager/IntegrationEvents/Events/GracePeriodConfirmedIntegrationEvent.cs View File

@ -1,4 +1,4 @@
namespace SagaManager.IntegrationEvents.Events
namespace GracePeriodManager.IntegrationEvents.Events
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;


src/Services/SagaManager/SagaManager/SagaManagerSettings.cs → src/Services/SagaManager/SagaManager/ManagerSettings.cs View File

@ -1,6 +1,6 @@
namespace SagaManager
namespace GracePeriodManager
{
public class SagaManagerSettings
public class ManagerSettings
{
public string ConnectionString { get; set; }

+ 8
- 8
src/Services/SagaManager/SagaManager/Program.cs View File

@ -1,4 +1,4 @@
namespace SagaManager
namespace GracePeriodManager
{
using System.IO;
using System;
@ -31,14 +31,14 @@
var logger = serviceProvider.GetService<ILoggerFactory>();
Configure(logger);
var sagaManagerService = serviceProvider
.GetRequiredService<ISagaManagerService>();
var gracePeriodManagerService = serviceProvider
.GetRequiredService<IManagerService>();
var checkUpdateTime = serviceProvider
.GetRequiredService<IOptions<SagaManagerSettings>>().Value.CheckUpdateTime;
.GetRequiredService<IOptions<ManagerSettings>>().Value.CheckUpdateTime;
while (true)
{
sagaManagerService.CheckConfirmedGracePeriodOrders();
gracePeriodManagerService.CheckConfirmedGracePeriodOrders();
await Task.Delay(checkUpdateTime);
}
}
@ -57,11 +57,11 @@
{
services.AddLogging()
.AddOptions()
.Configure<SagaManagerSettings>(Configuration)
.AddSingleton<ISagaManagerService, SagaManagerService>()
.Configure<ManagerSettings>(Configuration)
.AddSingleton<IManagerService, ManagerService>()
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value;
var settings = sp.GetRequiredService<IOptions<ManagerSettings>>().Value;
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
var factory = new ConnectionFactory()
{


+ 7
- 0
src/Services/SagaManager/SagaManager/Services/IManagerService.cs View File

@ -0,0 +1,7 @@
namespace GracePeriodManager.Services
{
public interface IManagerService
{
void CheckConfirmedGracePeriodOrders();
}
}

+ 0
- 7
src/Services/SagaManager/SagaManager/Services/ISagaManagerService.cs View File

@ -1,7 +0,0 @@
namespace SagaManager.Services
{
public interface ISagaManagerService
{
void CheckConfirmedGracePeriodOrders();
}
}

src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs → src/Services/SagaManager/SagaManager/Services/ManagerService.cs View File

@ -1,22 +1,22 @@
namespace SagaManager.Services
namespace GracePeriodManager.Services
{
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Dapper;
using IntegrationEvents.Events;
using GracePeriodManager.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Data.SqlClient;
public class SagaManagerService : ISagaManagerService
public class ManagerService : IManagerService
{
private readonly SagaManagerSettings _settings;
private readonly ManagerSettings _settings;
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,
ILogger<SagaManagerService> logger)
ILogger<ManagerService> logger)
{
_settings = settings.Value;
_eventBus = eventBus;
@ -41,11 +41,11 @@
{
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();
orderIds = conn.Query<int>(
@"SELECT Id FROM [Microsoft.eShopOnContainers.Services.OrderingDb].[ordering].[orders]
WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriodTime
WHERE DATEDIFF(minute, [OrderDate], GETDATE()) >= @GracePeriodTime
AND [OrderStatusId] = 1",
new { GracePeriodTime = _settings.GracePeriodTime });
}

+ 1
- 1
src/Services/SagaManager/SagaManager/appsettings.json View File

@ -8,6 +8,6 @@
}
},
"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"
}

+ 1
- 12
src/Web/WebMVC/Services/BasketService.cs View File

@ -120,18 +120,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
basket.Items.Add(product);
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()
{


+ 0
- 1
src/Web/WebMVC/Services/IBasketService.cs View File

@ -15,6 +15,5 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
Task Checkout(BasketDTO basket);
Task<Basket> SetQuantities(ApplicationUser user, Dictionary<string, int> quantities);
Order MapBasketToOrder(Basket basket);
Task CleanBasket(ApplicationUser user);
}
}

+ 1
- 11
src/Web/WebSPA/Client/modules/basket/basket.service.ts View File

@ -51,10 +51,6 @@ export class BasketService {
}
}
}
this.basketEvents.orderCreated$.subscribe(x => {
this.dropBasket();
});
}
addItemToBasket(item): Observable<boolean> {
@ -83,13 +79,7 @@ export class BasketService {
return response.json();
});
}
dropBasket() {
this.basket.items = [];
this.service.delete(this.basketUrl + '/' + this.basket.buyerId);
this.basketDropedSource.next();
}
}
mapBasketInfoCheckout(order: IOrder): IBasketCheckout {
let basketCheckout = <IBasketCheckout>{};


Loading…
Cancel
Save