Moved all usings to globalusing file

This commit is contained in:
Sumit Ghosh 2021-10-12 17:34:41 +05:30
parent 818995d8b8
commit 666fba815f
77 changed files with 2458 additions and 3026 deletions

View File

@ -1,13 +1,6 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Behaviors;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Behaviors
{ {
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger; private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger;
public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger) => _logger = logger; public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger) => _logger = logger;
@ -19,5 +12,5 @@ namespace Ordering.API.Application.Behaviors
return response; return response;
} }
}
} }

View File

@ -1,18 +1,9 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Behaviors;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Serilog.Context;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Behaviors using Microsoft.Extensions.Logging;
public class TransactionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{ {
public class TransactionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly ILogger<TransactionBehaviour<TRequest, TResponse>> _logger; private readonly ILogger<TransactionBehaviour<TRequest, TResponse>> _logger;
private readonly OrderingContext _dbContext; private readonly OrderingContext _dbContext;
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
@ -70,5 +61,4 @@ namespace Ordering.API.Application.Behaviors
throw; throw;
} }
} }
}
} }

View File

@ -1,16 +1,7 @@
using FluentValidation; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Behaviors;
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.Domain.Exceptions;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Behaviors public class ValidatorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{ {
public class ValidatorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly ILogger<ValidatorBehavior<TRequest, TResponse>> _logger; private readonly ILogger<ValidatorBehavior<TRequest, TResponse>> _logger;
private readonly IValidator<TRequest>[] _validators; private readonly IValidator<TRequest>[] _validators;
@ -42,5 +33,4 @@ namespace Ordering.API.Application.Behaviors
return await next(); return await next();
} }
}
} }

View File

@ -1,10 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System.Runtime.Serialization;
namespace Ordering.API.Application.Commands public class CancelOrderCommand : IRequest<bool>
{ {
public class CancelOrderCommand : IRequest<bool>
{
[DataMember] [DataMember]
public int OrderNumber { get; set; } public int OrderNumber { get; set; }
@ -16,5 +13,4 @@ namespace Ordering.API.Application.Commands
{ {
OrderNumber = orderNumber; OrderNumber = orderNumber;
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Commands // Regular CommandHandler
public class CancelOrderCommandHandler : IRequestHandler<CancelOrderCommand, bool>
{ {
// Regular CommandHandler
public class CancelOrderCommandHandler : IRequestHandler<CancelOrderCommand, bool>
{
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public CancelOrderCommandHandler(IOrderRepository orderRepository) public CancelOrderCommandHandler(IOrderRepository orderRepository)
@ -35,12 +27,12 @@ namespace Ordering.API.Application.Commands
orderToUpdate.SetCancelledStatus(); orderToUpdate.SetCancelledStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class CancelOrderIdentifiedCommandHandler : IdentifiedCommandHandler<CancelOrderCommand, bool> public class CancelOrderIdentifiedCommandHandler : IdentifiedCommandHandler<CancelOrderCommand, bool>
{ {
public CancelOrderIdentifiedCommandHandler( public CancelOrderIdentifiedCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -53,5 +45,4 @@ namespace Ordering.API.Application.Commands
{ {
return true; // Ignore duplicate requests for processing order. return true; // Ignore duplicate requests for processing order.
} }
}
} }

View File

@ -1,25 +1,20 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Ordering.API.Application.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands // DDD and CQRS patterns comment: Note that it is recommended to implement immutable Commands
{ // In this case, its immutability is achieved by having all the setters as private
// DDD and CQRS patterns comment: Note that it is recommended to implement immutable Commands // plus only being able to update the data just once, when creating the object through its constructor.
// In this case, its immutability is achieved by having all the setters as private // References on Immutable Commands:
// plus only being able to update the data just once, when creating the object through its constructor. // http://cqrs.nu/Faq
// References on Immutable Commands: // https://docs.spine3.org/motivation/immutability.html
// http://cqrs.nu/Faq // http://blog.gauffin.org/2012/06/griffin-container-introducing-command-support/
// https://docs.spine3.org/motivation/immutability.html // https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/how-to-implement-a-lightweight-class-with-auto-implemented-properties
// http://blog.gauffin.org/2012/06/griffin-container-introducing-command-support/
// https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/how-to-implement-a-lightweight-class-with-auto-implemented-properties
[DataContract] using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
public class CreateOrderCommand
[DataContract]
public class CreateOrderCommand
: IRequest<bool> : IRequest<bool>
{ {
[DataMember] [DataMember]
private readonly List<OrderItemDTO> _orderItems; private readonly List<OrderItemDTO> _orderItems;
@ -102,5 +97,5 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
public string PictureUrl { get; init; } public string PictureUrl { get; init; }
} }
}
} }

View File

@ -1,20 +1,11 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
{
using Domain.AggregatesModel.OrderAggregate;
using global::Ordering.API.Application.IntegrationEvents;
using global::Ordering.API.Application.IntegrationEvents.Events;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
// Regular CommandHandler using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
public class CreateOrderCommandHandler
// Regular CommandHandler
public class CreateOrderCommandHandler
: IRequestHandler<CreateOrderCommand, bool> : IRequestHandler<CreateOrderCommand, bool>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly IIdentityService _identityService; private readonly IIdentityService _identityService;
private readonly IMediator _mediator; private readonly IMediator _mediator;
@ -60,12 +51,12 @@
return await _orderRepository.UnitOfWork return await _orderRepository.UnitOfWork
.SaveEntitiesAsync(cancellationToken); .SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class CreateOrderIdentifiedCommandHandler : IdentifiedCommandHandler<CreateOrderCommand, bool> public class CreateOrderIdentifiedCommandHandler : IdentifiedCommandHandler<CreateOrderCommand, bool>
{ {
public CreateOrderIdentifiedCommandHandler( public CreateOrderIdentifiedCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -78,5 +69,4 @@
{ {
return true; // Ignore duplicate requests for creating order. return true; // Ignore duplicate requests for creating order.
} }
}
} }

View File

@ -1,11 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Ordering.API.Application.Models; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
using System.Collections.Generic;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands public class CreateOrderDraftCommand : IRequest<OrderDraftDTO>
{ {
public class CreateOrderDraftCommand : IRequest<OrderDraftDTO>
{
public string BuyerId { get; private set; } public string BuyerId { get; private set; }
@ -16,6 +13,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
BuyerId = buyerId; BuyerId = buyerId;
Items = items; Items = items;
} }
}
} }

View File

@ -1,20 +1,12 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
{
using Domain.AggregatesModel.OrderAggregate;
using global::Ordering.API.Application.Models;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
// Regular CommandHandler using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
public class CreateOrderDraftCommandHandler using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
// Regular CommandHandler
public class CreateOrderDraftCommandHandler
: IRequestHandler<CreateOrderDraftCommand, OrderDraftDTO> : IRequestHandler<CreateOrderDraftCommand, OrderDraftDTO>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly IIdentityService _identityService; private readonly IIdentityService _identityService;
private readonly IMediator _mediator; private readonly IMediator _mediator;
@ -38,11 +30,11 @@
return Task.FromResult(OrderDraftDTO.FromOrder(order)); return Task.FromResult(OrderDraftDTO.FromOrder(order));
} }
} }
public record OrderDraftDTO public record OrderDraftDTO
{ {
public IEnumerable<OrderItemDTO> OrderItems { get; init; } public IEnumerable<OrderItemDTO> OrderItems { get; init; }
public decimal Total { get; init; } public decimal Total { get; init; }
@ -63,9 +55,4 @@
}; };
} }
}
} }

View File

@ -1,11 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands public class IdentifiedCommand<T, R> : IRequest<R>
{
public class IdentifiedCommand<T, R> : IRequest<R>
where T : IRequest<R> where T : IRequest<R>
{ {
public T Command { get; } public T Command { get; }
public Guid Id { get; } public Guid Id { get; }
public IdentifiedCommand(T command, Guid id) public IdentifiedCommand(T command, Guid id)
@ -13,5 +10,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
Command = command; Command = command;
Id = id; Id = id;
} }
}
} }

View File

@ -1,22 +1,14 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands /// <summary>
{ /// Provides a base implementation for handling duplicate request and ensuring idempotent updates, in the cases where
/// <summary> /// a requestid sent by client is used to detect duplicate requests.
/// Provides a base implementation for handling duplicate request and ensuring idempotent updates, in the cases where /// </summary>
/// a requestid sent by client is used to detect duplicate requests. /// <typeparam name="T">Type of the command handler that performs the operation if request is not duplicated</typeparam>
/// </summary> /// <typeparam name="R">Return value of the inner command handler</typeparam>
/// <typeparam name="T">Type of the command handler that performs the operation if request is not duplicated</typeparam> public class IdentifiedCommandHandler<T, R> : IRequestHandler<IdentifiedCommand<T, R>, R>
/// <typeparam name="R">Return value of the inner command handler</typeparam>
public class IdentifiedCommandHandler<T, R> : IRequestHandler<IdentifiedCommand<T, R>, R>
where T : IRequest<R> where T : IRequest<R>
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IRequestManager _requestManager; private readonly IRequestManager _requestManager;
private readonly ILogger<IdentifiedCommandHandler<T, R>> _logger; private readonly ILogger<IdentifiedCommandHandler<T, R>> _logger;
@ -112,5 +104,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
} }
} }
} }
}
} }

View File

@ -1,10 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System.Runtime.Serialization;
namespace Ordering.API.Application.Commands public class SetAwaitingValidationOrderStatusCommand : IRequest<bool>
{ {
public class SetAwaitingValidationOrderStatusCommand : IRequest<bool>
{
[DataMember] [DataMember]
public int OrderNumber { get; private set; } public int OrderNumber { get; private set; }
@ -13,5 +10,4 @@ namespace Ordering.API.Application.Commands
{ {
OrderNumber = orderNumber; OrderNumber = orderNumber;
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Commands // Regular CommandHandler
public class SetAwaitingValidationOrderStatusCommandHandler : IRequestHandler<SetAwaitingValidationOrderStatusCommand, bool>
{ {
// Regular CommandHandler
public class SetAwaitingValidationOrderStatusCommandHandler : IRequestHandler<SetAwaitingValidationOrderStatusCommand, bool>
{
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public SetAwaitingValidationOrderStatusCommandHandler(IOrderRepository orderRepository) public SetAwaitingValidationOrderStatusCommandHandler(IOrderRepository orderRepository)
@ -35,12 +27,12 @@ namespace Ordering.API.Application.Commands
orderToUpdate.SetAwaitingValidationStatus(); orderToUpdate.SetAwaitingValidationStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class SetAwaitingValidationIdentifiedOrderStatusCommandHandler : IdentifiedCommandHandler<SetAwaitingValidationOrderStatusCommand, bool> public class SetAwaitingValidationIdentifiedOrderStatusCommandHandler : IdentifiedCommandHandler<SetAwaitingValidationOrderStatusCommand, bool>
{ {
public SetAwaitingValidationIdentifiedOrderStatusCommandHandler( public SetAwaitingValidationIdentifiedOrderStatusCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -53,5 +45,4 @@ namespace Ordering.API.Application.Commands
{ {
return true; // Ignore duplicate requests for processing order. return true; // Ignore duplicate requests for processing order.
} }
}
} }

View File

@ -1,10 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System.Runtime.Serialization;
namespace Ordering.API.Application.Commands public class SetPaidOrderStatusCommand : IRequest<bool>
{ {
public class SetPaidOrderStatusCommand : IRequest<bool>
{
[DataMember] [DataMember]
public int OrderNumber { get; private set; } public int OrderNumber { get; private set; }
@ -13,5 +10,4 @@ namespace Ordering.API.Application.Commands
{ {
OrderNumber = orderNumber; OrderNumber = orderNumber;
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Commands // Regular CommandHandler
public class SetPaidOrderStatusCommandHandler : IRequestHandler<SetPaidOrderStatusCommand, bool>
{ {
// Regular CommandHandler
public class SetPaidOrderStatusCommandHandler : IRequestHandler<SetPaidOrderStatusCommand, bool>
{
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public SetPaidOrderStatusCommandHandler(IOrderRepository orderRepository) public SetPaidOrderStatusCommandHandler(IOrderRepository orderRepository)
@ -38,12 +30,12 @@ namespace Ordering.API.Application.Commands
orderToUpdate.SetPaidStatus(); orderToUpdate.SetPaidStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class SetPaidIdentifiedOrderStatusCommandHandler : IdentifiedCommandHandler<SetPaidOrderStatusCommand, bool> public class SetPaidIdentifiedOrderStatusCommandHandler : IdentifiedCommandHandler<SetPaidOrderStatusCommand, bool>
{ {
public SetPaidIdentifiedOrderStatusCommandHandler( public SetPaidIdentifiedOrderStatusCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -56,5 +48,4 @@ namespace Ordering.API.Application.Commands
{ {
return true; // Ignore duplicate requests for processing order. return true; // Ignore duplicate requests for processing order.
} }
}
} }

View File

@ -1,10 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System.Runtime.Serialization;
namespace Ordering.API.Application.Commands public class SetStockConfirmedOrderStatusCommand : IRequest<bool>
{ {
public class SetStockConfirmedOrderStatusCommand : IRequest<bool>
{
[DataMember] [DataMember]
public int OrderNumber { get; private set; } public int OrderNumber { get; private set; }
@ -13,5 +10,4 @@ namespace Ordering.API.Application.Commands
{ {
OrderNumber = orderNumber; OrderNumber = orderNumber;
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Commands // Regular CommandHandler
public class SetStockConfirmedOrderStatusCommandHandler : IRequestHandler<SetStockConfirmedOrderStatusCommand, bool>
{ {
// Regular CommandHandler
public class SetStockConfirmedOrderStatusCommandHandler : IRequestHandler<SetStockConfirmedOrderStatusCommand, bool>
{
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public SetStockConfirmedOrderStatusCommandHandler(IOrderRepository orderRepository) public SetStockConfirmedOrderStatusCommandHandler(IOrderRepository orderRepository)
@ -38,12 +30,12 @@ namespace Ordering.API.Application.Commands
orderToUpdate.SetStockConfirmedStatus(); orderToUpdate.SetStockConfirmedStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class SetStockConfirmedOrderStatusIdenfifiedCommandHandler : IdentifiedCommandHandler<SetStockConfirmedOrderStatusCommand, bool> public class SetStockConfirmedOrderStatusIdenfifiedCommandHandler : IdentifiedCommandHandler<SetStockConfirmedOrderStatusCommand, bool>
{ {
public SetStockConfirmedOrderStatusIdenfifiedCommandHandler( public SetStockConfirmedOrderStatusIdenfifiedCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -56,5 +48,4 @@ namespace Ordering.API.Application.Commands
{ {
return true; // Ignore duplicate requests for processing order. return true; // Ignore duplicate requests for processing order.
} }
}
} }

View File

@ -1,11 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Ordering.API.Application.Commands public class SetStockRejectedOrderStatusCommand : IRequest<bool>
{ {
public class SetStockRejectedOrderStatusCommand : IRequest<bool>
{
[DataMember] [DataMember]
public int OrderNumber { get; private set; } public int OrderNumber { get; private set; }
@ -18,5 +14,4 @@ namespace Ordering.API.Application.Commands
OrderNumber = orderNumber; OrderNumber = orderNumber;
OrderStockItems = orderStockItems; OrderStockItems = orderStockItems;
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Commands // Regular CommandHandler
public class SetStockRejectedOrderStatusCommandHandler : IRequestHandler<SetStockRejectedOrderStatusCommand, bool>
{ {
// Regular CommandHandler
public class SetStockRejectedOrderStatusCommandHandler : IRequestHandler<SetStockRejectedOrderStatusCommand, bool>
{
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public SetStockRejectedOrderStatusCommandHandler(IOrderRepository orderRepository) public SetStockRejectedOrderStatusCommandHandler(IOrderRepository orderRepository)
@ -39,12 +31,12 @@ namespace Ordering.API.Application.Commands
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class SetStockRejectedOrderStatusIdenfifiedCommandHandler : IdentifiedCommandHandler<SetStockRejectedOrderStatusCommand, bool> public class SetStockRejectedOrderStatusIdenfifiedCommandHandler : IdentifiedCommandHandler<SetStockRejectedOrderStatusCommand, bool>
{ {
public SetStockRejectedOrderStatusIdenfifiedCommandHandler( public SetStockRejectedOrderStatusIdenfifiedCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -57,5 +49,4 @@ namespace Ordering.API.Application.Commands
{ {
return true; // Ignore duplicate requests for processing order. return true; // Ignore duplicate requests for processing order.
} }
}
} }

View File

@ -1,10 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using System.Runtime.Serialization;
namespace Ordering.API.Application.Commands public class ShipOrderCommand : IRequest<bool>
{ {
public class ShipOrderCommand : IRequest<bool>
{
[DataMember] [DataMember]
public int OrderNumber { get; private set; } public int OrderNumber { get; private set; }
@ -13,5 +10,4 @@ namespace Ordering.API.Application.Commands
{ {
OrderNumber = orderNumber; OrderNumber = orderNumber;
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.Commands // Regular CommandHandler
public class ShipOrderCommandHandler : IRequestHandler<ShipOrderCommand, bool>
{ {
// Regular CommandHandler
public class ShipOrderCommandHandler : IRequestHandler<ShipOrderCommand, bool>
{
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
public ShipOrderCommandHandler(IOrderRepository orderRepository) public ShipOrderCommandHandler(IOrderRepository orderRepository)
@ -35,12 +27,12 @@ namespace Ordering.API.Application.Commands
orderToUpdate.SetShippedStatus(); orderToUpdate.SetShippedStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken); return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
} }
} }
// Use for Idempotency in Command process // Use for Idempotency in Command process
public class ShipOrderIdentifiedCommandHandler : IdentifiedCommandHandler<ShipOrderCommand, bool> public class ShipOrderIdentifiedCommandHandler : IdentifiedCommandHandler<ShipOrderCommand, bool>
{ {
public ShipOrderIdentifiedCommandHandler( public ShipOrderIdentifiedCommandHandler(
IMediator mediator, IMediator mediator,
IRequestManager requestManager, IRequestManager requestManager,
@ -53,5 +45,4 @@ namespace Ordering.API.Application.Commands
{ {
return true; // Ignore duplicate requests for processing order. return true; // Ignore duplicate requests for processing order.
} }
}
} }

View File

@ -1,16 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVerified;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.Extensions.Logging;
using Ordering.Domain.Events;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVerified public class UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler
{
public class UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler
: INotificationHandler<BuyerAndPaymentMethodVerifiedDomainEvent> : INotificationHandler<BuyerAndPaymentMethodVerifiedDomainEvent>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
@ -34,5 +26,4 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri
.LogTrace("Order with Id: {OrderId} has been successfully updated with a payment method {PaymentMethod} ({Id})", .LogTrace("Order with Id: {OrderId} has been successfully updated with a payment method {PaymentMethod} ({Id})",
buyerPaymentMethodVerifiedEvent.OrderId, nameof(buyerPaymentMethodVerifiedEvent.Payment), buyerPaymentMethodVerifiedEvent.Payment.Id); buyerPaymentMethodVerifiedEvent.OrderId, nameof(buyerPaymentMethodVerifiedEvent.Payment), buyerPaymentMethodVerifiedEvent.Payment.Id);
} }
}
} }

View File

@ -1,19 +1,10 @@
using MediatR; using Microsoft.eShopOnContainers.Services.Ordering.Domain.Events;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Ordering.API.Application.IntegrationEvents.Events;
using Ordering.Domain.Events;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.DomainEventHandlers.OrderCancelled namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderCancelled;
{
public class OrderCancelledDomainEventHandler public class OrderCancelledDomainEventHandler
: INotificationHandler<OrderCancelledDomainEvent> : INotificationHandler<OrderCancelledDomainEvent>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly IBuyerRepository _buyerRepository; private readonly IBuyerRepository _buyerRepository;
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
@ -43,5 +34,4 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderCancelled
var orderStatusChangedToCancelledIntegrationEvent = new OrderStatusChangedToCancelledIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); var orderStatusChangedToCancelledIntegrationEvent = new OrderStatusChangedToCancelledIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name);
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToCancelledIntegrationEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToCancelledIntegrationEvent);
} }
}
} }

View File

@ -1,20 +1,8 @@
namespace Ordering.API.Application.DomainEventHandlers.OrderGracePeriodConfirmed namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderGracePeriodConfirmed;
{
using Domain.Events;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public class OrderStatusChangedToAwaitingValidationDomainEventHandler public class OrderStatusChangedToAwaitingValidationDomainEventHandler
: INotificationHandler<OrderStatusChangedToAwaitingValidationDomainEvent> : INotificationHandler<OrderStatusChangedToAwaitingValidationDomainEvent>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
private readonly IBuyerRepository _buyerRepository; private readonly IBuyerRepository _buyerRepository;
@ -48,5 +36,4 @@
order.Id, order.OrderStatus.Name, buyer.Name, orderStockList); order.Id, order.OrderStatus.Name, buyer.Name, orderStockList);
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToAwaitingValidationIntegrationEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToAwaitingValidationIntegrationEvent);
} }
}
} }

View File

@ -1,20 +1,8 @@
namespace Ordering.API.Application.DomainEventHandlers.OrderPaid namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderPaid;
{
using Domain.Events;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public class OrderStatusChangedToPaidDomainEventHandler public class OrderStatusChangedToPaidDomainEventHandler
: INotificationHandler<OrderStatusChangedToPaidDomainEvent> : INotificationHandler<OrderStatusChangedToPaidDomainEvent>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
private readonly IBuyerRepository _buyerRepository; private readonly IBuyerRepository _buyerRepository;
@ -53,5 +41,4 @@
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToPaidIntegrationEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToPaidIntegrationEvent);
} }
}
} }

View File

@ -1,19 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderShipped;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Ordering.API.Application.IntegrationEvents.Events;
using Ordering.Domain.Events;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.DomainEventHandlers.OrderShipped public class OrderShippedDomainEventHandler
{
public class OrderShippedDomainEventHandler
: INotificationHandler<OrderShippedDomainEvent> : INotificationHandler<OrderShippedDomainEvent>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly IBuyerRepository _buyerRepository; private readonly IBuyerRepository _buyerRepository;
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService; private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
@ -43,5 +32,4 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderShipped
var orderStatusChangedToShippedIntegrationEvent = new OrderStatusChangedToShippedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); var orderStatusChangedToShippedIntegrationEvent = new OrderStatusChangedToShippedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name);
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToShippedIntegrationEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToShippedIntegrationEvent);
} }
}
} }

View File

@ -1,8 +1,8 @@
namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderStartedEvent;
public class SendEmailToCustomerWhenOrderStartedDomainEventHandler
//: IAsyncNotificationHandler<OrderStartedDomainEvent>
{ {
public class SendEmailToCustomerWhenOrderStartedDomainEventHandler
//: IAsyncNotificationHandler<OrderStartedDomainEvent>
{
public SendEmailToCustomerWhenOrderStartedDomainEventHandler() public SendEmailToCustomerWhenOrderStartedDomainEventHandler()
{ {
@ -12,5 +12,4 @@
//{ //{
// //TBD - Send email logic // //TBD - Send email logic
//} //}
}
} }

View File

@ -1,19 +1,8 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderStartedEvent;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Ordering.API.Application.IntegrationEvents.Events;
using Ordering.Domain.Events;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler
{
public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler
: INotificationHandler<OrderStartedDomainEvent> : INotificationHandler<OrderStartedDomainEvent>
{ {
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
private readonly IBuyerRepository _buyerRepository; private readonly IBuyerRepository _buyerRepository;
private readonly IIdentityService _identityService; private readonly IIdentityService _identityService;
@ -63,5 +52,4 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent
.LogTrace("Buyer {BuyerId} and related payment method were validated or updated for orderId: {OrderId}.", .LogTrace("Buyer {BuyerId} and related payment method were validated or updated for orderId: {OrderId}.",
buyerUpdated.Id, orderStartedEvent.Order.Id); buyerUpdated.Id, orderStartedEvent.Order.Id);
} }
}
} }

View File

@ -1,19 +1,8 @@
namespace Ordering.API.Application.DomainEventHandlers.OrderStockConfirmed namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers.OrderStockConfirmed;
{
using Domain.Events;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Threading;
using System.Threading.Tasks;
public class OrderStatusChangedToStockConfirmedDomainEventHandler public class OrderStatusChangedToStockConfirmedDomainEventHandler
: INotificationHandler<OrderStatusChangedToStockConfirmedDomainEvent> : INotificationHandler<OrderStatusChangedToStockConfirmedDomainEvent>
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly IBuyerRepository _buyerRepository; private readonly IBuyerRepository _buyerRepository;
private readonly ILoggerFactory _logger; private readonly ILoggerFactory _logger;
@ -43,5 +32,4 @@
var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name); var orderStatusChangedToStockConfirmedIntegrationEvent = new OrderStatusChangedToStockConfirmedIntegrationEvent(order.Id, order.OrderStatus.Name, buyer.Name);
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToStockConfirmedIntegrationEvent); await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedToStockConfirmedIntegrationEvent);
} }
}
} }

View File

@ -1,16 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.EventHandling;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using Ordering.API.Application.IntegrationEvents.Events;
using Serilog.Context;
using System.Threading.Tasks;
namespace Ordering.API.Application.IntegrationEvents.EventHandling public class GracePeriodConfirmedIntegrationEventHandler : IIntegrationEventHandler<GracePeriodConfirmedIntegrationEvent>
{ {
public class GracePeriodConfirmedIntegrationEventHandler : IIntegrationEventHandler<GracePeriodConfirmedIntegrationEvent>
{
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<GracePeriodConfirmedIntegrationEventHandler> _logger; private readonly ILogger<GracePeriodConfirmedIntegrationEventHandler> _logger;
@ -48,5 +39,4 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
await _mediator.Send(command); await _mediator.Send(command);
} }
} }
}
} }

View File

@ -1,18 +1,8 @@
namespace Ordering.API.Application.IntegrationEvents.EventHandling namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.EventHandling;
{
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using Ordering.API.Application.IntegrationEvents.Events;
using Serilog.Context;
using System;
using System.Threading.Tasks;
public class OrderPaymentFailedIntegrationEventHandler : public class OrderPaymentFailedIntegrationEventHandler :
IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent> IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<OrderPaymentFailedIntegrationEventHandler> _logger; private readonly ILogger<OrderPaymentFailedIntegrationEventHandler> _logger;
@ -42,5 +32,4 @@
await _mediator.Send(command); await _mediator.Send(command);
} }
} }
}
} }

View File

@ -1,18 +1,8 @@
namespace Ordering.API.Application.IntegrationEvents.EventHandling namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.EventHandling;
{
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using Ordering.API.Application.IntegrationEvents.Events;
using Serilog.Context;
using System;
using System.Threading.Tasks;
public class OrderPaymentSucceededIntegrationEventHandler : public class OrderPaymentSucceededIntegrationEventHandler :
IIntegrationEventHandler<OrderPaymentSucceededIntegrationEvent> IIntegrationEventHandler<OrderPaymentSucceededIntegrationEvent>
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<OrderPaymentSucceededIntegrationEventHandler> _logger; private readonly ILogger<OrderPaymentSucceededIntegrationEventHandler> _logger;
@ -42,5 +32,4 @@
await _mediator.Send(command); await _mediator.Send(command);
} }
} }
}
} }

View File

@ -1,18 +1,8 @@
namespace Ordering.API.Application.IntegrationEvents.EventHandling namespace Ordering.API.Application.IntegrationEvents.EventHandling;
{
using Events;
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using Serilog.Context;
using System;
using System.Threading.Tasks;
public class OrderStockConfirmedIntegrationEventHandler : public class OrderStockConfirmedIntegrationEventHandler :
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent> IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<OrderStockConfirmedIntegrationEventHandler> _logger; private readonly ILogger<OrderStockConfirmedIntegrationEventHandler> _logger;
@ -42,5 +32,4 @@
await _mediator.Send(command); await _mediator.Send(command);
} }
} }
}
} }

View File

@ -1,17 +1,6 @@
namespace Ordering.API.Application.IntegrationEvents.EventHandling namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.EventHandling;
public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandler<OrderStockRejectedIntegrationEvent>
{ {
using Events;
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using Serilog.Context;
using System.Linq;
using System.Threading.Tasks;
public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandler<OrderStockRejectedIntegrationEvent>
{
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<OrderStockRejectedIntegrationEventHandler> _logger; private readonly ILogger<OrderStockRejectedIntegrationEventHandler> _logger;
@ -46,5 +35,4 @@
await _mediator.Send(command); await _mediator.Send(command);
} }
} }
}
} }

View File

@ -1,17 +1,7 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.EventHandling;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents.Events;
using Serilog.Context;
using System;
using System.Threading.Tasks;
namespace Ordering.API.Application.IntegrationEvents.EventHandling public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
{ {
public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>
{
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger; private readonly ILogger<UserCheckoutAcceptedIntegrationEventHandler> _logger;
@ -76,5 +66,4 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
} }
} }
} }
}
} }

View File

@ -1,12 +1,10 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public record GracePeriodConfirmedIntegrationEvent : IntegrationEvent public record GracePeriodConfirmedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public GracePeriodConfirmedIntegrationEvent(int orderId) => public GracePeriodConfirmedIntegrationEvent(int orderId) =>
OrderId = orderId; OrderId = orderId;
}
} }

View File

@ -1,11 +1,8 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public record OrderPaymentFailedIntegrationEvent : IntegrationEvent public record OrderPaymentFailedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public OrderPaymentFailedIntegrationEvent(int orderId) => OrderId = orderId; public OrderPaymentFailedIntegrationEvent(int orderId) => OrderId = orderId;
}
} }

View File

@ -1,11 +1,8 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public record OrderPaymentSucceededIntegrationEvent : IntegrationEvent public record OrderPaymentSucceededIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public OrderPaymentSucceededIntegrationEvent(int orderId) => OrderId = orderId; public OrderPaymentSucceededIntegrationEvent(int orderId) => OrderId = orderId;
}
} }

View File

@ -1,15 +1,12 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
namespace Ordering.API.Application.IntegrationEvents.Events // Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public record OrderStartedIntegrationEvent : IntegrationEvent
{ {
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public record OrderStartedIntegrationEvent : IntegrationEvent
{
public string UserId { get; init; } public string UserId { get; init; }
public OrderStartedIntegrationEvent(string userId) public OrderStartedIntegrationEvent(string userId)
=> UserId = userId; => UserId = userId;
}
} }

View File

@ -1,10 +1,7 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
public record OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent public record OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public string OrderStatus { get; } public string OrderStatus { get; }
public string BuyerName { get; } public string BuyerName { get; }
@ -18,10 +15,10 @@
OrderStatus = orderStatus; OrderStatus = orderStatus;
BuyerName = buyerName; BuyerName = buyerName;
} }
} }
public record OrderStockItem public record OrderStockItem
{ {
public int ProductId { get; } public int ProductId { get; }
public int Units { get; } public int Units { get; }
@ -30,5 +27,4 @@
ProductId = productId; ProductId = productId;
Units = units; Units = units;
} }
}
} }

View File

@ -1,9 +1,7 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
namespace Ordering.API.Application.IntegrationEvents.Events public record OrderStatusChangedToCancelledIntegrationEvent : IntegrationEvent
{ {
public record OrderStatusChangedToCancelledIntegrationEvent : IntegrationEvent
{
public int OrderId { get; } public int OrderId { get; }
public string OrderStatus { get; } public string OrderStatus { get; }
public string BuyerName { get; } public string BuyerName { get; }
@ -14,5 +12,4 @@ namespace Ordering.API.Application.IntegrationEvents.Events
OrderStatus = orderStatus; OrderStatus = orderStatus;
BuyerName = buyerName; BuyerName = buyerName;
} }
}
} }

View File

@ -1,10 +1,7 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public string OrderStatus { get; } public string OrderStatus { get; }
public string BuyerName { get; } public string BuyerName { get; }
@ -20,5 +17,5 @@
OrderStatus = orderStatus; OrderStatus = orderStatus;
BuyerName = buyerName; BuyerName = buyerName;
} }
}
} }

View File

@ -1,9 +1,7 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
namespace Ordering.API.Application.IntegrationEvents.Events public record OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent
{ {
public record OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; } public int OrderId { get; }
public string OrderStatus { get; } public string OrderStatus { get; }
public string BuyerName { get; } public string BuyerName { get; }
@ -14,5 +12,4 @@ namespace Ordering.API.Application.IntegrationEvents.Events
OrderStatus = orderStatus; OrderStatus = orderStatus;
BuyerName = buyerName; BuyerName = buyerName;
} }
}
} }

View File

@ -1,9 +1,7 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public record OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent public record OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public string OrderStatus { get; } public string OrderStatus { get; }
public string BuyerName { get; } public string BuyerName { get; }
@ -14,5 +12,4 @@
OrderStatus = orderStatus; OrderStatus = orderStatus;
BuyerName = buyerName; BuyerName = buyerName;
} }
}
} }

View File

@ -1,9 +1,7 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
namespace Ordering.API.Application.IntegrationEvents.Events public record OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent
{ {
public record OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; } public int OrderId { get; }
public string OrderStatus { get; } public string OrderStatus { get; }
public string BuyerName { get; } public string BuyerName { get; }
@ -14,5 +12,4 @@ namespace Ordering.API.Application.IntegrationEvents.Events
OrderStatus = orderStatus; OrderStatus = orderStatus;
BuyerName = buyerName; BuyerName = buyerName;
} }
}
} }

View File

@ -1,11 +1,8 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
public record OrderStockConfirmedIntegrationEvent : IntegrationEvent public record OrderStockConfirmedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public OrderStockConfirmedIntegrationEvent(int orderId) => OrderId = orderId; public OrderStockConfirmedIntegrationEvent(int orderId) => OrderId = orderId;
}
} }

View File

@ -1,10 +1,7 @@
namespace Ordering.API.Application.IntegrationEvents.Events namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
{
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
public record OrderStockRejectedIntegrationEvent : IntegrationEvent public record OrderStockRejectedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; } public int OrderId { get; }
public List<ConfirmedOrderStockItem> OrderStockItems { get; } public List<ConfirmedOrderStockItem> OrderStockItems { get; }
@ -15,10 +12,10 @@
OrderId = orderId; OrderId = orderId;
OrderStockItems = orderStockItems; OrderStockItems = orderStockItems;
} }
} }
public record ConfirmedOrderStockItem public record ConfirmedOrderStockItem
{ {
public int ProductId { get; } public int ProductId { get; }
public bool HasStock { get; } public bool HasStock { get; }
@ -27,5 +24,4 @@
ProductId = productId; ProductId = productId;
HasStock = hasStock; HasStock = hasStock;
} }
}
} }

View File

@ -1,11 +1,7 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
using Ordering.API.Application.Models;
using System;
namespace Ordering.API.Application.IntegrationEvents.Events public record UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
{ {
public record UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
{
public string UserId { get; } public string UserId { get; }
public string UserName { get; } public string UserName { get; }
@ -58,5 +54,4 @@ namespace Ordering.API.Application.IntegrationEvents.Events
UserName = userName; UserName = userName;
} }
}
} }

View File

@ -1,12 +1,7 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents;
using System;
using System.Threading.Tasks;
namespace Ordering.API.Application.IntegrationEvents public interface IOrderingIntegrationEventService
{ {
public interface IOrderingIntegrationEventService
{
Task PublishEventsThroughEventBusAsync(Guid transactionId); Task PublishEventsThroughEventBusAsync(Guid transactionId);
Task AddAndSaveEventAsync(IntegrationEvent evt); Task AddAndSaveEventAsync(IntegrationEvent evt);
}
} }

View File

@ -1,18 +1,7 @@
using Microsoft.EntityFrameworkCore; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
using Microsoft.Extensions.Logging;
using System;
using System.Data.Common;
using System.Threading.Tasks;
namespace Ordering.API.Application.IntegrationEvents public class OrderingIntegrationEventService : IOrderingIntegrationEventService
{ {
public class OrderingIntegrationEventService : IOrderingIntegrationEventService
{
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory; private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
private readonly IEventBus _eventBus; private readonly IEventBus _eventBus;
private readonly OrderingContext _orderingContext; private readonly OrderingContext _orderingContext;
@ -61,5 +50,4 @@ namespace Ordering.API.Application.IntegrationEvents
await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction()); await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction());
} }
}
} }

View File

@ -1,7 +1,7 @@
namespace Ordering.API.Application.Models namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
public class BasketItem
{ {
public class BasketItem
{
public string Id { get; init; } public string Id { get; init; }
public int ProductId { get; init; } public int ProductId { get; init; }
public string ProductName { get; init; } public string ProductName { get; init; }
@ -9,5 +9,5 @@
public decimal OldUnitPrice { get; init; } public decimal OldUnitPrice { get; init; }
public int Quantity { get; init; } public int Quantity { get; init; }
public string PictureUrl { get; init; } public string PictureUrl { get; init; }
}
} }

View File

@ -1,9 +1,7 @@
using System.Collections.Generic; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
namespace Ordering.API.Application.Models public class CustomerBasket
{ {
public class CustomerBasket
{
public string BuyerId { get; set; } public string BuyerId { get; set; }
public List<BasketItem> Items { get; set; } public List<BasketItem> Items { get; set; }
@ -12,5 +10,4 @@ namespace Ordering.API.Application.Models
BuyerId = buyerId; BuyerId = buyerId;
Items = items; Items = items;
} }
}
} }

View File

@ -1,15 +1,10 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public interface IOrderQueries public interface IOrderQueries
{ {
Task<Order> GetOrderAsync(int id); Task<Order> GetOrderAsync(int id);
Task<IEnumerable<OrderSummary>> GetOrdersFromUserAsync(Guid userId); Task<IEnumerable<OrderSummary>> GetOrdersFromUserAsync(Guid userId);
Task<IEnumerable<CardType>> GetCardTypesAsync(); Task<IEnumerable<CardType>> GetCardTypesAsync();
}
} }

View File

@ -1,14 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
{
using Dapper;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading.Tasks;
public class OrderQueries public class OrderQueries
: IOrderQueries : IOrderQueries
{ {
private string _connectionString = string.Empty; private string _connectionString = string.Empty;
public OrderQueries(string constr) public OrderQueries(string constr)
@ -101,5 +95,4 @@
return order; return order;
} }
}
} }

View File

@ -1,18 +1,15 @@
using System; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
using System.Collections.Generic;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries public record Orderitem
{ {
public record Orderitem
{
public string productname { get; init; } public string productname { get; init; }
public int units { get; init; } public int units { get; init; }
public double unitprice { get; init; } public double unitprice { get; init; }
public string pictureurl { get; init; } public string pictureurl { get; init; }
} }
public record Order public record Order
{ {
public int ordernumber { get; init; } public int ordernumber { get; init; }
public DateTime date { get; init; } public DateTime date { get; init; }
public string status { get; init; } public string status { get; init; }
@ -23,19 +20,18 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries
public string country { get; init; } public string country { get; init; }
public List<Orderitem> orderitems { get; set; } public List<Orderitem> orderitems { get; set; }
public decimal total { get; set; } public decimal total { get; set; }
} }
public record OrderSummary public record OrderSummary
{ {
public int ordernumber { get; init; } public int ordernumber { get; init; }
public DateTime date { get; init; } public DateTime date { get; init; }
public string status { get; init; } public string status { get; init; }
public double total { get; init; } public double total { get; init; }
} }
public record CardType public record CardType
{ {
public int Id { get; init; } public int Id { get; init; }
public string Name { get; init; } public string Name { get; init; }
}
} }

View File

@ -1,16 +1,11 @@
using FluentValidation; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Validations;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
namespace Ordering.API.Application.Validations public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
{ {
public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
{
public CancelOrderCommandValidator(ILogger<CancelOrderCommandValidator> logger) public CancelOrderCommandValidator(ILogger<CancelOrderCommandValidator> logger)
{ {
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found"); RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
} }
}
} }

View File

@ -1,15 +1,9 @@
using FluentValidation; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Validations;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand; using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
namespace Ordering.API.Application.Validations public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
{ {
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
{
public CreateOrderCommandValidator(ILogger<CreateOrderCommandValidator> logger) public CreateOrderCommandValidator(ILogger<CreateOrderCommandValidator> logger)
{ {
RuleFor(command => command.City).NotEmpty(); RuleFor(command => command.City).NotEmpty();
@ -36,5 +30,4 @@ namespace Ordering.API.Application.Validations
{ {
return orderItems.Any(); return orderItems.Any();
} }
}
} }

View File

@ -1,16 +1,11 @@
using FluentValidation; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Validations;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
namespace Ordering.API.Application.Validations public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand, bool>>
{ {
public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand, bool>>
{
public IdentifiedCommandValidator(ILogger<IdentifiedCommandValidator> logger) public IdentifiedCommandValidator(ILogger<IdentifiedCommandValidator> logger)
{ {
RuleFor(command => command.Id).NotEmpty(); RuleFor(command => command.Id).NotEmpty();
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
} }
}
} }

View File

@ -1,16 +1,11 @@
using FluentValidation; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Validations;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
namespace Ordering.API.Application.Validations public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
{ {
public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
{
public ShipOrderCommandValidator(ILogger<ShipOrderCommandValidator> logger) public ShipOrderCommandValidator(ILogger<ShipOrderCommandValidator> logger)
{ {
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found"); RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
} }
}
} }

View File

@ -1,13 +1,10 @@
using Microsoft.AspNetCore.Mvc; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers public class HomeController : Controller
{ {
public class HomeController : Controller
{
// GET: /<controller>/ // GET: /<controller>/
public IActionResult Index() public IActionResult Index()
{ {
return new RedirectResult("~/swagger"); return new RedirectResult("~/swagger");
} }
}
} }

View File

@ -1,24 +1,15 @@
using MediatR; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers [Route("api/v1/[controller]")]
[Authorize]
[ApiController]
public class OrdersController : ControllerBase
{ {
[Route("api/v1/[controller]")]
[Authorize]
[ApiController]
public class OrdersController : ControllerBase
{
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IOrderQueries _orderQueries; private readonly IOrderQueries _orderQueries;
private readonly IIdentityService _identityService; private readonly IIdentityService _identityService;
@ -149,5 +140,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
return await _mediator.Send(createOrderDraftCommand); return await _mediator.Send(createOrderDraftCommand);
} }
}
} }

View File

@ -1,10 +1,10 @@
using System.Collections.Generic; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Models;
using System.Collections.Generic;
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand; using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
namespace Ordering.API.Application.Models public static class BasketItemExtensions
{ {
public static class BasketItemExtensions
{
public static IEnumerable<OrderItemDTO> ToOrderItemsDTO(this IEnumerable<BasketItem> basketItems) public static IEnumerable<OrderItemDTO> ToOrderItemsDTO(this IEnumerable<BasketItem> basketItems)
{ {
foreach (var item in basketItems) foreach (var item in basketItems)
@ -24,5 +24,4 @@ namespace Ordering.API.Application.Models
Units = item.Quantity Units = item.Quantity
}; };
} }
}
} }

View File

@ -1,11 +1,7 @@
using System; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Extensions;
using System.Collections.Generic;
using System.Linq;
namespace Ordering.API.Extensions public static class LinqSelectExtensions
{ {
public static class LinqSelectExtensions
{
public static IEnumerable<SelectTryResult<TSource, TResult>> SelectTry<TSource, TResult>(this IEnumerable<TSource> enumerable, Func<TSource, TResult> selector) public static IEnumerable<SelectTryResult<TSource, TResult>> SelectTry<TSource, TResult>(this IEnumerable<TSource> enumerable, Func<TSource, TResult> selector)
{ {
foreach (TSource element in enumerable) foreach (TSource element in enumerable)
@ -46,5 +42,4 @@ namespace Ordering.API.Extensions
public TResult Result { get; private set; } public TResult Result { get; private set; }
public Exception CaughtException { get; private set; } public Exception CaughtException { get; private set; }
} }
}
} }

View File

@ -1,18 +1,7 @@
using Google.Protobuf.Collections; namespace GrpcOrdering;
using Grpc.Core;
using MediatR;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Extensions;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ApiModels = Ordering.API.Application.Models;
using AppCommand = Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
namespace GrpcOrdering public class OrderingService : OrderingGrpc.OrderingGrpcBase
{ {
public class OrderingService : OrderingGrpc.OrderingGrpcBase
{
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly ILogger<OrderingService> _logger; private readonly ILogger<OrderingService> _logger;
@ -86,5 +75,4 @@ namespace GrpcOrdering
PictureUrl = x.PictureUrl, PictureUrl = x.PictureUrl,
}); });
} }
}
} }

View File

@ -1,14 +1,10 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.ActionResults namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.ActionResults;
{
using AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
public class InternalServerErrorObjectResult : ObjectResult public class InternalServerErrorObjectResult : ObjectResult
{ {
public InternalServerErrorObjectResult(object error) public InternalServerErrorObjectResult(object error)
: base(error) : base(error)
{ {
StatusCode = StatusCodes.Status500InternalServerError; StatusCode = StatusCodes.Status500InternalServerError;
} }
}
} }

View File

@ -1,13 +1,7 @@
using Microsoft.AspNetCore.Mvc.Authorization; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth public class AuthorizationHeaderParameterOperationFilter : IOperationFilter
{ {
public class AuthorizationHeaderParameterOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context) public void Apply(OpenApiOperation operation, OperationFilterContext context)
{ {
var filterPipeline = context.ApiDescription.ActionDescriptor.FilterDescriptors; var filterPipeline = context.ApiDescription.ActionDescriptor.FilterDescriptors;
@ -30,5 +24,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Auth
} }
} }
}
} }

View File

@ -1,19 +1,8 @@
using Autofac; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositories;
using System.Reflection;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules public class ApplicationModule
{
public class ApplicationModule
: Autofac.Module : Autofac.Module
{ {
public string QueriesConnectionString { get; } public string QueriesConnectionString { get; }
@ -46,5 +35,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof
.AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); .AsClosedTypesOf(typeof(IIntegrationEventHandler<>));
} }
}
} }

View File

@ -1,17 +1,7 @@
using Autofac; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules;
using FluentValidation;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Ordering.API.Application.Behaviors;
using Ordering.API.Application.DomainEventHandlers.OrderStartedEvent;
using Ordering.API.Application.Validations;
using System.Linq;
using System.Reflection;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.AutofacModules public class MediatorModule : Autofac.Module
{ {
public class MediatorModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder) protected override void Load(ContainerBuilder builder)
{ {
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly) builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
@ -43,5 +33,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof
builder.RegisterGeneric(typeof(TransactionBehaviour<,>)).As(typeof(IPipelineBehavior<,>)); builder.RegisterGeneric(typeof(TransactionBehaviour<,>)).As(typeof(IPipelineBehavior<,>));
} }
}
} }

View File

@ -1,10 +1,4 @@
using Microsoft.EntityFrameworkCore; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Factories
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
using Microsoft.Extensions.Configuration;
using System.IO;
namespace Ordering.API.Infrastructure.Factories
{ {
public class OrderingDbContextFactory : IDesignTimeDbContextFactory<OrderingContext> public class OrderingDbContextFactory : IDesignTimeDbContextFactory<OrderingContext>
{ {

View File

@ -1,13 +1,7 @@
using Microsoft.AspNetCore.Authorization; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Filters;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Ordering.API.Infrastructure.Filters public class AuthorizeCheckOperationFilter : IOperationFilter
{ {
public class AuthorizeCheckOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context) public void Apply(OpenApiOperation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
@ -32,5 +26,4 @@ namespace Ordering.API.Infrastructure.Filters
} }
}; };
} }
}
} }

View File

@ -1,17 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Filters namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Filters;
{
using AspNetCore.Mvc;
using global::Ordering.Domain.Exceptions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.ActionResults;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Net;
public class HttpGlobalExceptionFilter : IExceptionFilter public class HttpGlobalExceptionFilter : IExceptionFilter
{ {
private readonly IWebHostEnvironment env; private readonly IWebHostEnvironment env;
private readonly ILogger<HttpGlobalExceptionFilter> logger; private readonly ILogger<HttpGlobalExceptionFilter> logger;
@ -67,5 +57,4 @@
public object DeveloperMessage { get; set; } public object DeveloperMessage { get; set; }
} }
}
} }

View File

@ -1,25 +1,9 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure;
{
using global::Ordering.API.Extensions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Ordering.Infrastructure;
using Polly;
using Polly.Retry;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
public class OrderingContextSeed using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate;
{
public class OrderingContextSeed
{
public async Task SeedAsync(OrderingContext context, IWebHostEnvironment env, IOptions<OrderingSettings> settings, ILogger<OrderingContextSeed> logger) public async Task SeedAsync(OrderingContext context, IWebHostEnvironment env, IOptions<OrderingSettings> settings, ILogger<OrderingContextSeed> logger)
{ {
var policy = CreatePolicy(logger, nameof(OrderingContextSeed)); var policy = CreatePolicy(logger, nameof(OrderingContextSeed));
@ -187,5 +171,4 @@
} }
); );
} }
}
} }

View File

@ -1,9 +1,9 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
public interface IIdentityService
{ {
public interface IIdentityService
{
string GetUserIdentity(); string GetUserIdentity();
string GetUserName(); string GetUserName();
}
} }

View File

@ -1,11 +1,7 @@
 namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
using Microsoft.AspNetCore.Http;
using System;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services public class IdentityService : IIdentityService
{ {
public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context; private IHttpContextAccessor _context;
public IdentityService(IHttpContextAccessor context) public IdentityService(IHttpContextAccessor context)
@ -22,5 +18,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Servi
{ {
return _context.HttpContext.User.Identity.Name; return _context.HttpContext.User.Identity.Name;
} }
}
} }

View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API namespace Microsoft.eShopOnContainers.Services.Ordering.API;
public class OrderingSettings
{ {
public class OrderingSettings
{
public bool UseCustomizationData { get; set; } public bool UseCustomizationData { get; set; }
public string ConnectionString { get; set; } public string ConnectionString { get; set; }
@ -11,5 +11,4 @@
public int GracePeriodTime { get; set; } public int GracePeriodTime { get; set; }
public int CheckUpdateTime { get; set; } public int CheckUpdateTime { get; set; }
}
} }

View File

@ -1,22 +1,4 @@
using Microsoft.AspNetCore; var configuration = GetConfiguration();
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.Services.Ordering.API;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Serilog;
using System;
using System.IO;
using System.Net;
using Azure.Identity;
using Azure.Core;
var configuration = GetConfiguration();
Log.Logger = CreateSerilogLogger(configuration); Log.Logger = CreateSerilogLogger(configuration);

View File

@ -1,45 +1,8 @@
namespace Microsoft.eShopOnContainers.Services.Ordering.API 
{ namespace Microsoft.eShopOnContainers.Services.Ordering.API;
using AspNetCore.Http;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using global::Ordering.API.Application.IntegrationEvents;
using global::Ordering.API.Application.IntegrationEvents.Events;
using global::Ordering.API.Infrastructure.Filters;
using GrpcOrdering;
using HealthChecks.UI.Client;
using Infrastructure.AutofacModules;
using Infrastructure.Filters;
using Infrastructure.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.eShopOnContainers.Services.Ordering.API.Controllers;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Ordering.Infrastructure;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Reflection;
public class Startup public class Startup
{ {
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
Configuration = configuration; Configuration = configuration;
@ -151,10 +114,10 @@
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
} }
} }
static class CustomExtensionsMethods static class CustomExtensionsMethods
{ {
public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddApplicationInsights(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddApplicationInsightsTelemetry(configuration); services.AddApplicationInsightsTelemetry(configuration);
@ -425,5 +388,4 @@
return services; return services;
} }
}
} }