Browse Source

Fix issue identityService.getuseridentity fails when called from integration event

pull/223/head
Ramón Tomás 7 years ago
parent
commit
f302316cb0
8 changed files with 27 additions and 21 deletions
  1. +5
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs
  2. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  3. +3
    -3
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs
  4. +1
    -2
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/UserCheckoutAcceptedIntegrationEventHandler.cs
  5. +7
    -8
      src/Services/Ordering/Ordering.API/Startup.cs
  6. +4
    -4
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  7. +3
    -1
      src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs
  8. +3
    -1
      src/Web/WebMVC/Services/OrderingService.cs

+ 5
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs View File

@ -23,6 +23,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
[DataMember] [DataMember]
private readonly List<OrderItemDTO> _orderItems; private readonly List<OrderItemDTO> _orderItems;
[DataMember]
public string UserId { get; private set; }
[DataMember] [DataMember]
public string City { get; private set; } public string City { get; private set; }
@ -61,11 +64,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
_orderItems = new List<OrderItemDTO>(); _orderItems = new List<OrderItemDTO>();
} }
public CreateOrderCommand(List<BasketItem> basketItems, string city, string street, string state, string country, string zipcode,
public CreateOrderCommand(List<BasketItem> basketItems, string userId, string city, string street, string state, string country, string zipcode,
string cardNumber, string cardHolderName, DateTime cardExpiration, string cardNumber, string cardHolderName, DateTime cardExpiration,
string cardSecurityNumber, int cardTypeId) : this() string cardSecurityNumber, int cardTypeId) : this()
{ {
_orderItems = MapToOrderItems(basketItems); _orderItems = MapToOrderItems(basketItems);
UserId = userId;
City = city; City = city;
Street = street; Street = street;
State = state; State = state;


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -42,7 +42,7 @@
// methods and constructor so validations, invariants and business logic // methods and constructor so validations, invariants and business logic
// make sure that consistency is preserved across the whole aggregate // make sure that consistency is preserved across the whole aggregate
var address = new Address(message.Street, message.City, message.State, message.Country, message.ZipCode); var address = new Address(message.Street, message.City, message.State, message.Country, message.ZipCode);
var order = new Order(address , message.CardTypeId, message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration);
var order = new Order(message.UserId, address, message.CardTypeId, message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration);
order.SetOrderStatusId(OrderStatus.Submited.Id); order.SetOrderStatusId(OrderStatus.Submited.Id);
foreach (var item in message.OrderItems) foreach (var item in message.OrderItems)
{ {


+ 3
- 3
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs View File

@ -26,14 +26,14 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent
{ {
var cardTypeId = (orderStartedEvent.CardTypeId != 0) ? orderStartedEvent.CardTypeId : 1; var cardTypeId = (orderStartedEvent.CardTypeId != 0) ? orderStartedEvent.CardTypeId : 1;
var userGuid = _identityService.GetUserIdentity();
//var userGuid = _identityService.GetUserIdentity();
var buyer = await _buyerRepository.FindAsync(userGuid);
var buyer = await _buyerRepository.FindAsync(orderStartedEvent.UserId);
bool buyerOriginallyExisted = (buyer == null) ? false : true; bool buyerOriginallyExisted = (buyer == null) ? false : true;
if (!buyerOriginallyExisted) if (!buyerOriginallyExisted)
{ {
buyer = new Buyer(userGuid);
buyer = new Buyer(orderStartedEvent.UserId);
} }
buyer.VerifyOrAddPaymentMethod(cardTypeId, buyer.VerifyOrAddPaymentMethod(cardTypeId,


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

@ -14,7 +14,6 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
public UserCheckoutAcceptedIntegrationEventHandler(IMediator mediator, public UserCheckoutAcceptedIntegrationEventHandler(IMediator mediator,
IOrderingIntegrationEventService orderingIntegrationEventService,
ILoggerFactory logger) ILoggerFactory logger)
{ {
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
@ -35,7 +34,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
var result = false; var result = false;
if (eventMsg.RequestId != Guid.Empty) if (eventMsg.RequestId != Guid.Empty)
{ {
var createOrderCommand = new CreateOrderCommand(eventMsg.Basket.Items, eventMsg.City, eventMsg.Street,
var createOrderCommand = new CreateOrderCommand(eventMsg.Basket.Items, eventMsg.UserId, eventMsg.City, eventMsg.Street,
eventMsg.State, eventMsg.Country, eventMsg.ZipCode, eventMsg.State, eventMsg.Country, eventMsg.ZipCode,
eventMsg.CardNumber, eventMsg.CardHolderName, eventMsg.CardExpiration, eventMsg.CardNumber, eventMsg.CardHolderName, eventMsg.CardExpiration,
eventMsg.CardSecurityNumber, eventMsg.CardTypeId); eventMsg.CardSecurityNumber, eventMsg.CardTypeId);


+ 7
- 8
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -125,13 +125,12 @@
return new DefaultRabbitMQPersistentConnection(factory, logger); return new DefaultRabbitMQPersistentConnection(factory, logger);
}); });
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddSingleton<IEventBus, EventBusRabbitMQ>(); services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddTransient<IIntegrationEventHandler, UserCheckoutAcceptedIntegrationEventHandler>();
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>(); services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
services.AddTransient<OrderStockConfirmedIntegrationEventHandler>();
services.AddTransient<OrderStockNotConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
services.AddOptions(); services.AddOptions();
//configure autofac //configure autofac
@ -176,13 +175,13 @@
{ {
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent,IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>(); eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>();
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, OrderStockConfirmedIntegrationEventHandler>();
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, OrderStockNotConfirmedIntegrationEventHandler>();
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
} }
protected virtual void ConfigureAuth(IApplicationBuilder app) protected virtual void ConfigureAuth(IApplicationBuilder app)


+ 4
- 4
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -40,7 +40,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
protected Order() { _orderItems = new List<OrderItem>(); } protected Order() { _orderItems = new List<OrderItem>(); }
public Order(Address address, int cardTypeId, string cardNumber, string cardSecurityNumber,
public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber,
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null) string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null)
{ {
_orderItems = new List<OrderItem>(); _orderItems = new List<OrderItem>();
@ -52,7 +52,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
// Add the OrderStarterDomainEvent to the domain events collection // Add the OrderStarterDomainEvent to the domain events collection
// to be raised/dispatched when comitting changes into the Database [ After DbContext.SaveChanges() ] // to be raised/dispatched when comitting changes into the Database [ After DbContext.SaveChanges() ]
AddOrderStartedDomainEvent(cardTypeId, cardNumber,
AddOrderStartedDomainEvent(userId, cardTypeId, cardNumber,
cardSecurityNumber, cardHolderName, cardExpiration); cardSecurityNumber, cardHolderName, cardExpiration);
} }
@ -113,11 +113,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
} }
} }
private void AddOrderStartedDomainEvent(int cardTypeId, string cardNumber,
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber,
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration) string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
{ {
var orderStartedDomainEvent = new OrderStartedDomainEvent( var orderStartedDomainEvent = new OrderStartedDomainEvent(
this, cardTypeId, cardNumber, cardSecurityNumber,
this, userId, cardTypeId, cardNumber, cardSecurityNumber,
cardHolderName, cardExpiration); cardHolderName, cardExpiration);
this.AddDomainEvent(orderStartedDomainEvent); this.AddDomainEvent(orderStartedDomainEvent);


+ 3
- 1
src/Services/Ordering/Ordering.Domain/Events/OrderStartedDomainEvent.cs View File

@ -12,6 +12,7 @@ namespace Ordering.Domain.Events
public class OrderStartedDomainEvent public class OrderStartedDomainEvent
: IAsyncNotification : IAsyncNotification
{ {
public string UserId { get; private set; }
public int CardTypeId { get; private set; } public int CardTypeId { get; private set; }
public string CardNumber { get; private set; } public string CardNumber { get; private set; }
public string CardSecurityNumber { get; private set; } public string CardSecurityNumber { get; private set; }
@ -19,12 +20,13 @@ namespace Ordering.Domain.Events
public DateTime CardExpiration { get; private set; } public DateTime CardExpiration { get; private set; }
public Order Order { get; private set; } public Order Order { get; private set; }
public OrderStartedDomainEvent(Order order,
public OrderStartedDomainEvent(Order order, string userId,
int cardTypeId, string cardNumber, int cardTypeId, string cardNumber,
string cardSecurityNumber, string cardHolderName, string cardSecurityNumber, string cardHolderName,
DateTime cardExpiration) DateTime cardExpiration)
{ {
Order = order; Order = order;
UserId = userId;
CardTypeId = cardTypeId; CardTypeId = cardTypeId;
CardNumber = cardNumber; CardNumber = cardNumber;
CardSecurityNumber = cardSecurityNumber; CardSecurityNumber = cardSecurityNumber;


+ 3
- 1
src/Web/WebMVC/Services/OrderingService.cs View File

@ -98,6 +98,8 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
public BasketDTO MapOrderToBasket(Order order) public BasketDTO MapOrderToBasket(Order order)
{ {
order.CardExpirationApiFormat();
return new BasketDTO() return new BasketDTO()
{ {
City = order.City, City = order.City,
@ -109,7 +111,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Services
CardHolderName = order.CardHolderName, CardHolderName = order.CardHolderName,
CardExpiration = order.CardExpiration, CardExpiration = order.CardExpiration,
CardSecurityNumber = order.CardSecurityNumber, CardSecurityNumber = order.CardSecurityNumber,
CardTypeId = order.CardTypeId,
CardTypeId = 1,
Buyer = order.Buyer, Buyer = order.Buyer,
RequestId = order.RequestId RequestId = order.RequestId
}; };


Loading…
Cancel
Save