From acb618a6fdda8c5c9441dd8efa44a06a67c29e20 Mon Sep 17 00:00:00 2001 From: meysamhadeli Date: Mon, 21 Nov 2022 04:31:21 +0330 Subject: [PATCH] refactor all properties and dtos --- booking.rest | 12 +++---- src/BuildingBlocks/Caching/CachingBehavior.cs | 11 +++--- src/BuildingBlocks/Caching/Extensions.cs | 29 --------------- src/BuildingBlocks/Caching/ICacheRequest.cs | 2 -- .../Caching/IInvalidateCacheRequest.cs | 4 --- .../Caching/InvalidateCachingBehavior.cs | 10 ++---- .../Core/Event/InternalCommand.cs | 5 +-- src/BuildingBlocks/Core/Model/Aggregate.cs | 2 +- src/BuildingBlocks/EFCore/EfTxBehavior.cs | 2 -- .../Booking/src/Booking.Api/Program.cs | 20 ----------- .../Dtos/CreateReservationResponseDto.cs | 16 ++------- .../Booking/Features/BookingMappings.cs | 21 +++++------ .../Dtos/V1/CreateBookingRequestDto.cs | 3 ++ .../Endpoints/V1/CreateBookingEndpoint.cs | 8 ++++- .../src/Booking/Booking/Models/Booking.cs | 2 -- .../InfrastructureExtensions.cs | 3 +- .../Infrastructure/MediatRExtensions.cs | 4 +-- .../Aircrafts/Dtos/AircraftResponseDto.cs | 8 +---- .../Aircrafts/Features/AircraftMappings.cs | 6 ++++ .../V1/Reads/CreateAircraftMongoCommand.cs | 19 +--------- .../CreateAircraftMongoCommandHandler.cs | 2 +- .../Dtos/V1/CreateAircraftRequestDto.cs | 4 +++ .../Endpoints/V1/CreateAircraftEndpoint.cs | 7 +++- .../src/Flight/Aircrafts/Models/Aircraft.cs | 4 --- .../src/Flight/Airports/AirportMappings.cs | 5 +++ .../Airports/Dtos/AirportResponseDto.cs | 9 ++--- .../V1/Reads/CreateAirportMongoCommand.cs | 17 +-------- .../Reads/CreateAirportMongoCommandHandler.cs | 2 +- .../Dtos/V1/CreateAirportRequestDto.cs | 3 ++ .../Endpoints/V1/CreateAirportEndpoint.cs | 7 +++- .../src/Flight/Airports/Models/Airport.cs | 4 --- .../Airports/Models/Reads/AirportReadModel.cs | 2 +- .../InfrastructureExtensions.cs | 4 +-- .../Infrastructure/MediatRExtensions.cs | 9 ++--- .../Flight/Flights/Dtos/FlightResponseDto.cs | 19 +++------- .../Commands/V1/CreateFlightCommandHandler.cs | 4 ++- .../V1/Reads/CreateFlightMongoCommand.cs | 36 ++----------------- .../Reads/CreateFlightMongoCommandHandler.cs | 2 +- .../Dtos/V1/CreateFlightRequestDto.cs | 7 ++++ .../Endpoints/V1/CreateFlightEndpoint.cs | 8 ++++- .../V1/Reads/DeleteFlightMongoCommand.cs | 36 ++----------------- .../Flight/Flights/Features/FlightMappings.cs | 20 ++++++++++- .../V1/GetAvailableFlightsEndpoint.cs | 2 +- .../Endpoints/V1/GetFlightByIdEndpoint.cs | 28 +-------------- .../V1/Reads/UpdateFlightMongoCommand.cs | 36 ++----------------- .../Commands/V1/UpdateFlightCommand.cs | 18 ++-------- .../Dtos/UpdateFlightRequestDto.cs | 6 ++++ .../Endpoints/V1/UpdateFlightEndpoint.cs | 8 +++-- .../Flights/Models/Reads/FlightReadModel.cs | 2 -- .../src/Flight/Seats/Dtos/SeatResponseDto.cs | 11 +----- .../V1/Reads/CreateSeatMongoCommand.cs | 22 ++---------- .../V1/Reads/CreateSeatMongoCommandHandler.cs | 2 +- .../Dtos/V1/CreateSeatRequestDto.cs | 3 ++ .../Endpoints/V1/CreateSeatEndpoint.cs | 35 ++++-------------- .../V1/Reads/ReserveSeatMongoCommand.cs | 21 ++--------- .../Dtos/V1/ReserveSeatRequestDto.cs | 4 +++ .../Endpoints/V1/ReserveSeatEndpoint.cs | 8 +++-- .../src/Flight/Seats/Features/SeatMappings.cs | 16 ++++++++- .../Fakes/FakeFlightCreated.cs | 3 +- .../Flight/Features/GetFlightByIdTests.cs | 2 +- .../InfrastructureExtensions.cs | 1 + .../Infrastructure/MediatRExtensions.cs | 4 +-- .../Dtos/RegisterNewUserResponseDto.cs | 12 +------ .../Identity/Features/IdentityMappings.cs | 15 ++++++++ .../V1/RegisterNewUserCommandHandler.cs | 12 ++----- .../Dtos/V1/RegisterNewUserRequestDto.cs | 4 +++ .../Endpoints/V1/RegisterNewUserEndpoint.cs | 7 +++- .../Identity/Models/ApplicationUser.cs | 6 ++-- .../Passenger/src/Passenger.Api/Program.cs | 22 ------------ .../InfrastructureExtensions.cs | 2 +- .../Infrastructure/MediatRExtensions.cs | 6 ++-- .../CompleteRegisterPassengerMongoCommand.cs | 21 ++--------- ...eteRegisterPassengerMongoCommandHandler.cs | 2 +- .../V1/CompleteRegisterPassengerRequestDto.cs | 3 ++ .../V1/CompleteRegisterPassengerEndpoint.cs | 9 +++-- .../Passengers/Features/PassengerMappings.cs | 5 +++ .../Models/Reads/PassengerReadModel.cs | 8 ++--- 77 files changed, 253 insertions(+), 511 deletions(-) delete mode 100644 src/BuildingBlocks/Caching/Extensions.cs create mode 100644 src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Dtos/V1/CreateBookingRequestDto.cs create mode 100644 src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Dtos/V1/CreateAircraftRequestDto.cs create mode 100644 src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Dtos/V1/CreateAirportRequestDto.cs create mode 100644 src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Dtos/V1/CreateFlightRequestDto.cs create mode 100644 src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Dtos/UpdateFlightRequestDto.cs create mode 100644 src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Dtos/V1/CreateSeatRequestDto.cs create mode 100644 src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Dtos/V1/ReserveSeatRequestDto.cs create mode 100644 src/Services/Identity/src/Identity/Identity/Features/IdentityMappings.cs create mode 100644 src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Dtos/V1/RegisterNewUserRequestDto.cs create mode 100644 src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Dtos/V1/CompleteRegisterPassengerRequestDto.cs diff --git a/booking.rest b/booking.rest index f4ca175..98391e3 100644 --- a/booking.rest +++ b/booking.rest @@ -39,13 +39,13 @@ Content-Type: application/json authorization: bearer {{Authenticate.response.body.access_token}} { - "firstName": "4John", - "lastName": "4Do", - "username": "4admin", + "firstName": "John", + "lastName": "Do", + "username": "admin", "passportNumber": "412900000000", - "email": "4admin@admin.com", - "password": "4Admin@12345", - "confirmPassword": "4Admin@12345" + "email": "admin@admin.com", + "password": "Admin@12345", + "confirmPassword": "Admin@12345" } ### diff --git a/src/BuildingBlocks/Caching/CachingBehavior.cs b/src/BuildingBlocks/Caching/CachingBehavior.cs index 39d5676..46e5de2 100644 --- a/src/BuildingBlocks/Caching/CachingBehavior.cs +++ b/src/BuildingBlocks/Caching/CachingBehavior.cs @@ -8,28 +8,25 @@ public class CachingBehavior : IPipelineBehavior where TResponse : notnull { - private readonly ICacheRequest _cacheRequest; private readonly IEasyCachingProvider _cachingProvider; private readonly ILogger> _logger; private readonly int defaultCacheExpirationInHours = 1; public CachingBehavior(IEasyCachingProviderFactory cachingFactory, - ILogger> logger, - ICacheRequest cacheRequest) + ILogger> logger) { _logger = logger; _cachingProvider = cachingFactory.GetCachingProvider("mem"); - _cacheRequest = cacheRequest; } public async Task Handle(TRequest request, RequestHandlerDelegate next, CancellationToken cancellationToken) { - if (request is not ICacheRequest || _cacheRequest == null) + if (request is not ICacheRequest cacheRequest) // No cache request found, so just continue through the pipeline return await next(); - var cacheKey = _cacheRequest.CacheKey; + var cacheKey = cacheRequest.CacheKey; var cachedResponse = await _cachingProvider.GetAsync(cacheKey); if (cachedResponse.Value != null) { @@ -40,7 +37,7 @@ public class CachingBehavior : IPipelineBehavior assembliesToScan, ServiceLifetime lifetime = ServiceLifetime.Transient) - { - // ICacheRequest discovery and registration - services.Scan(scan => scan - .FromAssemblies(assembliesToScan ?? AppDomain.CurrentDomain.GetAssemblies()) - .AddClasses(classes => classes.AssignableTo(typeof(ICacheRequest)), - false) - .AsImplementedInterfaces() - .WithLifetime(lifetime)); - - // IInvalidateCacheRequest discovery and registration - services.Scan(scan => scan - .FromAssemblies(assembliesToScan ?? AppDomain.CurrentDomain.GetAssemblies()) - .AddClasses(classes => classes.AssignableTo(typeof(IInvalidateCacheRequest)), - false) - .AsImplementedInterfaces() - .WithLifetime(lifetime)); - - return services; - } -} diff --git a/src/BuildingBlocks/Caching/ICacheRequest.cs b/src/BuildingBlocks/Caching/ICacheRequest.cs index 67fbb2f..1f688a0 100644 --- a/src/BuildingBlocks/Caching/ICacheRequest.cs +++ b/src/BuildingBlocks/Caching/ICacheRequest.cs @@ -1,5 +1,3 @@ -using MediatR; - namespace BuildingBlocks.Caching; public interface ICacheRequest diff --git a/src/BuildingBlocks/Caching/IInvalidateCacheRequest.cs b/src/BuildingBlocks/Caching/IInvalidateCacheRequest.cs index 9b43396..446980d 100644 --- a/src/BuildingBlocks/Caching/IInvalidateCacheRequest.cs +++ b/src/BuildingBlocks/Caching/IInvalidateCacheRequest.cs @@ -1,7 +1,3 @@ -using System; -using System.Linq; -using MediatR; - namespace BuildingBlocks.Caching { public interface IInvalidateCacheRequest diff --git a/src/BuildingBlocks/Caching/InvalidateCachingBehavior.cs b/src/BuildingBlocks/Caching/InvalidateCachingBehavior.cs index deb156d..5b27354 100644 --- a/src/BuildingBlocks/Caching/InvalidateCachingBehavior.cs +++ b/src/BuildingBlocks/Caching/InvalidateCachingBehavior.cs @@ -10,27 +10,23 @@ namespace BuildingBlocks.Caching { private readonly ILogger> _logger; private readonly IEasyCachingProvider _cachingProvider; - private readonly IInvalidateCacheRequest _invalidateCacheRequest; - public InvalidateCachingBehavior(IEasyCachingProviderFactory cachingFactory, - ILogger> logger, - IInvalidateCacheRequest invalidateCacheRequest) + ILogger> logger) { _logger = logger; _cachingProvider = cachingFactory.GetCachingProvider("mem"); - _invalidateCacheRequest = invalidateCacheRequest; } public async Task Handle(TRequest request, RequestHandlerDelegate next, CancellationToken cancellationToken) { - if (request is not IInvalidateCacheRequest || _invalidateCacheRequest == null) + if (request is not IInvalidateCacheRequest invalidateCacheRequest) { // No cache request found, so just continue through the pipeline return await next(); } - var cacheKey = _invalidateCacheRequest.CacheKey; + var cacheKey = invalidateCacheRequest.CacheKey; var response = await next(); await _cachingProvider.RemoveAsync(cacheKey); diff --git a/src/BuildingBlocks/Core/Event/InternalCommand.cs b/src/BuildingBlocks/Core/Event/InternalCommand.cs index 68ba81a..b854545 100644 --- a/src/BuildingBlocks/Core/Event/InternalCommand.cs +++ b/src/BuildingBlocks/Core/Event/InternalCommand.cs @@ -3,7 +3,4 @@ using BuildingBlocks.IdsGenerator; namespace BuildingBlocks.Core.Event; -public class InternalCommand : IInternalCommand, ICommand -{ - public long Id { get; init; } = SnowFlakIdGenerator.NewId(); -} +public record InternalCommand : IInternalCommand, ICommand; diff --git a/src/BuildingBlocks/Core/Model/Aggregate.cs b/src/BuildingBlocks/Core/Model/Aggregate.cs index d68a9c5..42c87ca 100644 --- a/src/BuildingBlocks/Core/Model/Aggregate.cs +++ b/src/BuildingBlocks/Core/Model/Aggregate.cs @@ -27,6 +27,6 @@ namespace BuildingBlocks.Core.Model public long Version { get; set; } = -1; - public TId Id { get; protected set; } + public TId Id { get; set; } } } diff --git a/src/BuildingBlocks/EFCore/EfTxBehavior.cs b/src/BuildingBlocks/EFCore/EfTxBehavior.cs index b0a6e76..e156fec 100644 --- a/src/BuildingBlocks/EFCore/EfTxBehavior.cs +++ b/src/BuildingBlocks/EFCore/EfTxBehavior.cs @@ -1,7 +1,5 @@ -using System.Data; using System.Text.Json; using BuildingBlocks.Core; -using BuildingBlocks.Core.Event; using MediatR; using Microsoft.Extensions.Logging; diff --git a/src/Services/Booking/src/Booking.Api/Program.cs b/src/Services/Booking/src/Booking.Api/Program.cs index 169e7d3..2b97163 100644 --- a/src/Services/Booking/src/Booking.Api/Program.cs +++ b/src/Services/Booking/src/Booking.Api/Program.cs @@ -1,25 +1,5 @@ -using Booking; -using Booking.Data; -using Booking.Extensions; using Booking.Extensions.Infrastructure; -using BuildingBlocks.EventStoreDB; -using BuildingBlocks.HealthCheck; -using BuildingBlocks.IdsGenerator; -using BuildingBlocks.Jwt; -using BuildingBlocks.Logging; -using BuildingBlocks.Mapster; -using BuildingBlocks.MassTransit; -using BuildingBlocks.Mongo; -using BuildingBlocks.OpenTelemetry; -using BuildingBlocks.PersistMessageProcessor; -using BuildingBlocks.Swagger; using BuildingBlocks.Web; -using Figgle; -using FluentValidation; -using Hellang.Middleware.ProblemDetails; -using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Prometheus; -using Serilog; var builder = WebApplication.CreateBuilder(args); diff --git a/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservationResponseDto.cs b/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservationResponseDto.cs index 676c180..f3392a8 100644 --- a/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservationResponseDto.cs +++ b/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservationResponseDto.cs @@ -1,16 +1,4 @@ namespace Booking.Booking.Dtos; -public record BookingResponseDto -{ - public long Id { get; init; } - public string Name { get; init; } - public string FlightNumber { get; init; } - public long AircraftId { get; init; } - - public decimal Price { get; init; } - public DateTime FlightDate { get; init; } - public string SeatNumber { get; init; } - public long DepartureAirportId { get; init; } - public long ArriveAirportId { get; init; } - public string Description { get; init; } -} +public record BookingResponseDto(long Id, string Name, string FlightNumber, long AircraftId, decimal Price, + DateTime FlightDate, string SeatNumber, long DepartureAirportId, long ArriveAirportId, string Description); diff --git a/src/Services/Booking/src/Booking/Booking/Features/BookingMappings.cs b/src/Services/Booking/src/Booking/Booking/Features/BookingMappings.cs index 7dcec1a..42d454d 100644 --- a/src/Services/Booking/src/Booking/Booking/Features/BookingMappings.cs +++ b/src/Services/Booking/src/Booking/Booking/Features/BookingMappings.cs @@ -1,6 +1,6 @@ using Booking.Booking.Dtos; -using Booking.Booking.Models.Reads; -using BuildingBlocks.IdsGenerator; +using Booking.Booking.Features.CreateBooking.Commands.V1; +using Booking.Booking.Features.CreateBooking.Dtos.V1; using Mapster; namespace Booking.Booking.Features; @@ -12,15 +12,12 @@ public class BookingMappings : IRegister config.Default.NameMatchingStrategy(NameMatchingStrategy.Flexible); config.NewConfig() - .Map(d => d.Name, s => s.PassengerInfo.Name) - .Map(d => d.Description, s => s.Trip.Description) - .Map(d => d.DepartureAirportId, s => s.Trip.DepartureAirportId) - .Map(d => d.ArriveAirportId, s => s.Trip.ArriveAirportId) - .Map(d => d.FlightNumber, s => s.Trip.FlightNumber) - .Map(d => d.FlightDate, s => s.Trip.FlightDate) - .Map(d => d.Price, s => s.Trip.Price) - .Map(d => d.SeatNumber, s => s.Trip.SeatNumber) - .Map(d => d.AircraftId, s => s.Trip.AircraftId); + .ConstructUsing(x => new BookingResponseDto(x.Id, x.PassengerInfo.Name, x.Trip.FlightNumber, + x.Trip.AircraftId, x.Trip.Price, x.Trip.FlightDate, x.Trip.SeatNumber, x.Trip.DepartureAirportId, x.Trip.ArriveAirportId, + x.Trip.Description)); + + + config.NewConfig() + .ConstructUsing(x => new CreateBookingCommand(x.PassengerId, x.FlightId, x.Description)); } } - diff --git a/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Dtos/V1/CreateBookingRequestDto.cs b/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Dtos/V1/CreateBookingRequestDto.cs new file mode 100644 index 0000000..9fe7a91 --- /dev/null +++ b/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Dtos/V1/CreateBookingRequestDto.cs @@ -0,0 +1,3 @@ +namespace Booking.Booking.Features.CreateBooking.Dtos.V1; + +public record CreateBookingRequestDto(long PassengerId, long FlightId, string Description); diff --git a/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Endpoints/V1/CreateBookingEndpoint.cs b/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Endpoints/V1/CreateBookingEndpoint.cs index 130b9af..80f5d11 100644 --- a/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Endpoints/V1/CreateBookingEndpoint.cs +++ b/src/Services/Booking/src/Booking/Booking/Features/CreateBooking/Endpoints/V1/CreateBookingEndpoint.cs @@ -1,5 +1,7 @@ using Booking.Booking.Features.CreateBooking.Commands.V1; +using Booking.Booking.Features.CreateBooking.Dtos.V1; using BuildingBlocks.Web; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; @@ -9,6 +11,7 @@ using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; namespace Booking.Booking.Features.CreateBooking.Endpoints.V1; + public class CreateBookingEndpoint : IMinimalEndpoint { public IEndpointRouteBuilder MapEndpoint(IEndpointRouteBuilder endpoints) @@ -27,8 +30,11 @@ public class CreateBookingEndpoint : IMinimalEndpoint return endpoints; } - private async Task CreateBooking(CreateBookingCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task CreateBooking(CreateBookingRequestDto request, IMediator mediator, IMapper mapper, + CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); diff --git a/src/Services/Booking/src/Booking/Booking/Models/Booking.cs b/src/Services/Booking/src/Booking/Booking/Models/Booking.cs index ab14f85..22e9ade 100644 --- a/src/Services/Booking/src/Booking/Booking/Models/Booking.cs +++ b/src/Services/Booking/src/Booking/Booking/Models/Booking.cs @@ -1,8 +1,6 @@ using Booking.Booking.Features.CreateBooking.Events.Domain.V1; using Booking.Booking.Models.ValueObjects; using BuildingBlocks.EventStoreDB.Events; -using BuildingBlocks.Utils; -using Microsoft.AspNetCore.Http; namespace Booking.Booking.Models; diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index 55f1a9f..3328456 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -92,13 +92,12 @@ public static class InfrastructureExtensions var env = app.Environment; var appOptions = app.GetOptions("AppOptions"); + app.UseProblemDetails(); app.UseSerilogRequestLogging(); app.UseCorrelationId(); app.UseRouting(); app.UseHttpMetrics(); app.UseHttpsRedirection(); - - app.UseProblemDetails(); app.UseCustomHealthCheck(); app.MapMetrics(); app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name)); diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/MediatRExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/MediatRExtensions.cs index f4bda39..042ed3f 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/MediatRExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/MediatRExtensions.cs @@ -10,8 +10,8 @@ public static class MediatRExtensions public static IServiceCollection AddCustomMediatR(this IServiceCollection services) { services.AddMediatR(typeof(BookingRoot).Assembly); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); return services; } diff --git a/src/Services/Flight/src/Flight/Aircrafts/Dtos/AircraftResponseDto.cs b/src/Services/Flight/src/Flight/Aircrafts/Dtos/AircraftResponseDto.cs index 00e9ff1..2781c2e 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Dtos/AircraftResponseDto.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Dtos/AircraftResponseDto.cs @@ -1,9 +1,3 @@ namespace Flight.Aircrafts.Dtos; -public record AircraftResponseDto -{ - public long Id { get; set; } - public string Name { get; init; } - public string Model { get; init; } - public int ManufacturingYear { get; init; } -} +public record AircraftResponseDto(long Id, string Name, string Model, int ManufacturingYear); diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs index 695ad9d..a1069e2 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs @@ -1,7 +1,10 @@ using BuildingBlocks.IdsGenerator; +using Flight.Aircrafts.Features.CreateAircraft.Commands.V1; using Flight.Aircrafts.Features.CreateAircraft.Commands.V1.Reads; +using Flight.Aircrafts.Features.CreateAircraft.Dtos.V1; using Flight.Aircrafts.Models; using Flight.Aircrafts.Models.Reads; +using Flight.Airports.Features.CreateAirport.Commands.V1; using Mapster; namespace Flight.Aircrafts.Features; @@ -17,5 +20,8 @@ public class AircraftMappings : IRegister config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.AircraftId, s => s.Id); + + config.NewConfig() + .ConstructUsing(x => new CreateAircraftCommand(x.Name, x.Model, x.ManufacturingYear)); } } diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommand.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommand.cs index efdf3f7..b032c85 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommand.cs @@ -2,21 +2,4 @@ namespace Flight.Aircrafts.Features.CreateAircraft.Commands.V1.Reads; -public class CreateAircraftMongoCommand : InternalCommand -{ - public CreateAircraftMongoCommand(long id, string name, string model, int manufacturingYear, bool isDeleted) - { - Id = id; - Name = name; - Model = model; - ManufacturingYear = manufacturingYear; - IsDeleted = isDeleted; - } - - - public long Id { get; } - public string Name { get; } - public string Model { get; } - public int ManufacturingYear { get; } - public bool IsDeleted { get; } -} +public record CreateAircraftMongoCommand(long Id, string Name, string Model, int ManufacturingYear, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommandHandler.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommandHandler.cs index c1efb94..80b0bbf 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommandHandler.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Commands/V1/Reads/CreateAircraftMongoCommandHandler.cs @@ -32,7 +32,7 @@ public class CreateAircraftMongoCommandHandler : ICommandHandler(command); var aircraft = await _flightReadDbContext.Aircraft.AsQueryable() - .FirstOrDefaultAsync(x => x.Id == aircraftReadModel.Id, cancellationToken); + .FirstOrDefaultAsync(x => x.AircraftId == aircraftReadModel.AircraftId, cancellationToken); if (aircraft is not null) throw new AircraftAlreadyExistException(); diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Dtos/V1/CreateAircraftRequestDto.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Dtos/V1/CreateAircraftRequestDto.cs new file mode 100644 index 0000000..c9ece02 --- /dev/null +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Dtos/V1/CreateAircraftRequestDto.cs @@ -0,0 +1,4 @@ +namespace Flight.Aircrafts.Features.CreateAircraft.Dtos.V1; + +public record CreateAircraftRequestDto(string Name, string Model, int ManufacturingYear); + diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Endpoints/V1/CreateAircraftEndpoint.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Endpoints/V1/CreateAircraftEndpoint.cs index baa9e78..a58fb69 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Endpoints/V1/CreateAircraftEndpoint.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreateAircraft/Endpoints/V1/CreateAircraftEndpoint.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using BuildingBlocks.Web; using Flight.Aircrafts.Dtos; using Flight.Aircrafts.Features.CreateAircraft.Commands.V1; +using Flight.Aircrafts.Features.CreateAircraft.Dtos.V1; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -29,8 +31,11 @@ public class CreateAircraftEndpoint : IMinimalEndpoint return endpoints; } - private async Task CreateAircraft(CreateAircraftCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task CreateAircraft(CreateAircraftRequestDto request, IMediator mediator, IMapper mapper, + CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); diff --git a/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs b/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs index 592605e..6a67276 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs @@ -6,10 +6,6 @@ namespace Flight.Aircrafts.Models; public record Aircraft : Aggregate { - public Aircraft() - { - } - public string Name { get; private set; } public string Model { get; private set; } public int ManufacturingYear { get; private set; } diff --git a/src/Services/Flight/src/Flight/Airports/AirportMappings.cs b/src/Services/Flight/src/Flight/Airports/AirportMappings.cs index 9118285..14c37e3 100644 --- a/src/Services/Flight/src/Flight/Airports/AirportMappings.cs +++ b/src/Services/Flight/src/Flight/Airports/AirportMappings.cs @@ -1,5 +1,7 @@ using BuildingBlocks.IdsGenerator; +using Flight.Airports.Features.CreateAirport.Commands.V1; using Flight.Airports.Features.CreateAirport.Commands.V1.Reads; +using Flight.Airports.Features.CreateAirport.Dtos.V1; using Flight.Airports.Models; using Flight.Airports.Models.Reads; using Mapster; @@ -17,5 +19,8 @@ public class AirportMappings : IRegister config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.AirportId, s => s.Id); + + config.NewConfig() + .ConstructUsing(x => new CreateAirportCommand(x.Name, x.Address, x.Code)); } } diff --git a/src/Services/Flight/src/Flight/Airports/Dtos/AirportResponseDto.cs b/src/Services/Flight/src/Flight/Airports/Dtos/AirportResponseDto.cs index fc9ca89..e5d4270 100644 --- a/src/Services/Flight/src/Flight/Airports/Dtos/AirportResponseDto.cs +++ b/src/Services/Flight/src/Flight/Airports/Dtos/AirportResponseDto.cs @@ -1,8 +1,3 @@ namespace Flight.Airports.Dtos; -public record AirportResponseDto -{ - public long Id { get; set; } - public string Name { get; init; } - public string Address { get; init; } - public string Code { get; init; } -} + +public record AirportResponseDto(long Id, string Name, string Address, string Code); diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommand.cs b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommand.cs index cfbc48c..61323d5 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommand.cs @@ -2,19 +2,4 @@ namespace Flight.Airports.Features.CreateAirport.Commands.V1.Reads; -public class CreateAirportMongoCommand : InternalCommand -{ - public CreateAirportMongoCommand(long id, string name, string address, string code, bool isDeleted) - { - Id = id; - Name = name; - Address = address; - Code = code; - IsDeleted = isDeleted; - } - - public string Name { get; } - public string Address { get; } - public string Code { get; } - public bool IsDeleted { get; } -} +public record CreateAirportMongoCommand(long Id, string Name, string Address, string Code, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommandHandler.cs b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommandHandler.cs index 6dc3de1..42dd920 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommandHandler.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Commands/V1/Reads/CreateAirportMongoCommandHandler.cs @@ -32,7 +32,7 @@ public class CreateAirportMongoCommandHandler : ICommandHandler(command); var aircraft = await _flightReadDbContext.Airport.AsQueryable() - .FirstOrDefaultAsync(x => x.Id == airportReadModel.Id, cancellationToken); + .FirstOrDefaultAsync(x => x.AirportId == airportReadModel.AirportId, cancellationToken); if (aircraft is not null) throw new AirportAlreadyExistException(); diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Dtos/V1/CreateAirportRequestDto.cs b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Dtos/V1/CreateAirportRequestDto.cs new file mode 100644 index 0000000..0a9ea0e --- /dev/null +++ b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Dtos/V1/CreateAirportRequestDto.cs @@ -0,0 +1,3 @@ +namespace Flight.Airports.Features.CreateAirport.Dtos.V1; + +public record CreateAirportRequestDto(string Name, string Address, string Code); diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Endpoints/V1/CreateAirportEndpoint.cs b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Endpoints/V1/CreateAirportEndpoint.cs index 4862435..b353783 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Endpoints/V1/CreateAirportEndpoint.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreateAirport/Endpoints/V1/CreateAirportEndpoint.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using BuildingBlocks.Web; using Flight.Airports.Dtos; using Flight.Airports.Features.CreateAirport.Commands.V1; +using Flight.Airports.Features.CreateAirport.Dtos.V1; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -29,8 +31,11 @@ public class CreateAirportEndpoint : IMinimalEndpoint return endpoints; } - private async Task CreateAirport(CreateAirportCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task CreateAirport(CreateAirportRequestDto request, IMediator mediator, IMapper mapper, + CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); diff --git a/src/Services/Flight/src/Flight/Airports/Models/Airport.cs b/src/Services/Flight/src/Flight/Airports/Models/Airport.cs index ae2a0b5..493bf52 100644 --- a/src/Services/Flight/src/Flight/Airports/Models/Airport.cs +++ b/src/Services/Flight/src/Flight/Airports/Models/Airport.cs @@ -6,10 +6,6 @@ namespace Flight.Airports.Models; public record Airport : Aggregate { - public Airport() - { - } - public string Name { get; private set; } public string Address { get; private set; } public string Code { get; private set; } diff --git a/src/Services/Flight/src/Flight/Airports/Models/Reads/AirportReadModel.cs b/src/Services/Flight/src/Flight/Airports/Models/Reads/AirportReadModel.cs index e94d320..515c836 100644 --- a/src/Services/Flight/src/Flight/Airports/Models/Reads/AirportReadModel.cs +++ b/src/Services/Flight/src/Flight/Airports/Models/Reads/AirportReadModel.cs @@ -7,5 +7,5 @@ public class AirportReadModel public string Name { get; init; } public string Address { get; init; } public string Code { get; init; } - public bool IsDeleted { get; set; } + public bool IsDeleted { get; init; } } diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index f6d7604..bdca307 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -90,8 +90,6 @@ public static class InfrastructureExtensions SnowFlakIdGenerator.Configure(1); - builder.Services.AddCachingRequest(new List {typeof(FlightRoot).Assembly}); - builder.Services.AddEasyCaching(options => { options.UseInMemory(configuration, "mem"); }); return builder; @@ -103,11 +101,11 @@ public static class InfrastructureExtensions var env = app.Environment; var appOptions = app.GetOptions("AppOptions"); + app.UseProblemDetails(); app.UseSerilogRequestLogging(); app.UseCorrelationId(); app.UseHttpMetrics(); app.UseMigration(env); - app.UseProblemDetails(); app.UseHttpsRedirection(); app.MapMetrics(); app.UseCustomHealthCheck(); diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/MediatRExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/MediatRExtensions.cs index 540ae22..9b565e4 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/MediatRExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/MediatRExtensions.cs @@ -12,10 +12,11 @@ public static class MediatRExtensions public static IServiceCollection AddCustomMediatR(this IServiceCollection services) { services.AddMediatR(typeof(FlightRoot).Assembly); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(EfTxBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(EfTxBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(InvalidateCachingBehavior<,>)); return services; } diff --git a/src/Services/Flight/src/Flight/Flights/Dtos/FlightResponseDto.cs b/src/Services/Flight/src/Flight/Flights/Dtos/FlightResponseDto.cs index a707d1d..0630de8 100644 --- a/src/Services/Flight/src/Flight/Flights/Dtos/FlightResponseDto.cs +++ b/src/Services/Flight/src/Flight/Flights/Dtos/FlightResponseDto.cs @@ -2,18 +2,7 @@ using System; using Flight.Flights.Models; namespace Flight.Flights.Dtos; -public record FlightResponseDto -{ - public long Id { get; init; } - public string FlightNumber { get; init; } - public long FlightId { get; set; } - public long AircraftId { get; init; } - public long DepartureAirportId { get; init; } - public DateTime DepartureDate { get; init; } - public DateTime ArriveDate { get; init; } - public long ArriveAirportId { get; init; } - public decimal DurationMinutes { get; init; } - public DateTime FlightDate { get; init; } - public Enums.FlightStatus Status { get; init; } - public decimal Price { get; init; } -} + +public record FlightResponseDto(long Id, string FlightNumber, long AircraftId, long DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, + Enums.FlightStatus Status, decimal Price); diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs index c176dfe..0673242 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/CreateFlightCommandHandler.cs @@ -40,6 +40,8 @@ public class CreateFlightCommandHandler : ICommandHandler(newFlight.Entity); + var f = _mapper.Map(newFlight.Entity); + + return f; } } diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommand.cs b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommand.cs index 8498e57..4f84f12 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommand.cs @@ -3,36 +3,6 @@ using BuildingBlocks.Core.Event; namespace Flight.Flights.Features.CreateFlight.Commands.V1.Reads; -public class CreateFlightMongoCommand : InternalCommand -{ - public CreateFlightMongoCommand(long id, string flightNumber, long aircraftId, DateTime departureDate, - long departureAirportId, - DateTime arriveDate, long arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, - decimal price, bool isDeleted) - { - Id = id; - FlightNumber = flightNumber; - AircraftId = aircraftId; - DepartureDate = departureDate; - DepartureAirportId = departureAirportId; - ArriveDate = arriveDate; - ArriveAirportId = arriveAirportId; - DurationMinutes = durationMinutes; - FlightDate = flightDate; - Status = status; - Price = price; - IsDeleted = isDeleted; - } - - public string FlightNumber { get; } - public long AircraftId { get; } - public DateTime DepartureDate { get; } - public long DepartureAirportId { get; } - public DateTime ArriveDate { get; } - public long ArriveAirportId { get; } - public decimal DurationMinutes { get; } - public DateTime FlightDate { get; } - public Enums.FlightStatus Status { get; } - public decimal Price { get; } - public bool IsDeleted { get; } -} +public record CreateFlightMongoCommand(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, + long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, + Enums.FlightStatus Status, decimal Price, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommandHandler.cs b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommandHandler.cs index b484200..4321e88 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommandHandler.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Commands/V1/Reads/CreateFlightMongoCommandHandler.cs @@ -33,7 +33,7 @@ public class CreateFlightMongoCommandHandler : ICommandHandler(command); var flight = await _flightReadDbContext.Flight.AsQueryable() - .FirstOrDefaultAsync(x => x.Id == flightReadModel.Id && !x.IsDeleted, cancellationToken); + .FirstOrDefaultAsync(x => x.FlightId == flightReadModel.FlightId && !x.IsDeleted, cancellationToken); if (flight is not null) throw new FlightAlreadyExistException(); diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Dtos/V1/CreateFlightRequestDto.cs b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Dtos/V1/CreateFlightRequestDto.cs new file mode 100644 index 0000000..b343e36 --- /dev/null +++ b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Dtos/V1/CreateFlightRequestDto.cs @@ -0,0 +1,7 @@ +using System; + +namespace Flight.Flights.Features.CreateFlight.Dtos.V1; + +public record CreateFlightRequestDto(string FlightNumber, long AircraftId, long DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, + decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price); diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Endpoints/V1/CreateFlightEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Endpoints/V1/CreateFlightEndpoint.cs index 0e64592..7ce5419 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Endpoints/V1/CreateFlightEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreateFlight/Endpoints/V1/CreateFlightEndpoint.cs @@ -3,6 +3,9 @@ using System.Threading.Tasks; using BuildingBlocks.Web; using Flight.Flights.Dtos; using Flight.Flights.Features.CreateFlight.Commands.V1; +using Flight.Flights.Features.CreateFlight.Dtos.V1; +using Mapster; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -29,8 +32,11 @@ public class CreateFlightEndpoint : IMinimalEndpoint return endpoints; } - private async Task CreateFlight(CreateFlightCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task CreateFlight(CreateFlightRequestDto request, IMediator mediator, IMapper mapper, + CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); diff --git a/src/Services/Flight/src/Flight/Flights/Features/DeleteFlight/Commands/V1/Reads/DeleteFlightMongoCommand.cs b/src/Services/Flight/src/Flight/Flights/Features/DeleteFlight/Commands/V1/Reads/DeleteFlightMongoCommand.cs index 06b0837..8dfca0b 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/DeleteFlight/Commands/V1/Reads/DeleteFlightMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/DeleteFlight/Commands/V1/Reads/DeleteFlightMongoCommand.cs @@ -3,36 +3,6 @@ using BuildingBlocks.Core.Event; namespace Flight.Flights.Features.DeleteFlight.Commands.V1.Reads; -public class DeleteFlightMongoCommand : InternalCommand -{ - public DeleteFlightMongoCommand(long id, string flightNumber, long aircraftId, DateTime departureDate, - long departureAirportId, - DateTime arriveDate, long arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, - decimal price, bool isDeleted) - { - Id = id; - FlightNumber = flightNumber; - AircraftId = aircraftId; - DepartureDate = departureDate; - DepartureAirportId = departureAirportId; - ArriveDate = arriveDate; - ArriveAirportId = arriveAirportId; - DurationMinutes = durationMinutes; - FlightDate = flightDate; - Status = status; - Price = price; - IsDeleted = isDeleted; - } - - public string FlightNumber { get; } - public long AircraftId { get; } - public DateTime DepartureDate { get; } - public long DepartureAirportId { get; } - public DateTime ArriveDate { get; } - public long ArriveAirportId { get; } - public decimal DurationMinutes { get; } - public DateTime FlightDate { get; } - public Enums.FlightStatus Status { get; } - public decimal Price { get; } - public bool IsDeleted { get; } -} +public record DeleteFlightMongoCommand(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, + long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, + Enums.FlightStatus Status, decimal Price, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs b/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs index e733305..cd223ae 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs @@ -1,9 +1,13 @@ using AutoMapper; using BuildingBlocks.IdsGenerator; using Flight.Flights.Dtos; +using Flight.Flights.Features.CreateFlight.Commands.V1; using Flight.Flights.Features.CreateFlight.Commands.V1.Reads; +using Flight.Flights.Features.CreateFlight.Dtos.V1; using Flight.Flights.Features.DeleteFlight.Commands.V1.Reads; +using Flight.Flights.Features.UpdateFlight.Commands.V1; using Flight.Flights.Features.UpdateFlight.Commands.V1.Reads; +using Flight.Flights.Features.UpdateFlight.Dtos; using Flight.Flights.Models.Reads; using Mapster; @@ -14,16 +18,30 @@ public class FlightMappings : IRegister public void Register(TypeAdapterConfig config) { config.NewConfig() - .Map(d => d.FlightId, s => s.Id); + .ConstructUsing(x => new FlightResponseDto(x.Id, x.FlightNumber, x.AircraftId, x.DepartureAirportId, x.DepartureDate, + x.ArriveDate, x.ArriveAirportId, x.DurationMinutes, x.FlightDate, x.Status, x.Price)); + config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.FlightId, s => s.Id); + config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.FlightId, s => s.Id); + config.NewConfig() .Map(d => d.FlightId, s => s.Id); + config.NewConfig() .Map(d => d.FlightId, s => s.Id); + + config.NewConfig() + .ConstructUsing(x => new CreateFlightCommand(x.FlightNumber, x.AircraftId, x.DepartureAirportId, + x.DepartureDate, x.ArriveDate, x.ArriveAirportId, x.DurationMinutes, x.FlightDate, x.Status, x.Price)); + + config.NewConfig() + .ConstructUsing(x => new UpdateFlightCommand(x.Id, x.FlightNumber, x.AircraftId, x.DepartureAirportId, x.DepartureDate, + x.ArriveDate, x.ArriveAirportId, x.DurationMinutes, x.FlightDate, x.Status, x.IsDeleted, x.Price)); + } } diff --git a/src/Services/Flight/src/Flight/Flights/Features/GetAvailableFlights/Endpoints/V1/GetAvailableFlightsEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/GetAvailableFlights/Endpoints/V1/GetAvailableFlightsEndpoint.cs index 3cbf21c..5646d1f 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/GetAvailableFlights/Endpoints/V1/GetAvailableFlightsEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/GetAvailableFlights/Endpoints/V1/GetAvailableFlightsEndpoint.cs @@ -36,4 +36,4 @@ public class GetAvailableFlightsEndpoint : IMinimalEndpoint return Results.Ok(result); } -} \ No newline at end of file +} diff --git a/src/Services/Flight/src/Flight/Flights/Features/GetFlightById/Endpoints/V1/GetFlightByIdEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/GetFlightById/Endpoints/V1/GetFlightByIdEndpoint.cs index c494576..1e31385 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/GetFlightById/Endpoints/V1/GetFlightByIdEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/GetFlightById/Endpoints/V1/GetFlightByIdEndpoint.cs @@ -1,29 +1,3 @@ -// using System.Threading; -// using System.Threading.Tasks; -// using BuildingBlocks.Web; -// using Flight.Flights.Features.GetFlightById.Queries.V1; -// using Microsoft.AspNetCore.Authorization; -// using Microsoft.AspNetCore.Http; -// using Microsoft.AspNetCore.Mvc; -// using Swashbuckle.AspNetCore.Annotations; -// -// namespace Flight.Flights.Features.GetFlightById.Endpoints.V1; -// -// [Route(BaseApiPath + "/flight")] -// public class GetFlightByIdEndpoint : BaseController -// { -// [Authorize] -// [HttpGet("{id}")] -// [ProducesResponseType(StatusCodes.Status200OK)] -// [ProducesResponseType(StatusCodes.Status400BadRequest)] -// [SwaggerOperation(Summary = "Get flight by id", Description = "Get flight by id")] -// public async Task GetById([FromRoute] GetFlightByIdQuery query, CancellationToken cancellationToken) -// { -// var result = await Mediator.Send(query, cancellationToken); -// return Ok(result); -// } -// } - using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -61,4 +35,4 @@ public class GetFlightByIdEndpoint : IMinimalEndpoint return Results.Ok(result); } -} \ No newline at end of file +} diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/Reads/UpdateFlightMongoCommand.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/Reads/UpdateFlightMongoCommand.cs index 4f07624..2d43110 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/Reads/UpdateFlightMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/Reads/UpdateFlightMongoCommand.cs @@ -3,36 +3,6 @@ using BuildingBlocks.Core.Event; namespace Flight.Flights.Features.UpdateFlight.Commands.V1.Reads; -public class UpdateFlightMongoCommand : InternalCommand -{ - public UpdateFlightMongoCommand(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, - DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, - decimal Price, bool IsDeleted) - { - this.Id = Id; - this.FlightNumber = FlightNumber; - this.AircraftId = AircraftId; - this.DepartureDate = DepartureDate; - this.DepartureAirportId = DepartureAirportId; - this.ArriveDate = ArriveDate; - this.ArriveAirportId = ArriveAirportId; - this.DurationMinutes = DurationMinutes; - this.FlightDate = FlightDate; - this.Status = Status; - this.Price = Price; - this.IsDeleted = IsDeleted; - } - - public string FlightNumber { get; } - public long AircraftId { get; } - public DateTime DepartureDate { get; } - public long DepartureAirportId { get; } - public DateTime ArriveDate { get; } - public long ArriveAirportId { get; } - public decimal DurationMinutes { get; } - public DateTime FlightDate { get; } - public Enums.FlightStatus Status { get; } - public decimal Price { get; } - public bool IsDeleted { get; } -} +public record UpdateFlightMongoCommand(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, + long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, + Enums.FlightStatus Status, decimal Price, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/UpdateFlightCommand.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/UpdateFlightCommand.cs index 0cc5ba4..f62daef 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/UpdateFlightCommand.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Commands/V1/UpdateFlightCommand.cs @@ -6,21 +6,9 @@ using Flight.Flights.Dtos; namespace Flight.Flights.Features.UpdateFlight.Commands.V1; -public record UpdateFlightCommand : ICommand, IInvalidateCacheRequest, IInternalCommand +public record UpdateFlightCommand(long Id, string FlightNumber, long AircraftId, long DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, + Enums.FlightStatus Status, bool IsDeleted, decimal Price) : ICommand, IInternalCommand, IInvalidateCacheRequest { - public long Id { get; init; } - public string FlightNumber { get; init; } - public long AircraftId { get; init; } - public long DepartureAirportId { get; init; } - public DateTime DepartureDate { get; init; } - public DateTime ArriveDate { get; init; } - public long ArriveAirportId { get; init; } - public decimal DurationMinutes { get; init; } - public DateTime FlightDate { get; init; } - - public Enums.FlightStatus Status { get; init; } - - public bool IsDeleted { get; init; } = false; - public decimal Price { get; init; } public string CacheKey => "GetAvailableFlightsQuery"; } diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Dtos/UpdateFlightRequestDto.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Dtos/UpdateFlightRequestDto.cs new file mode 100644 index 0000000..a4be2e2 --- /dev/null +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Dtos/UpdateFlightRequestDto.cs @@ -0,0 +1,6 @@ +using System; + +namespace Flight.Flights.Features.UpdateFlight.Dtos; + +public record UpdateFlightRequestDto(long Id, string FlightNumber, long AircraftId, long DepartureAirportId, DateTime DepartureDate, DateTime ArriveDate, + long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted); diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Endpoints/V1/UpdateFlightEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Endpoints/V1/UpdateFlightEndpoint.cs index 493ab76..a16dad8 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Endpoints/V1/UpdateFlightEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdateFlight/Endpoints/V1/UpdateFlightEndpoint.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using BuildingBlocks.Web; using Flight.Flights.Dtos; using Flight.Flights.Features.UpdateFlight.Commands.V1; +using Flight.Flights.Features.UpdateFlight.Dtos; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -29,10 +31,12 @@ public class UpdateFlightEndpoint : IMinimalEndpoint return endpoints; } - private async Task UpdateFlight(UpdateFlightCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task UpdateFlight(UpdateFlightRequestDto request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); } -} \ No newline at end of file +} diff --git a/src/Services/Flight/src/Flight/Flights/Models/Reads/FlightReadModel.cs b/src/Services/Flight/src/Flight/Flights/Models/Reads/FlightReadModel.cs index 3699e13..fb3fdcd 100644 --- a/src/Services/Flight/src/Flight/Flights/Models/Reads/FlightReadModel.cs +++ b/src/Services/Flight/src/Flight/Flights/Models/Reads/FlightReadModel.cs @@ -1,6 +1,4 @@ using System; -using MongoDB.Bson; -using MongoDB.Bson.Serialization.Attributes; namespace Flight.Flights.Models.Reads; diff --git a/src/Services/Flight/src/Flight/Seats/Dtos/SeatResponseDto.cs b/src/Services/Flight/src/Flight/Seats/Dtos/SeatResponseDto.cs index bdfb1e3..1fe3d49 100644 --- a/src/Services/Flight/src/Flight/Seats/Dtos/SeatResponseDto.cs +++ b/src/Services/Flight/src/Flight/Seats/Dtos/SeatResponseDto.cs @@ -1,12 +1,3 @@ -using Flight.Seats.Models; - namespace Flight.Seats.Dtos; -public record SeatResponseDto -{ - public long Id { get; set; } - public string SeatNumber { get; init; } - public Enums.SeatType Type { get; init; } - public Enums.SeatClass Class { get; init; } - public long FlightId { get; init; } -} +public record SeatResponseDto(long Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId); diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommand.cs b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommand.cs index dc94bc1..df4cc59 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommand.cs @@ -2,23 +2,5 @@ namespace Flight.Seats.Features.CreateSeat.Commands.V1.Reads; -public class CreateSeatMongoCommand : InternalCommand -{ - public CreateSeatMongoCommand(long id, string seatNumber, Enums.SeatType type, Enums.SeatClass @class, - long flightId, bool isDeleted) - { - Id = id; - SeatNumber = seatNumber; - Type = type; - Class = @class; - FlightId = flightId; - IsDeleted = isDeleted; - } - - public long Id { get; } - public string SeatNumber { get; } - public Enums.SeatType Type { get; } - public Enums.SeatClass Class { get; } - public long FlightId { get; } - public bool IsDeleted { get; } -} +public record CreateSeatMongoCommand(long Id, string SeatNumber, Enums.SeatType Type, + Enums.SeatClass Class, long FlightId, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommandHandler.cs b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommandHandler.cs index 5658e43..66a7e7f 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommandHandler.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Commands/V1/Reads/CreateSeatMongoCommandHandler.cs @@ -32,7 +32,7 @@ public class CreateSeatMongoCommandHandler : ICommandHandler(command); var seat = await _flightReadDbContext.Seat.AsQueryable() - .FirstOrDefaultAsync(x => x.Id == seatReadModel.Id, cancellationToken); + .FirstOrDefaultAsync(x => x.SeatId == seatReadModel.SeatId, cancellationToken); if (seat is not null) throw new SeatAlreadyExistException(); diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Dtos/V1/CreateSeatRequestDto.cs b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Dtos/V1/CreateSeatRequestDto.cs new file mode 100644 index 0000000..e176ddc --- /dev/null +++ b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Dtos/V1/CreateSeatRequestDto.cs @@ -0,0 +1,3 @@ +namespace Flight.Seats.Features.CreateSeat.Dtos.V1; + +public record CreateSeatRequestDto(string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId); diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Endpoints/V1/CreateSeatEndpoint.cs b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Endpoints/V1/CreateSeatEndpoint.cs index aa72759..eed51ad 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Endpoints/V1/CreateSeatEndpoint.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreateSeat/Endpoints/V1/CreateSeatEndpoint.cs @@ -1,34 +1,10 @@ -// using System.Threading; -// using System.Threading.Tasks; -// using BuildingBlocks.Web; -// using Flight.Seats.Features.CreateSeat.Commands.V1; -// using Microsoft.AspNetCore.Http; -// using Microsoft.AspNetCore.Mvc; -// using Swashbuckle.AspNetCore.Annotations; -// -// namespace Flight.Seats.Features.CreateSeat.Endpoints.V1; -// -// [Route(BaseApiPath + "/flight/seat")] -// public class CreateSeatEndpoint : BaseController -// { -// [HttpPost] -// [ProducesResponseType(StatusCodes.Status201Created)] -// [ProducesResponseType(StatusCodes.Status400BadRequest)] -// [SwaggerOperation(Summary = "Create new seat", Description = "Create new seat")] -// public async Task Create(CreateSeatCommand command, CancellationToken cancellationToken) -// { -// var result = await Mediator.Send(command, cancellationToken); -// -// return Ok(result); -// } -// } - - using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; using Flight.Seats.Dtos; using Flight.Seats.Features.CreateSeat.Commands.V1; +using Flight.Seats.Features.CreateSeat.Dtos.V1; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -55,10 +31,13 @@ public class CreateSeatEndpoint : IMinimalEndpoint return endpoints; } - private async Task CreateSeat(CreateSeatCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task CreateSeat(CreateSeatRequestDto request, IMediator mediator, IMapper mapper, + CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); } -} \ No newline at end of file +} diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Commands/V1/Reads/ReserveSeatMongoCommand.cs b/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Commands/V1/Reads/ReserveSeatMongoCommand.cs index fdf77d5..ebc6a4c 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Commands/V1/Reads/ReserveSeatMongoCommand.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Commands/V1/Reads/ReserveSeatMongoCommand.cs @@ -2,22 +2,5 @@ namespace Flight.Seats.Features.ReserveSeat.Commands.V1.Reads; -public class ReserveSeatMongoCommand : InternalCommand -{ - public ReserveSeatMongoCommand(long id, string seatNumber, Enums.SeatType type, Enums.SeatClass @class, long flightId, - bool isDeleted) - { - Id = id; - SeatNumber = seatNumber; - Type = type; - Class = @class; - FlightId = flightId; - IsDeleted = isDeleted; - } - - public string SeatNumber { get; } - public Enums.SeatType Type { get; } - public Enums.SeatClass Class { get; } - public long FlightId { get; } - public bool IsDeleted { get; } -} +public record ReserveSeatMongoCommand(long Id, string SeatNumber, Enums.SeatType Type, + Enums.SeatClass Class, long FlightId, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Dtos/V1/ReserveSeatRequestDto.cs b/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Dtos/V1/ReserveSeatRequestDto.cs new file mode 100644 index 0000000..7b3ec12 --- /dev/null +++ b/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Dtos/V1/ReserveSeatRequestDto.cs @@ -0,0 +1,4 @@ +namespace Flight.Seats.Features.ReserveSeat.Dtos.V1; + + +public record ReserveSeatRequestDto(long FlightId, string SeatNumber); diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Endpoints/V1/ReserveSeatEndpoint.cs b/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Endpoints/V1/ReserveSeatEndpoint.cs index 7b4848b..1c8be67 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Endpoints/V1/ReserveSeatEndpoint.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/ReserveSeat/Endpoints/V1/ReserveSeatEndpoint.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using BuildingBlocks.Web; using Flight.Seats.Dtos; using Flight.Seats.Features.ReserveSeat.Commands.V1; +using Flight.Seats.Features.ReserveSeat.Dtos.V1; +using MapsterMapper; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -29,10 +31,12 @@ public class ReserveSeatEndpoint : IMinimalEndpoint return endpoints; } - private async Task ReserveSeat(ReserveSeatCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task ReserveSeat(ReserveSeatRequestDto request, IMediator mediator, IMapper mapper, CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); } -} \ No newline at end of file +} diff --git a/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs b/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs index d8db4fb..11443d3 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs @@ -1,7 +1,11 @@ using BuildingBlocks.IdsGenerator; using Flight.Seats.Dtos; +using Flight.Seats.Features.CreateSeat.Commands.V1; using Flight.Seats.Features.CreateSeat.Commands.V1.Reads; +using Flight.Seats.Features.CreateSeat.Dtos.V1; +using Flight.Seats.Features.ReserveSeat.Commands.V1; using Flight.Seats.Features.ReserveSeat.Commands.V1.Reads; +using Flight.Seats.Features.ReserveSeat.Dtos.V1; using Flight.Seats.Models; using Flight.Seats.Models.Reads; using Mapster; @@ -12,14 +16,24 @@ public class SeatMappings : IRegister { public void Register(TypeAdapterConfig config) { - config.NewConfig(); + config.NewConfig() + .ConstructUsing(x => new SeatResponseDto(x.Id, x.SeatNumber, x.Type, x.Class, x.FlightId)); + config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.SeatId, s => s.Id); + config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.SeatId, s => s.Id); + config.NewConfig() .Map(d => d.SeatId, s => s.Id); + + config.NewConfig() + .ConstructUsing(x => new CreateSeatCommand(x.SeatNumber, x.Type, x.Class, x.FlightId)); + + config.NewConfig() + .ConstructUsing(x => new ReserveSeatCommand(x.FlightId, x.SeatNumber)); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs index 90579b0..7efde6a 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeFlightCreated.cs @@ -1,5 +1,4 @@ -using Flight.Flights.Features.CreateFlight; -using Flight.Flights.Features.CreateFlight.Commands.V1; +using Flight.Flights.Features.CreateFlight.Commands.V1; namespace Integration.Test.Fakes; diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs index 819ded5..c1eb678 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs @@ -39,7 +39,7 @@ public class GetFlightByIdTests : IntegrationTestBase("AppOptions"); + app.UseProblemDetails(); app.UseSerilogRequestLogging(); app.UseMigration(env); app.UseCorrelationId(); diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/MediatRExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/MediatRExtensions.cs index 3671165..3ee8384 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/MediatRExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/MediatRExtensions.cs @@ -10,8 +10,8 @@ public static class MediatRExtensions public static IServiceCollection AddCustomMediatR(this IServiceCollection services) { services.AddMediatR(typeof(IdentityRoot).Assembly); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); return services; } diff --git a/src/Services/Identity/src/Identity/Identity/Dtos/RegisterNewUserResponseDto.cs b/src/Services/Identity/src/Identity/Identity/Dtos/RegisterNewUserResponseDto.cs index 00b87b7..35fbda4 100644 --- a/src/Services/Identity/src/Identity/Identity/Dtos/RegisterNewUserResponseDto.cs +++ b/src/Services/Identity/src/Identity/Identity/Dtos/RegisterNewUserResponseDto.cs @@ -1,13 +1,3 @@ -using System; - namespace Identity.Identity.Dtos; -public record RegisterNewUserResponseDto -{ - public long Id { get; init; } - public string FirstName { get; init; } - public string LastName { get; init; } - public string Username { get; init; } - - public string PassportNumber { get; set; } -} +public record RegisterNewUserResponseDto(long Id, string FirstName, string LastName, string Username, string PassportNumber); diff --git a/src/Services/Identity/src/Identity/Identity/Features/IdentityMappings.cs b/src/Services/Identity/src/Identity/Identity/Features/IdentityMappings.cs new file mode 100644 index 0000000..903ebb3 --- /dev/null +++ b/src/Services/Identity/src/Identity/Identity/Features/IdentityMappings.cs @@ -0,0 +1,15 @@ +using Identity.Identity.Features.RegisterNewUser.Commands.V1; +using Identity.Identity.Features.RegisterNewUser.Dtos.V1; +using Mapster; + +namespace Identity.Identity.Features; + +public class IdentityMappings : IRegister +{ + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .ConstructUsing(x => new RegisterNewUserCommand(x.FirstName, x.LastName, x.Username, x.Email, + x.Password, x.ConfirmPassword, x.PassportNumber)); + } +} diff --git a/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Commands/V1/RegisterNewUserCommandHandler.cs b/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Commands/V1/RegisterNewUserCommandHandler.cs index 2ff2f37..6546da5 100644 --- a/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Commands/V1/RegisterNewUserCommandHandler.cs +++ b/src/Services/Identity/src/Identity/Identity/Features/RegisterNewUser/Commands/V1/RegisterNewUserCommandHandler.cs @@ -29,7 +29,7 @@ public class RegisterNewUserCommandHandler : ICommandHandler RegisterNewUser(RegisterNewUserCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task RegisterNewUser(RegisterNewUserRequestDto request, IMediator mediator, IMapper mapper, + CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); diff --git a/src/Services/Identity/src/Identity/Identity/Models/ApplicationUser.cs b/src/Services/Identity/src/Identity/Identity/Models/ApplicationUser.cs index 55fbe95..29bc6dd 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/ApplicationUser.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/ApplicationUser.cs @@ -4,7 +4,7 @@ namespace Identity.Identity.Models; public class ApplicationUser : IdentityUser { - public string FirstName { get; set; } - public string LastName { get; set; } - public string PassPortNumber { get; set; } + public string FirstName { get; init; } + public string LastName { get; init; } + public string PassPortNumber { get; init; } } diff --git a/src/Services/Passenger/src/Passenger.Api/Program.cs b/src/Services/Passenger/src/Passenger.Api/Program.cs index a7e37c2..67a3ae7 100644 --- a/src/Services/Passenger/src/Passenger.Api/Program.cs +++ b/src/Services/Passenger/src/Passenger.Api/Program.cs @@ -1,27 +1,5 @@ -using BuildingBlocks.EFCore; -using BuildingBlocks.Exception; -using BuildingBlocks.HealthCheck; -using BuildingBlocks.IdsGenerator; -using BuildingBlocks.Jwt; -using BuildingBlocks.Logging; -using BuildingBlocks.Mapster; -using BuildingBlocks.MassTransit; -using BuildingBlocks.Mongo; -using BuildingBlocks.OpenTelemetry; -using BuildingBlocks.PersistMessageProcessor; -using BuildingBlocks.Swagger; using BuildingBlocks.Web; -using Figgle; -using FluentValidation; -using Hellang.Middleware.ProblemDetails; -using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Passenger; -using Passenger.Data; -using Passenger.Extensions; using Passenger.Extensions.Infrastructure; -using Passenger.GrpcServer.Services; -using Prometheus; -using Serilog; var builder = WebApplication.CreateBuilder(args); diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index 9c9e3f1..1899bf0 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -91,11 +91,11 @@ public static class InfrastructureExtensions var env = app.Environment; var appOptions = app.GetOptions("AppOptions"); + app.UseProblemDetails(); app.UseSerilogRequestLogging(); app.UseMigration(env); app.UseCorrelationId(); app.UseHttpMetrics(); - app.UseProblemDetails(); app.UseHttpsRedirection(); app.UseCustomHealthCheck(); app.MapMetrics(); diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/MediatRExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/MediatRExtensions.cs index a3fc74b..ec8ca4f 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/MediatRExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/MediatRExtensions.cs @@ -11,9 +11,9 @@ public static class MediatRExtensions public static IServiceCollection AddCustomMediatR(this IServiceCollection services) { services.AddMediatR(typeof(PassengerRoot).Assembly); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); - services.AddScoped(typeof(IPipelineBehavior<,>), typeof(EfTxBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(EfTxBehavior<,>)); return services; } diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommand.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommand.cs index a88231d..bca3943 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommand.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommand.cs @@ -2,22 +2,5 @@ namespace Passenger.Passengers.Features.CompleteRegisterPassenger.Commands.V1.Reads; -public class CompleteRegisterPassengerMongoCommand : InternalCommand -{ - public CompleteRegisterPassengerMongoCommand(long id, string passportNumber, string name, - Enums.PassengerType passengerType, int age, bool isDeleted) - { - Id = id; - PassportNumber = passportNumber; - Name = name; - PassengerType = passengerType; - Age = age; - IsDeleted = isDeleted; - } - - public string PassportNumber { get; } - public string Name { get; } - public Enums.PassengerType PassengerType { get; } - public int Age { get; } - public bool IsDeleted { get; } -} +public record CompleteRegisterPassengerMongoCommand(long Id, string PassportNumber, string Name, + Enums.PassengerType PassengerType, int Age, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommandHandler.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommandHandler.cs index c10688e..a19ec74 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommandHandler.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Commands/V1/Reads/CompleteRegisterPassengerMongoCommandHandler.cs @@ -29,7 +29,7 @@ public class CompleteRegisterPassengerMongoCommandHandler : ICommandHandler(command); var passenger = await _passengerReadDbContext.Passenger.AsQueryable() - .FirstOrDefaultAsync(x => x.PassengerId == command.Id && !x.IsDeleted, cancellationToken); + .FirstOrDefaultAsync(x => x.PassengerId == passengerReadModel.PassengerId && !x.IsDeleted, cancellationToken); if (passenger is not null) { diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Dtos/V1/CompleteRegisterPassengerRequestDto.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Dtos/V1/CompleteRegisterPassengerRequestDto.cs new file mode 100644 index 0000000..6b7b227 --- /dev/null +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Dtos/V1/CompleteRegisterPassengerRequestDto.cs @@ -0,0 +1,3 @@ +namespace Passenger.Passengers.Features.CompleteRegisterPassenger.Dtos.V1; + +public record CompleteRegisterPassengerRequestDto(string PassportNumber, Enums.PassengerType PassengerType, int Age); diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Endpoints/V1/CompleteRegisterPassengerEndpoint.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Endpoints/V1/CompleteRegisterPassengerEndpoint.cs index 8d314a2..869e4fe 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Endpoints/V1/CompleteRegisterPassengerEndpoint.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompleteRegisterPassenger/Endpoints/V1/CompleteRegisterPassengerEndpoint.cs @@ -1,12 +1,12 @@ using BuildingBlocks.Web; +using MapsterMapper; using MediatR; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Passenger.Passengers.Dtos; using Passenger.Passengers.Features.CompleteRegisterPassenger.Commands.V1; +using Passenger.Passengers.Features.CompleteRegisterPassenger.Dtos.V1; using Swashbuckle.AspNetCore.Annotations; namespace Passenger.Passengers.Features.CompleteRegisterPassenger.Endpoints.V1; @@ -29,8 +29,11 @@ public class CompleteRegisterPassengerEndpoint : IMinimalEndpoint return endpoints; } - private async Task CompleteRegisterPassenger(CompleteRegisterPassengerCommand command, IMediator mediator, CancellationToken cancellationToken) + private async Task CompleteRegisterPassenger(CompleteRegisterPassengerRequestDto request, IMapper mapper, + IMediator mediator, CancellationToken cancellationToken) { + var command = mapper.Map(request); + var result = await mediator.Send(command, cancellationToken); return Results.Ok(result); diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs index a8da772..59dcd9b 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs @@ -3,7 +3,9 @@ using BuildingBlocks.Contracts.EventBus.Messages; using BuildingBlocks.IdsGenerator; using Mapster; using Passenger.Passengers.Dtos; +using Passenger.Passengers.Features.CompleteRegisterPassenger.Commands.V1; using Passenger.Passengers.Features.CompleteRegisterPassenger.Commands.V1.Reads; +using Passenger.Passengers.Features.CompleteRegisterPassenger.Dtos.V1; using Passenger.Passengers.Models.Reads; namespace Passenger.Passengers.Features; @@ -15,5 +17,8 @@ public class PassengerMappings : IRegister config.NewConfig() .Map(d => d.Id, s => SnowFlakIdGenerator.NewId()) .Map(d => d.PassengerId, s => s.Id); + + config.NewConfig() + .ConstructUsing(x => new CompleteRegisterPassengerCommand(x.PassportNumber, x.PassengerType, x.Age)); } } diff --git a/src/Services/Passenger/src/Passenger/Passengers/Models/Reads/PassengerReadModel.cs b/src/Services/Passenger/src/Passenger/Passengers/Models/Reads/PassengerReadModel.cs index a45601e..37f71ab 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Models/Reads/PassengerReadModel.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Models/Reads/PassengerReadModel.cs @@ -4,9 +4,9 @@ public class PassengerReadModel { public long Id { get; init; } public long PassengerId { get; init; } - public string PassportNumber { get; private set; } - public string Name { get; private set; } - public Enums.PassengerType PassengerType { get; private set; } - public int Age { get; private set; } + public string PassportNumber { get; init; } + public string Name { get; init; } + public Enums.PassengerType PassengerType { get; init; } + public int Age { get; init; } public bool IsDeleted { get; init; } }