Browse Source

TenantId added to all events in main flow

pull/1240/head
espent1004 5 years ago
parent
commit
f5f871fc94
8 changed files with 23 additions and 6 deletions
  1. +2
    -0
      src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs
  2. +4
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/SetStockConfirmedOrderStatusCommand.cs
  3. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/SetStockConfirmedOrderStatusCommandHandler.cs
  4. +2
    -0
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs
  5. +1
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs
  6. +2
    -2
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  7. +7
    -0
      src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToStockConfirmedDomainEvent.cs
  8. +4
    -1
      src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs

+ 2
- 0
src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/OrderStatusChangedToAwaitingValidationIntegrationEventHandler.cs View File

@ -49,6 +49,8 @@
? (IntegrationEvent)new OrderStockRejectedIntegrationEvent(@event.OrderId, confirmedOrderStockItems) ? (IntegrationEvent)new OrderStockRejectedIntegrationEvent(@event.OrderId, confirmedOrderStockItems)
: new OrderStockConfirmedIntegrationEvent(@event.OrderId); : new OrderStockConfirmedIntegrationEvent(@event.OrderId);
confirmedIntegrationEvent.TenantId = @event.TenantId;
await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent); await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent);
await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent); await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent);


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

@ -12,10 +12,13 @@ namespace Ordering.API.Application.Commands
[DataMember] [DataMember]
public int OrderNumber { get; private set; } public int OrderNumber { get; private set; }
[DataMember]
public int TenantId { get; private set; }
public SetStockConfirmedOrderStatusCommand(int orderNumber)
public SetStockConfirmedOrderStatusCommand(int orderNumber, int tenantId)
{ {
OrderNumber = orderNumber; OrderNumber = orderNumber;
TenantId = tenantId;
} }
} }
} }

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

@ -35,7 +35,7 @@ namespace Ordering.API.Application.Commands
return false; return false;
} }
orderToUpdate.SetStockConfirmedStatus();
orderToUpdate.SetStockConfirmedStatus(command.TenantId);
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }


+ 2
- 0
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs View File

@ -41,6 +41,8 @@
var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString()); var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString());
var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name);
orderStatusChangedToStockConfirmedIntegrationEvent.TenantId =
orderStatusChangedToStockConfirmedDomainEvent.TenantId;
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToStockConfirmedIntegrationEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToStockConfirmedIntegrationEvent);
} }
} }

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

@ -33,7 +33,7 @@
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId);
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId, @event.TenantId);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",


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

@ -114,11 +114,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
} }
} }
public void SetStockConfirmedStatus()
public void SetStockConfirmedStatus(int tenantId)
{ {
if (_orderStatusId == OrderStatus.AwaitingValidation.Id) if (_orderStatusId == OrderStatus.AwaitingValidation.Id)
{ {
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id));
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id).withTenantId(tenantId));
_orderStatusId = OrderStatus.StockConfirmed.Id; _orderStatusId = OrderStatus.StockConfirmed.Id;
_description = "All the items were confirmed with available stock."; _description = "All the items were confirmed with available stock.";


+ 7
- 0
src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToStockConfirmedDomainEvent.cs View File

@ -9,8 +9,15 @@
: INotification : INotification
{ {
public int OrderId { get; } public int OrderId { get; }
public int TenantId { get; set; }
public OrderStatusChangedToStockConfirmedDomainEvent(int orderId) public OrderStatusChangedToStockConfirmedDomainEvent(int orderId)
=> OrderId = orderId; => OrderId = orderId;
public OrderStatusChangedToStockConfirmedDomainEvent withTenantId(int tenantId)
{
this.TenantId = tenantId;
return this;
}
} }
} }

+ 4
- 1
src/Services/Payment/Payment.API/IntegrationEvents/EventHandling/OrderStatusChangedToStockConfirmedIntegrationEventHandler.cs View File

@ -1,4 +1,6 @@
namespace Payment.API.IntegrationEvents.EventHandling
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
namespace Payment.API.IntegrationEvents.EventHandling
{ {
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
@ -50,6 +52,7 @@
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
} }
orderPaymentIntegrationEvent.TenantId = @event.TenantId;
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent); _logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, Program.AppName, orderPaymentIntegrationEvent);
_eventBus.Publish(orderPaymentIntegrationEvent); _eventBus.Publish(orderPaymentIntegrationEvent);


Loading…
Cancel
Save