From c60af19a0af328bcf765835cee5a2c6a480cfeaa Mon Sep 17 00:00:00 2001 From: Pc Date: Sat, 1 Apr 2023 02:03:05 +0330 Subject: [PATCH] feat: Use NewId instead of IdGen for generate Id for unique id in distributed system --- booking.rest | 24 ++++---- src/BuildingBlocks/BuildingBlocks.csproj | 1 - .../EventBus.Messages/FlighContracts.cs | 14 ++--- .../EventBus.Messages/IdentityContracts.cs | 2 +- .../EventBus.Messages/PassengerContracts.cs | 4 +- .../EventBus.Messages/ReservationContracts.cs | 2 +- src/BuildingBlocks/Core/Event/IEvent.cs | 5 +- .../Core/Event/InternalCommand.cs | 1 - src/BuildingBlocks/Core/Model/Aggregate.cs | 39 ++++++------- .../Events/AggregateStreamExtensions.cs | 6 +- .../Repository/EventStoreDBRepository.cs | 8 +-- .../Repository/RepositoryExtensions.cs | 8 +-- .../Exception/AggregateNotFoundException.cs | 4 +- .../IdsGenerator/SnowflakeIdGenerator.cs | 35 ------------ ....cs => 20230331173133_initial.Designer.cs} | 8 +-- ...3_initial.cs => 20230331173133_initial.cs} | 2 +- .../PersistMessageDbContextModelSnapshot.cs | 6 +- .../IPersistMessageProcessor.cs | 8 +-- .../PersistMessageProcessor/PersistMessage.cs | 4 +- .../PersistMessageProcessor.cs | 15 +++-- src/BuildingBlocks/TestBase/TestBase.cs | 2 +- src/Services/Booking/src/Booking.Api/.env | 1 - .../Booking/Booking/Dtos/CreateReservation.cs | 4 +- .../Commands/V1/BookingCreatedDomainEvent.cs | 2 +- .../CreatingBook/Commands/V1/CreateBooking.cs | 24 ++++---- .../Commands/V1/CreateBookingEndpoint.cs | 2 +- .../src/Booking/Booking/Models/Booking.cs | 4 +- .../Models/{Reads => }/BookingReadModel.cs | 8 +-- .../Booking/Models/ValueObjects/Trip.cs | 2 +- .../Booking/src/Booking/BookingProjection.cs | 6 +- .../src/Booking/Data/BookingReadDbContext.cs | 5 +- .../InfrastructureExtensions.cs | 3 - .../Booking/GrpcClient/Protos/flight.proto | 43 ++++++++------ .../Booking/GrpcClient/Protos/passenger.proto | 10 +++- .../Booking/Features/CreateBookingTests.cs | 11 ++-- .../Fakes/FakeCreateBookingCommand.cs | 9 +-- .../Fakes/FakeFlightResponse.cs | 32 +++++++---- .../Fakes/FakeGetAvailableSeatsResponse.cs | 36 ++++++++++++ .../Fakes/FakePassengerResponse.cs | 23 +++++--- .../Fakes/FakeReserveSeatResponse.cs | 14 +++++ .../Fakes/FakeSeatsResponsecs.cs | 33 ----------- src/Services/Flight/src/Flight.Api/.env | 1 - .../Aircrafts/Features/AircraftMappings.cs | 8 +-- .../V1/AircraftCreatedDomainEvent.cs | 3 +- .../CreatingAircraft/V1/CreateAircraft.cs | 13 ++--- .../V1/CreateAircraftEndpoint.cs | 3 +- .../V1/CreateAircraftMongo.cs | 3 +- .../src/Flight/Aircrafts/Models/Aircraft.cs | 5 +- .../Aircrafts/Models/AircraftReadModel.cs | 6 +- .../Airports/Features/AirportMappings.cs | 10 ++-- .../V1/AirportCreatedDomainEvent.cs | 3 +- .../CreatingAirport/V1/CreateAirport.cs | 9 ++- .../V1/CreateAirportEndpoint.cs | 3 +- .../CreatingAirport/V1/CreateAirportMongo.cs | 3 +- .../src/Flight/Airports/Models/Airport.cs | 6 +- .../Airports/Models/AirportReadModel.cs | 6 +- ...ner.cs => 20230331144237_Init.Designer.cs} | 36 ++++++------ ...0222458_Init.cs => 20230331144237_Init.cs} | 16 +++--- .../FlightDbContextModelSnapshot.cs | 34 +++++------ .../src/Flight/Data/Seed/FlightDataSeeder.cs | 56 ++++++------------- .../src/Flight/Data/Seed/InitialData.cs | 55 ++++++++++++++++++ .../InfrastructureExtensions.cs | 4 -- .../src/Flight/Flights/Dtos/FlightDto.cs | 4 +- .../CreatingFlight/V1/CreateFlight.cs | 12 ++-- .../CreatingFlight/V1/CreateFlightEndpoint.cs | 6 +- .../CreatingFlight/V1/CreateFlightMongo.cs | 8 +-- .../V1/FlightCreatedDomainEvent.cs | 4 +- .../DeletingFlight/V1/DeleteFlight.cs | 7 +-- .../DeletingFlight/V1/DeleteFlightEndpoint.cs | 3 +- .../DeletingFlight/V1/DeleteFlightMongo.cs | 4 +- .../V1/FlightDeletedDomainEvent.cs | 4 +- .../Flight/Flights/Features/FlightMappings.cs | 6 +- .../GettingFlightById/V1/GetFlightById.cs | 3 +- .../V1/GetFlightByIdEndpoint.cs | 3 +- .../V1/FlightUpdatedDomainEvent.cs | 4 +- .../UpdatingFlight/V1/UpdateFlight.cs | 12 ++-- .../UpdatingFlight/V1/UpdateFlightEndpoint.cs | 4 +- .../UpdatingFlight/V1/UpdateFlightMongo.cs | 4 +- .../src/Flight/Flights/Models/Flight.cs | 26 ++++----- .../Flight/Flights/Models/FlightReadModel.cs | 10 ++-- .../src/Flight/GrpcServer/Protos/flight.proto | 22 ++++---- .../GrpcServer/Services/FlightGrpcServices.cs | 7 ++- .../Flight/src/Flight/Seats/Dtos/SeatDto.cs | 4 +- .../Features/CreatingSeat/V1/CreateSeat.cs | 11 ++-- .../CreatingSeat/V1/CreateSeatEndpoint.cs | 5 +- .../CreatingSeat/V1/CreateSeatMongo.cs | 5 +- .../CreatingSeat/V1/SeatCreatedDomainEvent.cs | 3 +- .../V1/GetAvailableSeats.cs | 3 +- .../V1/GetAvailableSeatsEndpoint.cs | 3 +- .../ReservingSeat/Commands/V1/ReserveSeat.cs | 5 +- .../Commands/V1/ReserveSeatEndpoint.cs | 5 +- .../Commands/V1/ReserveSeatMongo.cs | 5 +- .../Commands/V1/SeatReservedDomainEvent.cs | 3 +- .../src/Flight/Seats/Features/SeatMappings.cs | 6 +- .../Flight/src/Flight/Seats/Models/Seat.cs | 6 +- .../src/Flight/Seats/Models/SeatReadModel.cs | 8 ++- .../Fakes/FakeCreateFlightCommand.cs | 11 ++-- .../Fakes/FakeCreateAircraftCommand.cs | 4 +- .../Fakes/FakeCreateAirportCommand.cs | 4 +- .../Fakes/FakeCreateFlightCommand.cs | 12 ++-- .../Fakes/FakeCreateSeatCommand.cs | 7 ++- .../Flight/Features/DeleteFlightTests.cs | 3 +- .../Flight/Features/GetFlightByIdTests.cs | 5 +- .../Flight/Features/UpdateFlightTests.cs | 6 +- .../Seat/Features/GetAvailableSeatsTests.cs | 2 +- .../Seat/Features/ReserveSeatTests.cs | 4 +- .../CreateAircraftCommandHandlerTests.cs | 2 +- .../CreateAirportCommandHandlerTests.cs | 2 +- .../tests/UnitTest/Common/DbContextFactory.cs | 35 +++++++----- .../tests/UnitTest/Common/UnitTestFixture.cs | 1 - .../Fakes/FakeCreateAircraftCommand.cs | 4 +- .../Fakes/FakeCreateAirportCommand.cs | 4 +- .../UnitTest/Fakes/FakeCreateFlightCommand.cs | 12 ++-- .../UnitTest/Fakes/FakeCreateSeatCommand.cs | 8 ++- .../tests/UnitTest/Fakes/FakeFlightUpdate.cs | 4 +- .../Fakes/FakeValidateCreateFlightCommand.cs | 6 +- .../Fakes/FakeValidateCreateSeatCommand.cs | 3 +- .../CreateFlightCommandHandlerTests.cs | 2 +- .../Features/Domain/UpdateFlightTests.cs | 3 +- .../Features/CreateSeatCommandHandlerTests.cs | 2 +- src/Services/Identity/src/Identity.Api/.env | 1 - .../src/Identity/Data/IdentityContext.cs | 2 +- ....cs => 20230331193410_initial.Designer.cs} | 40 ++++++------- ...5_initial.cs => 20230331193410_initial.cs} | 18 +++--- .../IdentityContextModelSnapshot.cs | 38 ++++++------- .../Identity/Data/Seed/IdentityDataSeeder.cs | 38 ++++--------- .../src/Identity/Data/Seed/InitialData.cs | 38 +++++++++++++ .../InfrastructureExtensions.cs | 3 - .../RegisteringNewUser/V1/RegisterNewUser.cs | 3 +- .../V1/RegisterNewUserEndpoint.cs | 3 +- .../src/Identity/Identity/Models/Role.cs | 3 +- .../src/Identity/Identity/Models/RoleClaim.cs | 3 +- .../src/Identity/Identity/Models/User.cs | 3 +- .../src/Identity/Identity/Models/UserClaim.cs | 3 +- .../src/Identity/Identity/Models/UserLogin.cs | 3 +- .../src/Identity/Identity/Models/UserRole.cs | 3 +- .../src/Identity/Identity/Models/UserToken.cs | 3 +- src/Services/Passenger/src/Passenger.Api/.env | 1 - ....cs => 20230331204805_initial.Designer.cs} | 8 +-- ...1_initial.cs => 20230331204805_initial.cs} | 2 +- .../PassengerDbContextModelSnapshot.cs | 6 +- .../InfrastructureExtensions.cs | 3 - .../GrpcServer/Protos/passenger.proto | 12 ++-- .../Services/PassengerGrpcServices.cs | 8 +-- .../V1/PassengerCreatedDomainEvent.cs | 2 +- .../RegisteringNewUser/V1/RegisterNewUser.cs | 5 +- .../Passenger/Passengers/Dtos/PassengerDto.cs | 2 +- .../V1/CompleteRegisterPassenger.cs | 4 +- .../V1/CompleteRegisterPassengerMongo.cs | 4 +- ...ssengerRegistrationCompletedDomainEvent.cs | 2 +- .../Queries/V1/GetPassengerById.cs | 2 +- .../Queries/V1/GetPassengerByIdEndpoint.cs | 2 +- .../Passengers/Features/PassengerMappings.cs | 4 +- .../Passenger/Passengers/Models/Passenger.cs | 6 +- .../Passengers/Models/PassengerReadModel.cs | 4 +- .../FakeCompleteRegisterPassengerCommand.cs | 4 +- .../Fakes/FakePassengerCreated.cs | 5 +- .../Fakes/FakePassengerResponseDto.cs | 7 ++- .../IntegrationTest/Fakes/FakeUserCreated.cs | 5 +- .../Features/GetPassengerByIdTests.cs | 5 +- 160 files changed, 760 insertions(+), 672 deletions(-) delete mode 100644 src/BuildingBlocks/IdsGenerator/SnowflakeIdGenerator.cs rename src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/{20230122204943_initial.Designer.cs => 20230331173133_initial.Designer.cs} (93%) rename src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/{20230122204943_initial.cs => 20230331173133_initial.cs} (95%) delete mode 100644 src/Services/Booking/src/Booking.Api/.env rename src/Services/Booking/src/Booking/Booking/Models/{Reads => }/BookingReadModel.cs (51%) create mode 100644 src/Services/Booking/tests/IntegrationTest/Fakes/FakeGetAvailableSeatsResponse.cs create mode 100644 src/Services/Booking/tests/IntegrationTest/Fakes/FakeReserveSeatResponse.cs delete mode 100644 src/Services/Booking/tests/IntegrationTest/Fakes/FakeSeatsResponsecs.cs delete mode 100644 src/Services/Flight/src/Flight.Api/.env rename src/Services/Flight/src/Flight/Data/Migrations/{20230120222458_Init.Designer.cs => 20230331144237_Init.Designer.cs} (92%) rename src/Services/Flight/src/Flight/Data/Migrations/{20230120222458_Init.cs => 20230331144237_Init.cs} (90%) create mode 100644 src/Services/Flight/src/Flight/Data/Seed/InitialData.cs delete mode 100644 src/Services/Identity/src/Identity.Api/.env rename src/Services/Identity/src/Identity/Data/Migrations/{20230122204905_initial.Designer.cs => 20230331193410_initial.Designer.cs} (92%) rename src/Services/Identity/src/Identity/Data/Migrations/{20230122204905_initial.cs => 20230331193410_initial.cs} (91%) create mode 100644 src/Services/Identity/src/Identity/Data/Seed/InitialData.cs delete mode 100644 src/Services/Passenger/src/Passenger.Api/.env rename src/Services/Passenger/src/Passenger/Data/Migrations/{20230120222631_initial.Designer.cs => 20230331204805_initial.Designer.cs} (93%) rename src/Services/Passenger/src/Passenger/Data/Migrations/{20230120222631_initial.cs => 20230331204805_initial.cs} (95%) diff --git a/booking.rest b/booking.rest index 0140e30..319ae75 100644 --- a/booking.rest +++ b/booking.rest @@ -8,8 +8,8 @@ @booking-api=http://localhost:6010 @contentType = application/json -@flightid = 1 -@passengerId = 1 +@flightid = "3c5c0000-97c6-fc34-2eb9-08db322230c9" +@passengerId = "8c9c0000-97c6-fc34-2eb9-66db322230c9" ################################# Identity API ################################# @@ -70,7 +70,7 @@ authorization: bearer {{Authenticate.response.body.access_token}} "seatNumber": "1255", "type": 1, "class": 1, - "flightId": 1 + "flightId": "3c5c0000-97c6-fc34-2eb9-08db322230c9" } ### @@ -83,7 +83,7 @@ Content-Type: application/json authorization: bearer {{Authenticate.response.body.access_token}} { - "flightId": 1, + "flightId": "3c5c0000-97c6-fc34-2eb9-08db322230c9", "seatNumber": "1255" } ### @@ -125,11 +125,11 @@ authorization: bearer {{Authenticate.response.body.access_token}} { "flightNumber": "12BB", - "aircraftId": 1, - "departureAirportId": 1, + "aircraftId": "3c5c0000-97c6-fc34-fcd3-08db322230c8", + "departureAirportId": "3c5c0000-97c6-fc34-a0cb-08db322230c8", "departureDate": "2022-03-01T14:55:41.255Z", "arriveDate": "2022-03-01T14:55:41.255Z", - "arriveAirportId": 2, + "arriveAirportId": "3c5c0000-97c6-fc34-fc3c-08db322230c8", "durationMinutes": 120, "flightDate": "2022-03-01T14:55:41.255Z", "status": 1, @@ -148,11 +148,11 @@ authorization: bearer {{Authenticate.response.body.access_token}} { "id": 1, "flightNumber": "BD467", - "aircraftId": 1, - "departureAirportId": 1, + "aircraftId": "3c5c0000-97c6-fc34-fcd3-08db322230c8", + "departureAirportId": "3c5c0000-97c6-fc34-a0cb-08db322230c8", "departureDate": "2022-04-23T12:17:45.140Z", "arriveDate": "2022-04-23T12:17:45.140Z", - "arriveAirportId": 2, + "arriveAirportId": "3c5c0000-97c6-fc34-fc3c-08db322230c8", "durationMinutes": 120, "flightDate": "2022-04-23T12:17:45.140Z", "status": 4, @@ -250,8 +250,8 @@ Content-Type: application/json authorization: bearer {{Authenticate.response.body.access_token}} { - "passengerId": 8765596234940416, - "flightId": 1, + "passengerId": "8c9c0000-97c6-fc34-2eb9-66db322230c9", + "flightId": "3c5c0000-97c6-fc34-2eb9-08db322230c9", "description": "I want to fly to iran" } ### diff --git a/src/BuildingBlocks/BuildingBlocks.csproj b/src/BuildingBlocks/BuildingBlocks.csproj index 6ef8e41..5b7da12 100644 --- a/src/BuildingBlocks/BuildingBlocks.csproj +++ b/src/BuildingBlocks/BuildingBlocks.csproj @@ -18,7 +18,6 @@ - diff --git a/src/BuildingBlocks/Contracts/EventBus.Messages/FlighContracts.cs b/src/BuildingBlocks/Contracts/EventBus.Messages/FlighContracts.cs index 72b7a62..6d6dccf 100644 --- a/src/BuildingBlocks/Contracts/EventBus.Messages/FlighContracts.cs +++ b/src/BuildingBlocks/Contracts/EventBus.Messages/FlighContracts.cs @@ -2,10 +2,10 @@ using BuildingBlocks.Core.Event; namespace BuildingBlocks.Contracts.EventBus.Messages; -public record FlightCreated(long Id) : IIntegrationEvent; -public record FlightUpdated(long Id) : IIntegrationEvent; -public record FlightDeleted(long Id) : IIntegrationEvent; -public record AircraftCreated(long Id) : IIntegrationEvent; -public record AirportCreated(long Id) : IIntegrationEvent; -public record SeatCreated(long Id) : IIntegrationEvent; -public record SeatReserved(long Id) : IIntegrationEvent; +public record FlightCreated(Guid Id) : IIntegrationEvent; +public record FlightUpdated(Guid Id) : IIntegrationEvent; +public record FlightDeleted(Guid Id) : IIntegrationEvent; +public record AircraftCreated(Guid Id) : IIntegrationEvent; +public record AirportCreated(Guid Id) : IIntegrationEvent; +public record SeatCreated(Guid Id) : IIntegrationEvent; +public record SeatReserved(Guid Id) : IIntegrationEvent; diff --git a/src/BuildingBlocks/Contracts/EventBus.Messages/IdentityContracts.cs b/src/BuildingBlocks/Contracts/EventBus.Messages/IdentityContracts.cs index c39cba5..f0af2b9 100644 --- a/src/BuildingBlocks/Contracts/EventBus.Messages/IdentityContracts.cs +++ b/src/BuildingBlocks/Contracts/EventBus.Messages/IdentityContracts.cs @@ -2,4 +2,4 @@ using BuildingBlocks.Core.Event; namespace BuildingBlocks.Contracts.EventBus.Messages; -public record UserCreated(long Id, string Name, string PassportNumber) : IIntegrationEvent; +public record UserCreated(Guid Id, string Name, string PassportNumber) : IIntegrationEvent; diff --git a/src/BuildingBlocks/Contracts/EventBus.Messages/PassengerContracts.cs b/src/BuildingBlocks/Contracts/EventBus.Messages/PassengerContracts.cs index aadff7c..551620d 100644 --- a/src/BuildingBlocks/Contracts/EventBus.Messages/PassengerContracts.cs +++ b/src/BuildingBlocks/Contracts/EventBus.Messages/PassengerContracts.cs @@ -2,5 +2,5 @@ using BuildingBlocks.Core.Event; namespace BuildingBlocks.Contracts.EventBus.Messages; -public record PassengerRegistrationCompleted(long Id) : IIntegrationEvent; -public record PassengerCreated(long Id) : IIntegrationEvent; +public record PassengerRegistrationCompleted(Guid Id) : IIntegrationEvent; +public record PassengerCreated(Guid Id) : IIntegrationEvent; diff --git a/src/BuildingBlocks/Contracts/EventBus.Messages/ReservationContracts.cs b/src/BuildingBlocks/Contracts/EventBus.Messages/ReservationContracts.cs index ca7bdfb..d32daf4 100644 --- a/src/BuildingBlocks/Contracts/EventBus.Messages/ReservationContracts.cs +++ b/src/BuildingBlocks/Contracts/EventBus.Messages/ReservationContracts.cs @@ -2,4 +2,4 @@ using BuildingBlocks.Core.Event; namespace BuildingBlocks.Contracts.EventBus.Messages; -public record BookingCreated(long Id) : IIntegrationEvent; +public record BookingCreated(Guid Id) : IIntegrationEvent; diff --git a/src/BuildingBlocks/Core/Event/IEvent.cs b/src/BuildingBlocks/Core/Event/IEvent.cs index 9a00477..749c441 100644 --- a/src/BuildingBlocks/Core/Event/IEvent.cs +++ b/src/BuildingBlocks/Core/Event/IEvent.cs @@ -1,11 +1,12 @@ -using BuildingBlocks.IdsGenerator; using MediatR; namespace BuildingBlocks.Core.Event; +using global::MassTransit; + public interface IEvent : INotification { - long EventId => SnowflakeIdGenerator.NewId(); + Guid EventId => NewId.NextGuid(); public DateTime OccurredOn => DateTime.Now; public string EventType => GetType().AssemblyQualifiedName; } diff --git a/src/BuildingBlocks/Core/Event/InternalCommand.cs b/src/BuildingBlocks/Core/Event/InternalCommand.cs index b854545..b5ca942 100644 --- a/src/BuildingBlocks/Core/Event/InternalCommand.cs +++ b/src/BuildingBlocks/Core/Event/InternalCommand.cs @@ -1,5 +1,4 @@ using BuildingBlocks.Core.CQRS; -using BuildingBlocks.IdsGenerator; namespace BuildingBlocks.Core.Event; diff --git a/src/BuildingBlocks/Core/Model/Aggregate.cs b/src/BuildingBlocks/Core/Model/Aggregate.cs index 14697d5..f64caaf 100644 --- a/src/BuildingBlocks/Core/Model/Aggregate.cs +++ b/src/BuildingBlocks/Core/Model/Aggregate.cs @@ -1,32 +1,29 @@ using BuildingBlocks.Core.Event; -namespace BuildingBlocks.Core.Model +namespace BuildingBlocks.Core.Model; + +public abstract record Aggregate : Aggregate; + +public abstract record Aggregate : Audit, IAggregate { - public abstract record Aggregate : Aggregate + private readonly List _domainEvents = new(); + public IReadOnlyList DomainEvents => _domainEvents.AsReadOnly(); + + public void AddDomainEvent(IDomainEvent domainEvent) { + _domainEvents.Add(domainEvent); } - public abstract record Aggregate : Audit, IAggregate + public IEvent[] ClearDomainEvents() { - private readonly List _domainEvents = new(); - public IReadOnlyList DomainEvents => _domainEvents.AsReadOnly(); + IEvent[] dequeuedEvents = _domainEvents.ToArray(); - public void AddDomainEvent(IDomainEvent domainEvent) - { - _domainEvents.Add(domainEvent); - } + _domainEvents.Clear(); - public IEvent[] ClearDomainEvents() - { - IEvent[] dequeuedEvents = _domainEvents.ToArray(); - - _domainEvents.Clear(); - - return dequeuedEvents; - } - - public long Version { get; set; } - - public TId Id { get; set; } + return dequeuedEvents; } + + public long Version { get; set; } + + public TId Id { get; set; } } diff --git a/src/BuildingBlocks/EventStoreDB/Events/AggregateStreamExtensions.cs b/src/BuildingBlocks/EventStoreDB/Events/AggregateStreamExtensions.cs index 03d93ec..34452d8 100644 --- a/src/BuildingBlocks/EventStoreDB/Events/AggregateStreamExtensions.cs +++ b/src/BuildingBlocks/EventStoreDB/Events/AggregateStreamExtensions.cs @@ -7,7 +7,7 @@ public static class AggregateStreamExtensions { public static async Task AggregateStream( this EventStoreClient eventStore, - long id, + Guid id, CancellationToken cancellationToken, ulong? fromVersion = null ) where T : class, IProjection @@ -19,11 +19,13 @@ public static class AggregateStreamExtensions cancellationToken: cancellationToken ); - // TODO: consider adding extension method for the aggregation and deserialisation + // TODO: consider adding extension method for the aggregation and deserialization var aggregate = (T)Activator.CreateInstance(typeof(T), true)!; if (await readResult.ReadState == ReadState.StreamNotFound) + { return null; + } await foreach (var @event in readResult) { diff --git a/src/BuildingBlocks/EventStoreDB/Repository/EventStoreDBRepository.cs b/src/BuildingBlocks/EventStoreDB/Repository/EventStoreDBRepository.cs index 8dee798..767e19a 100644 --- a/src/BuildingBlocks/EventStoreDB/Repository/EventStoreDBRepository.cs +++ b/src/BuildingBlocks/EventStoreDB/Repository/EventStoreDBRepository.cs @@ -4,9 +4,9 @@ using EventStore.Client; namespace BuildingBlocks.EventStoreDB.Repository; -public interface IEventStoreDBRepository where T : class, IAggregateEventSourcing +public interface IEventStoreDBRepository where T : class, IAggregateEventSourcing { - Task Find(long id, CancellationToken cancellationToken); + Task Find(Guid id, CancellationToken cancellationToken); Task Add(T aggregate, CancellationToken cancellationToken); Task Update(T aggregate, long? expectedRevision = null, @@ -15,7 +15,7 @@ public interface IEventStoreDBRepository where T : class, IAggregateEventSour Task Delete(T aggregate, long? expectedRevision = null, CancellationToken cancellationToken = default); } -public class EventStoreDBRepository : IEventStoreDBRepository where T : class, IAggregateEventSourcing +public class EventStoreDBRepository : IEventStoreDBRepository where T : class, IAggregateEventSourcing { private static readonly long _currentUserId; private readonly EventStoreClient eventStore; @@ -25,7 +25,7 @@ public class EventStoreDBRepository : IEventStoreDBRepository where T : cl this.eventStore = eventStore ?? throw new ArgumentNullException(nameof(eventStore)); } - public Task Find(long id, CancellationToken cancellationToken) + public Task Find(Guid id, CancellationToken cancellationToken) { return eventStore.AggregateStream( id, diff --git a/src/BuildingBlocks/EventStoreDB/Repository/RepositoryExtensions.cs b/src/BuildingBlocks/EventStoreDB/Repository/RepositoryExtensions.cs index 66c7c9e..79ba271 100644 --- a/src/BuildingBlocks/EventStoreDB/Repository/RepositoryExtensions.cs +++ b/src/BuildingBlocks/EventStoreDB/Repository/RepositoryExtensions.cs @@ -7,9 +7,9 @@ public static class RepositoryExtensions { public static async Task Get( this IEventStoreDBRepository repository, - long id, + Guid id, CancellationToken cancellationToken - ) where T : class, IAggregateEventSourcing + ) where T : class, IAggregateEventSourcing { var entity = await repository.Find(id, cancellationToken); @@ -18,11 +18,11 @@ public static class RepositoryExtensions public static async Task GetAndUpdate( this IEventStoreDBRepository repository, - long id, + Guid id, Action action, long? expectedVersion = null, CancellationToken cancellationToken = default - ) where T : class, IAggregateEventSourcing + ) where T : class, IAggregateEventSourcing { var entity = await repository.Get(id, cancellationToken); diff --git a/src/BuildingBlocks/Exception/AggregateNotFoundException.cs b/src/BuildingBlocks/Exception/AggregateNotFoundException.cs index 1e6d015..aadaad6 100644 --- a/src/BuildingBlocks/Exception/AggregateNotFoundException.cs +++ b/src/BuildingBlocks/Exception/AggregateNotFoundException.cs @@ -2,11 +2,11 @@ namespace BuildingBlocks.Exception; public class AggregateNotFoundException : System.Exception { - public AggregateNotFoundException(string typeName, long id) : base($"{typeName} with id '{id}' was not found") + public AggregateNotFoundException(string typeName, Guid id) : base($"{typeName} with id '{id}' was not found") { } - public static AggregateNotFoundException For(long id) + public static AggregateNotFoundException For(Guid id) { return new AggregateNotFoundException(typeof(T).Name, id); } diff --git a/src/BuildingBlocks/IdsGenerator/SnowflakeIdGenerator.cs b/src/BuildingBlocks/IdsGenerator/SnowflakeIdGenerator.cs deleted file mode 100644 index b2fd850..0000000 --- a/src/BuildingBlocks/IdsGenerator/SnowflakeIdGenerator.cs +++ /dev/null @@ -1,35 +0,0 @@ -using IdGen; - -namespace BuildingBlocks.IdsGenerator; - -// Ref: https://github.com/RobThree/IdGen -// https://github.com/RobThree/IdGen/issues/34 -// https://www.callicoder.com/distributed-unique-id-sequence-number-generator/ -public static class SnowflakeIdGenerator -{ - private static readonly IdGenerator Generator; - static SnowflakeIdGenerator() - { - // Read `GENERATOR_ID` from .env file in service root folder or system environment variables - var generatorId = DotNetEnv.Env.GetInt("GENERATOR_ID", 0); - - // Let's say we take current time as our epoch - var epoch = DateTime.Now; - - // Create an ID with 45 bits for timestamp, 2 for generator-id - // and 16 for sequence - var structure = new IdStructure(45, 2, 16); - - // Prepare options - var options = new IdGeneratorOptions(structure, new DefaultTimeSource(epoch)); - - // Create an IdGenerator with it's generator-id set to 0, our custom epoch - // and id-structure - Generator = new IdGenerator(generatorId, options); - } - - public static long NewId() - { - return Generator.CreateId(); - } -} diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230122204943_initial.Designer.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230331173133_initial.Designer.cs similarity index 93% rename from src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230122204943_initial.Designer.cs rename to src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230331173133_initial.Designer.cs index c6730e2..1200bdf 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230122204943_initial.Designer.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230331173133_initial.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations { [DbContext(typeof(PersistMessageDbContext))] - [Migration("20230122204943_initial")] + [Migration("20230331173133_initial")] partial class initial { /// @@ -20,15 +20,15 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("BuildingBlocks.PersistMessageProcessor.PersistMessage", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Created") diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230122204943_initial.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230331173133_initial.cs similarity index 95% rename from src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230122204943_initial.cs rename to src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230331173133_initial.cs index 47847cf..2518f08 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230122204943_initial.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230331173133_initial.cs @@ -15,7 +15,7 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations name: "persist_message", columns: table => new { - id = table.Column(type: "bigint", nullable: false), + id = table.Column(type: "uuid", nullable: false), datatype = table.Column(name: "data_type", type: "text", nullable: true), data = table.Column(type: "text", nullable: true), created = table.Column(type: "timestamp with time zone", nullable: false), diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs index 2f55c12..dd237d0 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs @@ -17,15 +17,15 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("BuildingBlocks.PersistMessageProcessor.PersistMessage", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Created") diff --git a/src/BuildingBlocks/PersistMessageProcessor/IPersistMessageProcessor.cs b/src/BuildingBlocks/PersistMessageProcessor/IPersistMessageProcessor.cs index c1da1af..f83beda 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/IPersistMessageProcessor.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/IPersistMessageProcessor.cs @@ -15,7 +15,7 @@ public interface IPersistMessageProcessor CancellationToken cancellationToken = default) where TMessageEnvelope : MessageEnvelope; - Task AddReceivedMessageAsync( + Task AddReceivedMessageAsync( TMessageEnvelope messageEnvelope, CancellationToken cancellationToken = default) where TMessageEnvelope : MessageEnvelope; @@ -30,14 +30,14 @@ public interface IPersistMessageProcessor CancellationToken cancellationToken = default); Task ExistMessageAsync( - long messageId, + Guid messageId, CancellationToken cancellationToken = default); Task ProcessInboxAsync( - long messageId, + Guid messageId, CancellationToken cancellationToken = default); - Task ProcessAsync(long messageId, MessageDeliveryType deliveryType, CancellationToken cancellationToken = default); + Task ProcessAsync(Guid messageId, MessageDeliveryType deliveryType, CancellationToken cancellationToken = default); Task ProcessAllAsync(CancellationToken cancellationToken = default); } diff --git a/src/BuildingBlocks/PersistMessageProcessor/PersistMessage.cs b/src/BuildingBlocks/PersistMessageProcessor/PersistMessage.cs index bd25d4e..42d0ca5 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/PersistMessage.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/PersistMessage.cs @@ -4,7 +4,7 @@ using Core.Model; public class PersistMessage: IVersion { - public PersistMessage(long id, string dataType, string data, MessageDeliveryType deliveryType) + public PersistMessage(Guid id, string dataType, string data, MessageDeliveryType deliveryType) { Id = id; DataType = dataType; @@ -15,7 +15,7 @@ public class PersistMessage: IVersion RetryCount = 0; } - public long Id { get; private set; } + public Guid Id { get; private set; } public string DataType { get; private set; } public string Data { get; private set; } public DateTime Created { get; private set; } diff --git a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs index 561e059..ff18f6e 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/PersistMessageProcessor.cs @@ -2,7 +2,6 @@ using System.Text.Json; using Ardalis.GuardClauses; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; using BuildingBlocks.Utils; using MassTransit; using MediatR; @@ -40,7 +39,7 @@ public class PersistMessageProcessor : IPersistMessageProcessor await SavePersistMessageAsync(messageEnvelope, MessageDeliveryType.Outbox, cancellationToken); } - public Task AddReceivedMessageAsync(TMessageEnvelope messageEnvelope, + public Task AddReceivedMessageAsync(TMessageEnvelope messageEnvelope, CancellationToken cancellationToken = default) where TMessageEnvelope : MessageEnvelope { return SavePersistMessageAsync(messageEnvelope, MessageDeliveryType.Inbox, cancellationToken); @@ -60,7 +59,7 @@ public class PersistMessageProcessor : IPersistMessageProcessor .AsReadOnly(); } - public Task ExistMessageAsync(long messageId, CancellationToken cancellationToken = default) + public Task ExistMessageAsync(Guid messageId, CancellationToken cancellationToken = default) { return _persistMessageDbContext.PersistMessages.FirstOrDefaultAsync(x => x.Id == messageId && @@ -70,7 +69,7 @@ public class PersistMessageProcessor : IPersistMessageProcessor } public async Task ProcessAsync( - long messageId, + Guid messageId, MessageDeliveryType deliveryType, CancellationToken cancellationToken = default) { @@ -131,7 +130,7 @@ public class PersistMessageProcessor : IPersistMessageProcessor } } - public async Task ProcessInboxAsync(long messageId, CancellationToken cancellationToken = default) + public async Task ProcessInboxAsync(Guid messageId, CancellationToken cancellationToken = default) { var message = await _persistMessageDbContext.PersistMessages.FirstOrDefaultAsync( x => x.Id == messageId && @@ -191,18 +190,18 @@ public class PersistMessageProcessor : IPersistMessageProcessor return true; } - private async Task SavePersistMessageAsync( + private async Task SavePersistMessageAsync( MessageEnvelope messageEnvelope, MessageDeliveryType deliveryType, CancellationToken cancellationToken = default) { Guard.Against.Null(messageEnvelope.Message, nameof(messageEnvelope.Message)); - long id; + Guid id; if (messageEnvelope.Message is IEvent message) id = message.EventId; else - id = SnowflakeIdGenerator.NewId(); + id = NewId.NextGuid(); await _persistMessageDbContext.PersistMessages.AddAsync( new PersistMessage( diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index 93dbb38..ef258e9 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -398,7 +398,7 @@ public class TestWriteFixture : TestFixture }); } - public Task FindAsync(long id) + public Task FindAsync(Guid id) where T : class, IAudit { return ExecuteDbContextAsync(db => db.Set().FindAsync(id).AsTask()); diff --git a/src/Services/Booking/src/Booking.Api/.env b/src/Services/Booking/src/Booking.Api/.env deleted file mode 100644 index 467e2da..0000000 --- a/src/Services/Booking/src/Booking.Api/.env +++ /dev/null @@ -1 +0,0 @@ -GENERATOR_ID=4 diff --git a/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservation.cs b/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservation.cs index f3392a8..56c4a89 100644 --- a/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservation.cs +++ b/src/Services/Booking/src/Booking/Booking/Dtos/CreateReservation.cs @@ -1,4 +1,4 @@ namespace Booking.Booking.Dtos; -public record BookingResponseDto(long Id, string Name, string FlightNumber, long AircraftId, decimal Price, - DateTime FlightDate, string SeatNumber, long DepartureAirportId, long ArriveAirportId, string Description); +public record BookingResponseDto(Guid Id, string Name, string FlightNumber, Guid AircraftId, decimal Price, + DateTime FlightDate, string SeatNumber, Guid DepartureAirportId, Guid ArriveAirportId, string Description); diff --git a/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/BookingCreatedDomainEvent.cs b/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/BookingCreatedDomainEvent.cs index e7ae19d..d919c60 100644 --- a/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/BookingCreatedDomainEvent.cs +++ b/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/BookingCreatedDomainEvent.cs @@ -4,4 +4,4 @@ using BuildingBlocks.Core.Event; using BuildingBlocks.Core.Model; using Models.ValueObjects; -public record BookingCreatedDomainEvent(long Id, PassengerInfo PassengerInfo, Trip Trip) : Audit, IDomainEvent; +public record BookingCreatedDomainEvent(Guid Id, PassengerInfo PassengerInfo, Trip Trip) : Audit, IDomainEvent; diff --git a/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/CreateBooking.cs b/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/CreateBooking.cs index 01264fd..2e854d7 100644 --- a/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/CreateBooking.cs +++ b/src/Services/Booking/src/Booking/Booking/Features/CreatingBook/Commands/V1/CreateBooking.cs @@ -5,17 +5,17 @@ using BuildingBlocks.Core; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; using BuildingBlocks.EventStoreDB.Repository; -using BuildingBlocks.IdsGenerator; using BuildingBlocks.Web; using Exceptions; using Flight; using FluentValidation; +using MassTransit; using Models.ValueObjects; using Passenger; -public record CreateBooking(long PassengerId, long FlightId, string Description) : ICommand, IInternalCommand +public record CreateBooking(Guid PassengerId, Guid FlightId, string Description) : ICommand, IInternalCommand { - public long Id { get; init; } = SnowflakeIdGenerator.NewId(); + public Guid Id { get; init; } = NewId.NextGuid(); } public record CreateBookingResult(ulong Id); @@ -54,19 +54,17 @@ internal class CreateBookingCommandHandler : ICommandHandler +public record Booking : AggregateEventSourcing { public Trip Trip { get; private set; } public PassengerInfo PassengerInfo { get; private set; } - public static Booking Create(long id, PassengerInfo passengerInfo, Trip trip, bool isDeleted = false, long? userId = null) + public static Booking Create(Guid id, PassengerInfo passengerInfo, Trip trip, bool isDeleted = false, long? userId = null) { var booking = new Booking { Id = id, Trip = trip, PassengerInfo = passengerInfo, IsDeleted = isDeleted }; diff --git a/src/Services/Booking/src/Booking/Booking/Models/Reads/BookingReadModel.cs b/src/Services/Booking/src/Booking/Booking/Models/BookingReadModel.cs similarity index 51% rename from src/Services/Booking/src/Booking/Booking/Models/Reads/BookingReadModel.cs rename to src/Services/Booking/src/Booking/Booking/Models/BookingReadModel.cs index 7ec381c..99b7e15 100644 --- a/src/Services/Booking/src/Booking/Booking/Models/Reads/BookingReadModel.cs +++ b/src/Services/Booking/src/Booking/Booking/Models/BookingReadModel.cs @@ -1,11 +1,11 @@ -using Booking.Booking.Models.ValueObjects; +namespace Booking.Booking.Models; -namespace Booking.Booking.Models.Reads; +using ValueObjects; public class BookingReadModel { - public long Id { get; init; } - public long BookId { get; init; } + public Guid Id { get; init; } + public Guid BookId { get; init; } public Trip Trip { get; init; } public PassengerInfo PassengerInfo { get; init; } public bool IsDeleted { get; init; } diff --git a/src/Services/Booking/src/Booking/Booking/Models/ValueObjects/Trip.cs b/src/Services/Booking/src/Booking/Booking/Models/ValueObjects/Trip.cs index 4a302e4..8d318fd 100644 --- a/src/Services/Booking/src/Booking/Booking/Models/ValueObjects/Trip.cs +++ b/src/Services/Booking/src/Booking/Booking/Models/ValueObjects/Trip.cs @@ -1,4 +1,4 @@ namespace Booking.Booking.Models.ValueObjects; -public record Trip(string FlightNumber, long AircraftId, long DepartureAirportId, long ArriveAirportId, +public record Trip(string FlightNumber, Guid AircraftId, Guid DepartureAirportId, Guid ArriveAirportId, DateTime FlightDate, decimal Price, string Description, string SeatNumber); diff --git a/src/Services/Booking/src/Booking/BookingProjection.cs b/src/Services/Booking/src/Booking/BookingProjection.cs index fed0ade..68b8df3 100644 --- a/src/Services/Booking/src/Booking/BookingProjection.cs +++ b/src/Services/Booking/src/Booking/BookingProjection.cs @@ -1,8 +1,6 @@ -using Booking.Booking.Models.Reads; using Booking.Data; using BuildingBlocks.EventStoreDB.Events; using BuildingBlocks.EventStoreDB.Projections; -using BuildingBlocks.IdsGenerator; using MediatR; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -10,6 +8,8 @@ using MongoDB.Driver.Linq; namespace Booking; using Booking.Features.CreatingBook.Commands.V1; +using Booking.Models; +using MassTransit; public class BookingProjection : IProjectionProcessor { @@ -41,7 +41,7 @@ public class BookingProjection : IProjectionProcessor { var bookingReadModel = new BookingReadModel { - Id = SnowflakeIdGenerator.NewId(), + Id = NewId.NextGuid(), Trip = @event.Trip, BookId = @event.Id, PassengerInfo = @event.PassengerInfo, diff --git a/src/Services/Booking/src/Booking/Data/BookingReadDbContext.cs b/src/Services/Booking/src/Booking/Data/BookingReadDbContext.cs index 071244f..e2d48f5 100644 --- a/src/Services/Booking/src/Booking/Data/BookingReadDbContext.cs +++ b/src/Services/Booking/src/Booking/Data/BookingReadDbContext.cs @@ -1,11 +1,12 @@ -using Booking.Booking.Models.Reads; -using BuildingBlocks.Mongo; +using BuildingBlocks.Mongo; using Humanizer; using Microsoft.Extensions.Options; using MongoDB.Driver; namespace Booking.Data; +using Booking.Models; + public class BookingReadDbContext : MongoDbContext { public BookingReadDbContext(IOptions options) : base(options) diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index 92de13d..c0aa996 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -33,9 +33,6 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - // https://github.com/tonerdo/dotnet-env - DotNetEnv.Env.TraversePath().Load(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/src/Services/Booking/src/Booking/GrpcClient/Protos/flight.proto b/src/Services/Booking/src/Booking/GrpcClient/Protos/flight.proto index d70205c..aba77c4 100644 --- a/src/Services/Booking/src/Booking/GrpcClient/Protos/flight.proto +++ b/src/Services/Booking/src/Booking/GrpcClient/Protos/flight.proto @@ -5,51 +5,60 @@ import "google/protobuf/timestamp.proto"; service FlightGrpcService { - rpc GetById (GetByIdRequest) returns (FlightResponse); - rpc GetAvailableSeats (GetAvailableSeatsRequest) returns (ListSeatsResponse); - rpc ReserveSeat (ReserveSeatRequest) returns (SeatsResponse); + rpc GetById (GetByIdRequest) returns (GetFlightByIdResult); + rpc GetAvailableSeats (GetAvailableSeatsRequest) returns (GetAvailableSeatsResult); + rpc ReserveSeat (ReserveSeatRequest) returns (ReserveSeatResult); } message GetByIdRequest { - int64 Id = 1; + string Id = 1; +} + +message GetFlightByIdResult{ + FlightResponse FlightDto = 1; +} + +message GetAvailableSeatsResult{ +repeated SeatDtoResponse SeatDtos = 1; +} + +message ReserveSeatResult{ + string Id = 1; } message FlightResponse { - int64 Id = 1; + string Id = 1; string FlightNumber = 2; - int64 AircraftId = 3; - int64 DepartureAirportId = 4; + string AircraftId = 3; + string DepartureAirportId = 4; google.protobuf.Timestamp DepartureDate = 5; google.protobuf.Timestamp ArriveDate = 6; - int64 ArriveAirportId = 7; + string ArriveAirportId = 7; double DurationMinutes = 8; google.protobuf.Timestamp FlightDate = 9; FlightStatus Status = 10; double Price = 11; - int64 FlightId = 12; + string FlightId = 12; } message GetAvailableSeatsRequest { - int64 FlightId = 1; + string FlightId = 1; } -message SeatsResponse { - int64 Id = 1; +message SeatDtoResponse { + string Id = 1; string SeatNumber = 2; SeatType Type = 3; SeatClass Class = 4; - int64 FlightId = 5; + string FlightId = 5; } message ReserveSeatRequest { - int64 FlightId = 1; + string FlightId = 1; string SeatNumber = 2; } -message ListSeatsResponse { - repeated SeatsResponse items = 1; -} enum FlightStatus { FLIGHT_STATUS_UNKNOWN = 0; diff --git a/src/Services/Booking/src/Booking/GrpcClient/Protos/passenger.proto b/src/Services/Booking/src/Booking/GrpcClient/Protos/passenger.proto index dc63f56..bb98c29 100644 --- a/src/Services/Booking/src/Booking/GrpcClient/Protos/passenger.proto +++ b/src/Services/Booking/src/Booking/GrpcClient/Protos/passenger.proto @@ -4,15 +4,19 @@ package passenger; service PassengerGrpcService { - rpc GetById (GetByIdRequest) returns (PassengerResponse); + rpc GetById (GetByIdRequest) returns (GetPassengerByIdResult); } message GetByIdRequest { - int64 Id = 1; + string Id = 1; +} + +message GetPassengerByIdResult { + PassengerResponse PassengerDto = 1; } message PassengerResponse { - int64 Id = 1; + string Id = 1; string Name = 2; string PassportNumber = 3; PassengerType PassengerType = 4; diff --git a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs index d779ae2..15aacbf 100644 --- a/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs +++ b/src/Services/Booking/tests/IntegrationTest/Booking/Features/CreateBookingTests.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Threading.Tasks; +using System.Threading.Tasks; using Booking.Api; using Booking.Data; using BuildingBlocks.Contracts.EventBus.Messages; @@ -54,7 +53,7 @@ namespace Integration.Test.Booking.Features var mockPassenger = Substitute.For(); mockPassenger.GetByIdAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(new FakePassengerResponse().Generate()), + .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakePassengerResponse.Generate()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); return mockPassenger; @@ -68,15 +67,15 @@ namespace Integration.Test.Booking.Features var mockFlight = Substitute.For(); mockFlight.GetByIdAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(new FakeFlightResponse().Generate()), + .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeFlightResponse.Generate()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); mockFlight.GetAvailableSeatsAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeSeatsResponse.Generate()), + .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeGetAvailableSeatsResponse.Generate()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); mockFlight.ReserveSeatAsync(Arg.Any()) - .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeSeatsResponse.Generate()?.Items?.First()), + .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeReserveSeatResponse.Generate()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { })); return mockFlight; diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeCreateBookingCommand.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeCreateBookingCommand.cs index 3961db5..39f3846 100644 --- a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeCreateBookingCommand.cs +++ b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeCreateBookingCommand.cs @@ -1,16 +1,17 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; namespace Integration.Test.Fakes; +using System; using global::Booking.Booking.Features.CreatingBook.Commands.V1; +using MassTransit; public sealed class FakeCreateBookingCommand : AutoFaker { public FakeCreateBookingCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); - RuleFor(r => r.FlightId, _ => 1); - RuleFor(r => r.PassengerId, _ => 1); + RuleFor(r => r.Id, _ => NewId.NextGuid()); + RuleFor(r => r.FlightId, _ => new Guid("3c5c0000-97c6-fc34-2eb9-08db322230c9")); + RuleFor(r => r.PassengerId, _ => new Guid("4c5c8888-97c6-fc34-2eb9-18db322230c1")); } } diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs index 6e309c2..9a44330 100644 --- a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs +++ b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs @@ -5,19 +5,27 @@ using Google.Protobuf.WellKnownTypes; namespace Integration.Test.Fakes; -public class FakeFlightResponse : AutoFaker +public static class FakeFlightResponse { - public FakeFlightResponse() + public static GetFlightByIdResult Generate() { - RuleFor(r => r.Id, _ => 1); - RuleFor(r => r.Price, _ => 100); - RuleFor(r => r.Status, _ => FlightStatus.Completed); - RuleFor(r => r.AircraftId, _ => 1); - RuleFor(r => r.ArriveAirportId, _ => 1); - RuleFor(r => r.ArriveDate, _ => DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp()); - RuleFor(r => r.DepartureDate, _ => DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp()); - RuleFor(r => r.FlightDate, _ => DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp()); - RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); - RuleFor(r => r.DepartureAirportId, _ => 2); + var flightMock = new GetFlightByIdResult + { + FlightDto = new FlightResponse + { + Id = new Guid("3c5c0000-97c6-fc34-2eb9-08db322230c9").ToString(), + Price = 100, + Status = FlightStatus.Completed, + AircraftId = new Guid("3c5c0000-97c6-fc34-fcd3-08db322230c8").ToString(), + ArriveAirportId = new Guid("3c5c0000-97c6-fc34-a0cb-08db322230c8").ToString(), + ArriveDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp(), + DepartureDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp(), + FlightDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp(), + FlightNumber = "1500B", + DepartureAirportId = new Guid("3c5c0000-97c6-fc34-fc3c-08db322230c8").ToString() + } + }; + + return flightMock; } } diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeGetAvailableSeatsResponse.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeGetAvailableSeatsResponse.cs new file mode 100644 index 0000000..205a45c --- /dev/null +++ b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeGetAvailableSeatsResponse.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using Flight; + +namespace Integration.Test.Fakes; + +using System; +using MassTransit; + +public static class FakeGetAvailableSeatsResponse +{ + public static GetAvailableSeatsResult Generate() + { + var result = new GetAvailableSeatsResult(); + result.SeatDtos.AddRange(new List + { + new SeatDtoResponse() + { + FlightId = new Guid("3c5c0000-97c6-fc34-2eb9-08db322230c9").ToString(), + Class = SeatClass.Economy, + Type = SeatType.Aisle, + SeatNumber = "33F", + Id = NewId.NextGuid().ToString() + }, + new SeatDtoResponse() + { + FlightId = new Guid("3c5c0000-97c6-fc34-2eb9-08db322230c9").ToString(), + Class = SeatClass.Economy, + Type = SeatType.Window, + SeatNumber = "22D", + Id = NewId.NextGuid().ToString() + } + }); + + return result; + } +} diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakePassengerResponse.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakePassengerResponse.cs index a525e8a..31cbd98 100644 --- a/src/Services/Booking/tests/IntegrationTest/Fakes/FakePassengerResponse.cs +++ b/src/Services/Booking/tests/IntegrationTest/Fakes/FakePassengerResponse.cs @@ -1,13 +1,22 @@ -using AutoBogus; -using BuildingBlocks.IdsGenerator; +namespace Integration.Test.Fakes; + +using MassTransit; using Passenger; -namespace Integration.Test.Fakes; - -public class FakePassengerResponse : AutoFaker +public static class FakePassengerResponse { - public FakePassengerResponse() + public static GetPassengerByIdResult Generate() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + var result = new GetPassengerByIdResult + { + PassengerDto = new PassengerResponse() + { + Id = NewId.NextGuid().ToString(), + Name = "Test", + PassportNumber = "121618" + } + }; + + return result; } } diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeReserveSeatResponse.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeReserveSeatResponse.cs new file mode 100644 index 0000000..ea69f5c --- /dev/null +++ b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeReserveSeatResponse.cs @@ -0,0 +1,14 @@ +namespace Integration.Test.Fakes; +using Flight; +using MassTransit; + +public static class FakeReserveSeatResponse +{ + public static ReserveSeatResult Generate() + { + var result = new ReserveSeatResult(); + result.Id = NewId.NextGuid().ToString(); + + return result; + } +} diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeSeatsResponsecs.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeSeatsResponsecs.cs deleted file mode 100644 index 6fbd781..0000000 --- a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeSeatsResponsecs.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using Flight; - -namespace Integration.Test.Fakes; - -public static class FakeSeatsResponse -{ - public static ListSeatsResponse Generate() - { - var result = new ListSeatsResponse(); - result.Items.AddRange(new List - { - new SeatsResponse() - { - FlightId = 1, - Class = SeatClass.Economy, - Type = SeatType.Aisle, - SeatNumber = "33F", - Id = 1 - }, - new SeatsResponse() - { - FlightId = 1, - Class = SeatClass.Economy, - Type = SeatType.Window, - SeatNumber = "22D", - Id = 2 - } - }); - - return result; - } -} diff --git a/src/Services/Flight/src/Flight.Api/.env b/src/Services/Flight/src/Flight.Api/.env deleted file mode 100644 index 2e1ed1b..0000000 --- a/src/Services/Flight/src/Flight.Api/.env +++ /dev/null @@ -1 +0,0 @@ -GENERATOR_ID=1 diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs index 0da501b..9776895 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/AircraftMappings.cs @@ -1,21 +1,21 @@ -using BuildingBlocks.IdsGenerator; -using Flight.Aircrafts.Models; +using Flight.Aircrafts.Models; using Mapster; namespace Flight.Aircrafts.Features; using CreatingAircraft.V1; +using MassTransit; public class AircraftMappings : IRegister { public void Register(TypeAdapterConfig config) { config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.AircraftId, s => s.Id); config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.AircraftId, s => s.Id); config.NewConfig() diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/AircraftCreatedDomainEvent.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/AircraftCreatedDomainEvent.cs index f9c7bac..d296895 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/AircraftCreatedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/AircraftCreatedDomainEvent.cs @@ -1,5 +1,6 @@ namespace Flight.Aircrafts.Features.CreatingAircraft.V1; +using System; using BuildingBlocks.Core.Event; -public record AircraftCreatedDomainEvent(long Id, string Name, string Model, int ManufacturingYear, bool IsDeleted) : IDomainEvent; +public record AircraftCreatedDomainEvent(Guid Id, string Name, string Model, int ManufacturingYear, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraft.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraft.cs index 64fa423..f06e33f 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraft.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraft.cs @@ -1,26 +1,25 @@ namespace Flight.Aircrafts.Features.CreatingAircraft.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; using Exceptions; -using Flight.Aircrafts.Dtos; -using Flight.Aircrafts.Models; -using Flight.Data; +using Models; +using Data; using FluentValidation; -using MapsterMapper; +using MassTransit; using MediatR; using Microsoft.EntityFrameworkCore; public record CreateAircraft(string Name, string Model, int ManufacturingYear) : ICommand, IInternalCommand { - public long Id { get; init; } = SnowflakeIdGenerator.NewId(); + public Guid Id { get; init; } = NewId.NextGuid(); } -public record CreateAircraftResult(long Id); +public record CreateAircraftResult(Guid Id); internal class CreateAircraftValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftEndpoint.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftEndpoint.cs index 3a1fe44..57abf33 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftEndpoint.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Aircrafts.Features.CreatingAircraft.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -11,7 +12,7 @@ using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; public record CreateAircraftRequestDto(string Name, string Model, int ManufacturingYear); -public record CreateAircraftResponseDto(long Id); +public record CreateAircraftResponseDto(Guid Id); public class CreateAircraftEndpoint : IMinimalEndpoint { diff --git a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftMongo.cs b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftMongo.cs index 845bd75..dcb5003 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftMongo.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Features/CreatingAircraft/V1/CreateAircraftMongo.cs @@ -1,5 +1,6 @@ namespace Flight.Aircrafts.Features.CreatingAircraft.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; @@ -13,7 +14,7 @@ using MediatR; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record CreateAircraftMongo(long Id, string Name, string Model, int ManufacturingYear, bool IsDeleted) : InternalCommand; +public record CreateAircraftMongo(Guid Id, string Name, string Model, int ManufacturingYear, bool IsDeleted) : InternalCommand; public class CreateAircraftMongoHandler : ICommandHandler { diff --git a/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs b/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs index 2608f0a..6ac88dd 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Models/Aircraft.cs @@ -2,15 +2,16 @@ using BuildingBlocks.Core.Model; namespace Flight.Aircrafts.Models; +using System; using Features.CreatingAircraft.V1; -public record Aircraft : Aggregate +public record Aircraft : Aggregate { public string Name { get; private set; } public string Model { get; private set; } public int ManufacturingYear { get; private set; } - public static Aircraft Create(long id, string name, string model, int manufacturingYear, bool isDeleted = false) + public static Aircraft Create(Guid id, string name, string model, int manufacturingYear, bool isDeleted = false) { var aircraft = new Aircraft { diff --git a/src/Services/Flight/src/Flight/Aircrafts/Models/AircraftReadModel.cs b/src/Services/Flight/src/Flight/Aircrafts/Models/AircraftReadModel.cs index 2f52435..bdca7f0 100644 --- a/src/Services/Flight/src/Flight/Aircrafts/Models/AircraftReadModel.cs +++ b/src/Services/Flight/src/Flight/Aircrafts/Models/AircraftReadModel.cs @@ -1,9 +1,11 @@ namespace Flight.Aircrafts.Models; +using System; + public class AircraftReadModel { - public long Id { get; init; } - public long AircraftId { get; init; } + public Guid Id { get; init; } + public Guid AircraftId { get; init; } public string Name { get; init; } public string Model { get; init; } public int ManufacturingYear { get; init; } diff --git a/src/Services/Flight/src/Flight/Airports/Features/AirportMappings.cs b/src/Services/Flight/src/Flight/Airports/Features/AirportMappings.cs index 75bbd32..805f178 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/AirportMappings.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/AirportMappings.cs @@ -1,20 +1,20 @@ namespace Flight.Airports.Features; -using BuildingBlocks.IdsGenerator; -using Flight.Airports.Features.CreatingAirport.V1; -using Flight.Airports.Models; +using CreatingAirport.V1; +using Models; using Mapster; +using MassTransit; public class AirportMappings : IRegister { public void Register(TypeAdapterConfig config) { config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.AirportId, s => s.Id); config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.AirportId, s => s.Id); config.NewConfig() diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/AirportCreatedDomainEvent.cs b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/AirportCreatedDomainEvent.cs index 315a5b1..d0ea78d 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/AirportCreatedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/AirportCreatedDomainEvent.cs @@ -1,5 +1,6 @@ namespace Flight.Airports.Features.CreatingAirport.V1; +using System; using BuildingBlocks.Core.Event; -public record AirportCreatedDomainEvent(long Id, string Name, string Address, string Code, bool IsDeleted) : IDomainEvent; +public record AirportCreatedDomainEvent(Guid Id, string Name, string Address, string Code, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirport.cs b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirport.cs index 150ce60..0f7f802 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirport.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirport.cs @@ -1,25 +1,24 @@ namespace Flight.Airports.Features.CreatingAirport.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; -using Dtos; using Exceptions; using Data; using FluentValidation; -using MapsterMapper; +using MassTransit; using MediatR; using Microsoft.EntityFrameworkCore; public record CreateAirport(string Name, string Address, string Code) : ICommand, IInternalCommand { - public long Id { get; init; } = SnowflakeIdGenerator.NewId(); + public Guid Id { get; init; } = NewId.NextGuid(); } -public record CreateAirportResult(long Id); +public record CreateAirportResult(Guid Id); internal class CreateAirportValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportEndpoint.cs b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportEndpoint.cs index 8059fd0..63a54a8 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportEndpoint.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Airports.Features.CreatingAirport.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -11,7 +12,7 @@ using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; public record CreateAirportRequestDto(string Name, string Address, string Code); -public record CreateAirportResponseDto(long Id); +public record CreateAirportResponseDto(Guid Id); public class CreateAirportEndpoint : IMinimalEndpoint { diff --git a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportMongo.cs b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportMongo.cs index c46fc72..2f2e62b 100644 --- a/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportMongo.cs +++ b/src/Services/Flight/src/Flight/Airports/Features/CreatingAirport/V1/CreateAirportMongo.cs @@ -1,5 +1,6 @@ namespace Flight.Airports.Features.CreatingAirport.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; @@ -13,7 +14,7 @@ using MediatR; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record CreateAirportMongo(long Id, string Name, string Address, string Code, bool IsDeleted) : InternalCommand; +public record CreateAirportMongo(Guid Id, string Name, string Address, string Code, bool IsDeleted) : InternalCommand; internal class CreateAirportMongoHandler : ICommandHandler { diff --git a/src/Services/Flight/src/Flight/Airports/Models/Airport.cs b/src/Services/Flight/src/Flight/Airports/Models/Airport.cs index 655f692..fbdd71d 100644 --- a/src/Services/Flight/src/Flight/Airports/Models/Airport.cs +++ b/src/Services/Flight/src/Flight/Airports/Models/Airport.cs @@ -1,17 +1,17 @@ using BuildingBlocks.Core.Model; -using BuildingBlocks.IdsGenerator; namespace Flight.Airports.Models; +using System; using Features.CreatingAirport.V1; -public record Airport : Aggregate +public record Airport : Aggregate { public string Name { get; private set; } public string Address { get; private set; } public string Code { get; private set; } - public static Airport Create(long id, string name, string address, string code, bool isDeleted = false) + public static Airport Create(Guid id, string name, string address, string code, bool isDeleted = false) { var airport = new Airport { diff --git a/src/Services/Flight/src/Flight/Airports/Models/AirportReadModel.cs b/src/Services/Flight/src/Flight/Airports/Models/AirportReadModel.cs index 5cc384d..d6d8f99 100644 --- a/src/Services/Flight/src/Flight/Airports/Models/AirportReadModel.cs +++ b/src/Services/Flight/src/Flight/Airports/Models/AirportReadModel.cs @@ -1,9 +1,11 @@ namespace Flight.Airports.Models; +using System; + public class AirportReadModel { - public long Id { get; init; } - public long AirportId { get; init; } + public Guid Id { get; init; } + public Guid AirportId { get; init; } public string Name { get; init; } public string Address { get; init; } public string Code { get; init; } diff --git a/src/Services/Flight/src/Flight/Data/Migrations/20230120222458_Init.Designer.cs b/src/Services/Flight/src/Flight/Data/Migrations/20230331144237_Init.Designer.cs similarity index 92% rename from src/Services/Flight/src/Flight/Data/Migrations/20230120222458_Init.Designer.cs rename to src/Services/Flight/src/Flight/Data/Migrations/20230331144237_Init.Designer.cs index b83b9b0..f60fc7d 100644 --- a/src/Services/Flight/src/Flight/Data/Migrations/20230120222458_Init.Designer.cs +++ b/src/Services/Flight/src/Flight/Data/Migrations/20230331144237_Init.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Flight.Data.Migrations { [DbContext(typeof(FlightDbContext))] - [Migration("20230120222458_Init")] + [Migration("20230331144237_Init")] partial class Init { /// @@ -20,15 +20,15 @@ namespace Flight.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("CreatedAt") @@ -76,8 +76,8 @@ namespace Flight.Data.Migrations modelBuilder.Entity("Flight.Airports.Models.Airport", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Address") @@ -125,16 +125,16 @@ namespace Flight.Data.Migrations modelBuilder.Entity("Flight.Flights.Models.Flight", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); - b.Property("AircraftId") - .HasColumnType("bigint") + b.Property("AircraftId") + .HasColumnType("uuid") .HasColumnName("aircraft_id"); - b.Property("ArriveAirportId") - .HasColumnType("bigint") + b.Property("ArriveAirportId") + .HasColumnType("uuid") .HasColumnName("arrive_airport_id"); b.Property("ArriveDate") @@ -149,8 +149,8 @@ namespace Flight.Data.Migrations .HasColumnType("bigint") .HasColumnName("created_by"); - b.Property("DepartureAirportId") - .HasColumnType("bigint") + b.Property("DepartureAirportId") + .HasColumnType("uuid") .HasColumnName("departure_airport_id"); b.Property("DepartureDate") @@ -211,8 +211,8 @@ namespace Flight.Data.Migrations modelBuilder.Entity("Flight.Seats.Models.Seat", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Class") @@ -230,8 +230,8 @@ namespace Flight.Data.Migrations .HasColumnType("bigint") .HasColumnName("created_by"); - b.Property("FlightId") - .HasColumnType("bigint") + b.Property("FlightId") + .HasColumnType("uuid") .HasColumnName("flight_id"); b.Property("IsDeleted") diff --git a/src/Services/Flight/src/Flight/Data/Migrations/20230120222458_Init.cs b/src/Services/Flight/src/Flight/Data/Migrations/20230331144237_Init.cs similarity index 90% rename from src/Services/Flight/src/Flight/Data/Migrations/20230120222458_Init.cs rename to src/Services/Flight/src/Flight/Data/Migrations/20230331144237_Init.cs index affce5c..7d7c5ec 100644 --- a/src/Services/Flight/src/Flight/Data/Migrations/20230120222458_Init.cs +++ b/src/Services/Flight/src/Flight/Data/Migrations/20230331144237_Init.cs @@ -15,7 +15,7 @@ namespace Flight.Data.Migrations name: "aircraft", columns: table => new { - id = table.Column(type: "bigint", nullable: false), + id = table.Column(type: "uuid", nullable: false), name = table.Column(type: "text", nullable: true), model = table.Column(type: "text", nullable: true), manufacturingyear = table.Column(name: "manufacturing_year", type: "integer", nullable: false), @@ -35,7 +35,7 @@ namespace Flight.Data.Migrations name: "airport", columns: table => new { - id = table.Column(type: "bigint", nullable: false), + id = table.Column(type: "uuid", nullable: false), name = table.Column(type: "text", nullable: true), address = table.Column(type: "text", nullable: true), code = table.Column(type: "text", nullable: true), @@ -55,13 +55,13 @@ namespace Flight.Data.Migrations name: "flight", columns: table => new { - id = table.Column(type: "bigint", nullable: false), + id = table.Column(type: "uuid", nullable: false), flightnumber = table.Column(name: "flight_number", type: "text", nullable: true), - aircraftid = table.Column(name: "aircraft_id", type: "bigint", nullable: false), + aircraftid = table.Column(name: "aircraft_id", type: "uuid", nullable: false), departuredate = table.Column(name: "departure_date", type: "timestamp with time zone", nullable: false), - departureairportid = table.Column(name: "departure_airport_id", type: "bigint", nullable: false), + departureairportid = table.Column(name: "departure_airport_id", type: "uuid", nullable: false), arrivedate = table.Column(name: "arrive_date", type: "timestamp with time zone", nullable: false), - arriveairportid = table.Column(name: "arrive_airport_id", type: "bigint", nullable: false), + arriveairportid = table.Column(name: "arrive_airport_id", type: "uuid", nullable: false), durationminutes = table.Column(name: "duration_minutes", type: "numeric", nullable: false), flightdate = table.Column(name: "flight_date", type: "timestamp with time zone", nullable: false), status = table.Column(type: "text", nullable: false, defaultValue: "Unknown"), @@ -94,11 +94,11 @@ namespace Flight.Data.Migrations name: "seat", columns: table => new { - id = table.Column(type: "bigint", nullable: false), + id = table.Column(type: "uuid", nullable: false), seatnumber = table.Column(name: "seat_number", type: "text", nullable: true), type = table.Column(type: "text", nullable: false, defaultValue: "Unknown"), @class = table.Column(name: "class", type: "text", nullable: false, defaultValue: "Unknown"), - flightid = table.Column(name: "flight_id", type: "bigint", nullable: false), + flightid = table.Column(name: "flight_id", type: "uuid", nullable: false), createdat = table.Column(name: "created_at", type: "timestamp with time zone", nullable: true), createdby = table.Column(name: "created_by", type: "bigint", nullable: true), lastmodified = table.Column(name: "last_modified", type: "timestamp with time zone", nullable: true), diff --git a/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs b/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs index 8a46c93..5df1ffd 100644 --- a/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs +++ b/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs @@ -17,15 +17,15 @@ namespace Flight.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("CreatedAt") @@ -73,8 +73,8 @@ namespace Flight.Data.Migrations modelBuilder.Entity("Flight.Airports.Models.Airport", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Address") @@ -122,16 +122,16 @@ namespace Flight.Data.Migrations modelBuilder.Entity("Flight.Flights.Models.Flight", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); - b.Property("AircraftId") - .HasColumnType("bigint") + b.Property("AircraftId") + .HasColumnType("uuid") .HasColumnName("aircraft_id"); - b.Property("ArriveAirportId") - .HasColumnType("bigint") + b.Property("ArriveAirportId") + .HasColumnType("uuid") .HasColumnName("arrive_airport_id"); b.Property("ArriveDate") @@ -146,8 +146,8 @@ namespace Flight.Data.Migrations .HasColumnType("bigint") .HasColumnName("created_by"); - b.Property("DepartureAirportId") - .HasColumnType("bigint") + b.Property("DepartureAirportId") + .HasColumnType("uuid") .HasColumnName("departure_airport_id"); b.Property("DepartureDate") @@ -208,8 +208,8 @@ namespace Flight.Data.Migrations modelBuilder.Entity("Flight.Seats.Models.Seat", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Class") @@ -227,8 +227,8 @@ namespace Flight.Data.Migrations .HasColumnType("bigint") .HasColumnName("created_by"); - b.Property("FlightId") - .HasColumnType("bigint") + b.Property("FlightId") + .HasColumnType("uuid") .HasColumnName("flight_id"); b.Property("IsDeleted") diff --git a/src/Services/Flight/src/Flight/Data/Seed/FlightDataSeeder.cs b/src/Services/Flight/src/Flight/Data/Seed/FlightDataSeeder.cs index fb66552..977199d 100644 --- a/src/Services/Flight/src/Flight/Data/Seed/FlightDataSeeder.cs +++ b/src/Services/Flight/src/Flight/Data/Seed/FlightDataSeeder.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Threading.Tasks; using BuildingBlocks.EFCore; @@ -41,17 +40,13 @@ public class FlightDataSeeder : IDataSeeder { if (!await _flightDbContext.Airports.AnyAsync()) { - var airports = new List - { - Airport.Create(1, "Lisbon International Airport", "LIS", "12988"), - Airport.Create(2, "Sao Paulo International Airport", "BRZ", "11200") - }; - - await _flightDbContext.Airports.AddRangeAsync(airports); + await _flightDbContext.Airports.AddRangeAsync(InitialData.Airports); await _flightDbContext.SaveChangesAsync(); if (!await _flightReadDbContext.Airport.AsQueryable().AnyAsync()) - await _flightReadDbContext.Airport.InsertManyAsync(_mapper.Map>(airports)); + { + await _flightReadDbContext.Airport.InsertManyAsync(_mapper.Map>(InitialData.Airports)); + } } } @@ -59,18 +54,13 @@ public class FlightDataSeeder : IDataSeeder { if (!await _flightDbContext.Aircraft.AnyAsync()) { - var aircrafts = new List - { - Aircraft.Create(1, "Boeing 737", "B737", 2005), - Aircraft.Create(2, "Airbus 300", "A300", 2000), - Aircraft.Create(3, "Airbus 320", "A320", 2003) - }; - - await _flightDbContext.Aircraft.AddRangeAsync(aircrafts); + await _flightDbContext.Aircraft.AddRangeAsync(InitialData.Aircrafts); await _flightDbContext.SaveChangesAsync(); if (!await _flightReadDbContext.Aircraft.AsQueryable().AnyAsync()) - await _flightReadDbContext.Aircraft.InsertManyAsync(_mapper.Map>(aircrafts)); + { + await _flightReadDbContext.Aircraft.InsertManyAsync(_mapper.Map>(InitialData.Aircrafts)); + } } } @@ -79,21 +69,13 @@ public class FlightDataSeeder : IDataSeeder { if (!await _flightDbContext.Seats.AnyAsync()) { - var seats = new List - { - Seat.Create(1, "12A", Seats.Enums.SeatType.Window, Seats.Enums.SeatClass.Economy, 1), - Seat.Create(2, "12B", Seats.Enums.SeatType.Window, Seats.Enums.SeatClass.Economy, 1), - Seat.Create(3, "12C", Seats.Enums.SeatType.Middle, Seats.Enums.SeatClass.Economy, 1), - Seat.Create(4, "12D", Seats.Enums.SeatType.Middle, Seats.Enums.SeatClass.Economy, 1), - Seat.Create(5, "12E", Seats.Enums.SeatType.Aisle, Seats.Enums.SeatClass.Economy, 1), - Seat.Create(6, "12F", Seats.Enums.SeatType.Aisle, Seats.Enums.SeatClass.Economy, 1) - }; - - await _flightDbContext.Seats.AddRangeAsync(seats); + await _flightDbContext.Seats.AddRangeAsync(InitialData.Seats); await _flightDbContext.SaveChangesAsync(); if (!await _flightReadDbContext.Seat.AsQueryable().AnyAsync()) - await _flightReadDbContext.Seat.InsertManyAsync(_mapper.Map>(seats)); + { + await _flightReadDbContext.Seat.InsertManyAsync(_mapper.Map>(InitialData.Seats)); + } } } @@ -101,19 +83,13 @@ public class FlightDataSeeder : IDataSeeder { if (!await _flightDbContext.Flights.AnyAsync()) { - var flights = new List - { - Flights.Models.Flight.Create(1, "BD467", 1, 1, new DateTime(2022, 1, 31, 12, 0, 0), - new DateTime(2022, 1, 31, 14, 0, 0), - 2, 120m, - new DateTime(2022, 1, 31), Flights.Enums.FlightStatus.Completed, - 8000) - }; - await _flightDbContext.Flights.AddRangeAsync(flights); + await _flightDbContext.Flights.AddRangeAsync(InitialData.Flights); await _flightDbContext.SaveChangesAsync(); if (!await _flightReadDbContext.Flight.AsQueryable().AnyAsync()) - await _flightReadDbContext.Flight.InsertManyAsync(_mapper.Map>(flights)); + { + await _flightReadDbContext.Flight.InsertManyAsync(_mapper.Map>(InitialData.Flights)); + } } } } diff --git a/src/Services/Flight/src/Flight/Data/Seed/InitialData.cs b/src/Services/Flight/src/Flight/Data/Seed/InitialData.cs new file mode 100644 index 0000000..2953dd7 --- /dev/null +++ b/src/Services/Flight/src/Flight/Data/Seed/InitialData.cs @@ -0,0 +1,55 @@ +namespace Flight.Data.Seed; + +using System; +using System.Collections.Generic; +using System.Linq; +using Aircrafts.Models; +using Airports.Models; +using Flights.Models; +using MassTransit; +using Seats.Models; + +public static class InitialData +{ + public static List Airports { get;} + public static List Aircrafts { get;} + public static List Seats { get;} + public static List Flights { get; } + + + static InitialData() + { + Airports = new List + { + Airport.Create(new Guid("3c5c0000-97c6-fc34-a0cb-08db322230c8"), "Lisbon International Airport", "LIS", "12988"), + Airport.Create(new Guid("3c5c0000-97c6-fc34-fc3c-08db322230c8"), "Sao Paulo International Airport", "BRZ", "11200") + }; + + Aircrafts = new List + { + Aircraft.Create(new Guid("3c5c0000-97c6-fc34-fcd3-08db322230c8"), "Boeing 737", "B737", 2005), + Aircraft.Create(new Guid("3c5c0000-97c6-fc34-2e04-08db322230c9"), "Airbus 300", "A300", 2000), + Aircraft.Create(new Guid("3c5c0000-97c6-fc34-2e11-08db322230c9"), "Airbus 320", "A320", 2003) + }; + + + Flights = new List + { + Flight.Create(new Guid("3c5c0000-97c6-fc34-2eb9-08db322230c9"), "BD467", Aircrafts.First().Id, Airports.First().Id, new DateTime(2022, 1, 31, 12, 0, 0), + new DateTime(2022, 1, 31, 14, 0, 0), + Airports.Last().Id, 120m, + new DateTime(2022, 1, 31), global::Flight.Flights.Enums.FlightStatus.Completed, + 8000) + }; + + Seats = new List + { + Seat.Create(NewId.NextGuid(), "12A", global::Flight.Seats.Enums.SeatType.Window, global::Flight.Seats.Enums.SeatClass.Economy, Flights.First().Id), + Seat.Create(NewId.NextGuid(), "12B", global::Flight.Seats.Enums.SeatType.Window, global::Flight.Seats.Enums.SeatClass.Economy, Flights.First().Id), + Seat.Create(NewId.NextGuid(), "12C", global::Flight.Seats.Enums.SeatType.Middle, global::Flight.Seats.Enums.SeatClass.Economy, Flights.First().Id), + Seat.Create(NewId.NextGuid(), "12D", global::Flight.Seats.Enums.SeatType.Middle, global::Flight.Seats.Enums.SeatClass.Economy, Flights.First().Id), + Seat.Create(NewId.NextGuid(), "12E", global::Flight.Seats.Enums.SeatType.Aisle, global::Flight.Seats.Enums.SeatClass.Economy, Flights.First().Id), + Seat.Create(NewId.NextGuid(), "12F", global::Flight.Seats.Enums.SeatType.Aisle, global::Flight.Seats.Enums.SeatClass.Economy, Flights.First().Id) + }; + } +} diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index 82558e7..04cc878 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -4,7 +4,6 @@ using BuildingBlocks.Core; using BuildingBlocks.EFCore; using BuildingBlocks.Exception; using BuildingBlocks.HealthCheck; -using BuildingBlocks.IdsGenerator; using BuildingBlocks.Jwt; using BuildingBlocks.Logging; using BuildingBlocks.Mapster; @@ -38,9 +37,6 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - // https://github.com/tonerdo/dotnet-env - DotNetEnv.Env.TraversePath().Load(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/src/Services/Flight/src/Flight/Flights/Dtos/FlightDto.cs b/src/Services/Flight/src/Flight/Flights/Dtos/FlightDto.cs index fbfe7a1..9610506 100644 --- a/src/Services/Flight/src/Flight/Flights/Dtos/FlightDto.cs +++ b/src/Services/Flight/src/Flight/Flights/Dtos/FlightDto.cs @@ -2,6 +2,6 @@ using System; namespace Flight.Flights.Dtos; -public record FlightDto(long Id, string FlightNumber, long AircraftId, long DepartureAirportId, - DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, +public record FlightDto(Guid Id, string FlightNumber, Guid AircraftId, Guid DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price); diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlight.cs b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlight.cs index e41b17b..8572ce8 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlight.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlight.cs @@ -6,23 +6,21 @@ using System.Threading.Tasks; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; using Data; -using Dtos; using Exceptions; using FluentValidation; -using MapsterMapper; +using MassTransit; using Microsoft.EntityFrameworkCore; -public record CreateFlight(string FlightNumber, long AircraftId, long DepartureAirportId, - DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, +public record CreateFlight(string FlightNumber, Guid AircraftId, Guid DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price) : ICommand, IInternalCommand { - public long Id { get; init; } = SnowflakeIdGenerator.NewId(); + public Guid Id { get; init; } = NewId.NextGuid(); } -public record CreateFlightResult(long Id); +public record CreateFlightResult(Guid Id); internal class CreateFlightValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightEndpoint.cs index d71c0eb..8bb1d50 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightEndpoint.cs @@ -11,11 +11,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; -public record CreateFlightRequestDto(string FlightNumber, long AircraftId, long DepartureAirportId, - DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, +public record CreateFlightRequestDto(string FlightNumber, Guid AircraftId, Guid DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price); -public record CreateFlightResponseDto(long Id); +public record CreateFlightResponseDto(Guid Id); public class CreateFlightEndpoint : IMinimalEndpoint { diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightMongo.cs b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightMongo.cs index feef219..7327044 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightMongo.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/CreateFlightMongo.cs @@ -6,16 +6,16 @@ using System.Threading.Tasks; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using Flight.Data; -using Flight.Flights.Exceptions; +using Data; +using Exceptions; using MapsterMapper; using MediatR; using Models; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record CreateFlightMongo(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, +public record CreateFlightMongo(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate, + Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted) : InternalCommand; internal class CreateFlightMongoHandler : ICommandHandler diff --git a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/FlightCreatedDomainEvent.cs b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/FlightCreatedDomainEvent.cs index aaa3123..0d5b31d 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/FlightCreatedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/CreatingFlight/V1/FlightCreatedDomainEvent.cs @@ -3,6 +3,6 @@ namespace Flight.Flights.Features.CreatingFlight.V1; using System; using BuildingBlocks.Core.Event; -public record FlightCreatedDomainEvent(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, +public record FlightCreatedDomainEvent(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate, + Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlight.cs b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlight.cs index a72731c..55b5f2c 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlight.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlight.cs @@ -1,20 +1,19 @@ namespace Flight.Flights.Features.DeletingFlight.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; using Data; -using Dtos; using Exceptions; using FluentValidation; -using MapsterMapper; using Microsoft.EntityFrameworkCore; -public record DeleteFlight(long Id) : ICommand, IInternalCommand; +public record DeleteFlight(Guid Id) : ICommand, IInternalCommand; -public record DeleteFlightResult(long Id); +public record DeleteFlightResult(Guid Id); internal class DeleteFlightValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightEndpoint.cs index 6a1b83b..c0a3d32 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Flights.Features.DeletingFlight.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -25,7 +26,7 @@ public class DeleteFlightEndpoint : IMinimalEndpoint return builder; } - private async Task DeleteFlight(long id, IMediator mediator, CancellationToken cancellationToken) + private async Task DeleteFlight(Guid id, IMediator mediator, CancellationToken cancellationToken) { var result = await mediator.Send(new DeleteFlight(id), cancellationToken); diff --git a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightMongo.cs b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightMongo.cs index 2879e5c..8139855 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightMongo.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/DeleteFlightMongo.cs @@ -14,8 +14,8 @@ using Models; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record DeleteFlightMongo(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, +public record DeleteFlightMongo(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate, + Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted) : InternalCommand; internal class DeleteFlightMongoCommandHandler : ICommandHandler diff --git a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/FlightDeletedDomainEvent.cs b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/FlightDeletedDomainEvent.cs index a6813b7..06ed2dc 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/FlightDeletedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/DeletingFlight/V1/FlightDeletedDomainEvent.cs @@ -3,6 +3,6 @@ using System; using BuildingBlocks.Core.Event; -public record FlightDeletedDomainEvent(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, +public record FlightDeletedDomainEvent(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate, + Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs b/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs index e3c7541..5b529f6 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/FlightMappings.cs @@ -1,4 +1,3 @@ -using BuildingBlocks.IdsGenerator; using Mapster; namespace Flight.Flights.Features; @@ -6,6 +5,7 @@ namespace Flight.Flights.Features; using CreatingFlight.V1; using DeletingFlight.V1; using GettingAvailableFlights.V1; +using MassTransit; using Models; using UpdatingFlight.V1; using FlightDto = Dtos.FlightDto; @@ -19,11 +19,11 @@ public class FlightMappings : IRegister x.ArriveDate, x.ArriveAirportId, x.DurationMinutes, x.FlightDate, x.Status, x.Price)); config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.FlightId, s => s.Id); config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.FlightId, s => s.Id); config.NewConfig() diff --git a/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightById.cs b/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightById.cs index 8213f09..e7d7a68 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightById.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightById.cs @@ -1,5 +1,6 @@ namespace Flight.Flights.Features.GettingFlightById.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; @@ -12,7 +13,7 @@ using MapsterMapper; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record GetFlightById(long Id) : IQuery; +public record GetFlightById(Guid Id) : IQuery; public record GetFlightByIdResult(FlightDto FlightDto); diff --git a/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightByIdEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightByIdEndpoint.cs index 0ad4c07..3e37eb2 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightByIdEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/GettingFlightById/V1/GetFlightByIdEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Flights.Features.GettingFlightById.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -28,7 +29,7 @@ public class GetFlightByIdEndpoint : IMinimalEndpoint return builder; } - private async Task GetById(long id, IMediator mediator, CancellationToken cancellationToken) + private async Task GetById(Guid id, IMediator mediator, CancellationToken cancellationToken) { var result = await mediator.Send(new GetFlightById(id), cancellationToken); diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/FlightUpdatedDomainEvent.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/FlightUpdatedDomainEvent.cs index 0c08696..6739a70 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/FlightUpdatedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/FlightUpdatedDomainEvent.cs @@ -3,6 +3,6 @@ namespace Flight.Flights.Features.UpdatingFlight.V1; using System; using BuildingBlocks.Core.Event; -public record FlightUpdatedDomainEvent(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, +public record FlightUpdatedDomainEvent(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate, + Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlight.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlight.cs index dc83542..2dde4fd 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlight.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlight.cs @@ -7,23 +7,21 @@ using Ardalis.GuardClauses; using BuildingBlocks.Caching; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using Flight.Data; -using Flight.Flights.Dtos; -using Flight.Flights.Exceptions; +using Data; +using Exceptions; using Flight.Flights.Features.CreatingFlight.V1; using FluentValidation; -using MapsterMapper; using Microsoft.EntityFrameworkCore; -public record UpdateFlight(long Id, string FlightNumber, long AircraftId, long DepartureAirportId, - DateTime DepartureDate, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, +public record UpdateFlight(Guid Id, string FlightNumber, Guid AircraftId, Guid DepartureAirportId, + DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, bool IsDeleted, decimal Price) : ICommand, IInternalCommand, IInvalidateCacheRequest { public string CacheKey => "GetAvailableFlights"; } -public record UpdateFlightResult(long Id); +public record UpdateFlightResult(Guid Id); internal class UpdateFlightValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightEndpoint.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightEndpoint.cs index 30af956..e4cdb50 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightEndpoint.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightEndpoint.cs @@ -11,8 +11,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; -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); +public record UpdateFlightRequestDto(Guid Id, string FlightNumber, Guid AircraftId, Guid DepartureAirportId, DateTime DepartureDate, DateTime ArriveDate, + Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted); public class UpdateFlightEndpoint : IMinimalEndpoint { diff --git a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightMongo.cs b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightMongo.cs index d3eb683..8424567 100644 --- a/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightMongo.cs +++ b/src/Services/Flight/src/Flight/Flights/Features/UpdatingFlight/V1/UpdateFlightMongo.cs @@ -14,8 +14,8 @@ using Models; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record UpdateFlightMongo(long Id, string FlightNumber, long AircraftId, DateTime DepartureDate, - long DepartureAirportId, DateTime ArriveDate, long ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, +public record UpdateFlightMongo(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate, + Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate, Enums.FlightStatus Status, decimal Price, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Flight/src/Flight/Flights/Models/Flight.cs b/src/Services/Flight/src/Flight/Flights/Models/Flight.cs index d0b4fd5..86ab7a7 100644 --- a/src/Services/Flight/src/Flight/Flights/Models/Flight.cs +++ b/src/Services/Flight/src/Flight/Flights/Models/Flight.cs @@ -7,22 +7,22 @@ using Features.CreatingFlight.V1; using Features.DeletingFlight.V1; using Features.UpdatingFlight.V1; -public record Flight : Aggregate +public record Flight : Aggregate { public string FlightNumber { get; private set; } - public long AircraftId { get; private set; } + public Guid AircraftId { get; private set; } public DateTime DepartureDate { get; private set; } - public long DepartureAirportId { get; private set; } + public Guid DepartureAirportId { get; private set; } public DateTime ArriveDate { get; private set; } - public long ArriveAirportId { get; private set; } + public Guid ArriveAirportId { get; private set; } public decimal DurationMinutes { get; private set; } public DateTime FlightDate { get; private set; } public Enums.FlightStatus Status { get; private set; } public decimal Price { get; private set; } - public static Flight Create(long id, string flightNumber, long aircraftId, - long departureAirportId, DateTime departureDate, DateTime arriveDate, - long arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, + public static Flight Create(Guid id, string flightNumber, Guid aircraftId, + Guid departureAirportId, DateTime departureDate, DateTime arriveDate, + Guid arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, decimal price, bool isDeleted = false) { var flight = new Flight @@ -52,9 +52,9 @@ public record Flight : Aggregate } - public void Update(long id, string flightNumber, long aircraftId, - long departureAirportId, DateTime departureDate, DateTime arriveDate, - long arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, + public void Update(Guid id, string flightNumber, Guid aircraftId, + Guid departureAirportId, DateTime departureDate, DateTime arriveDate, + Guid arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, decimal price, bool isDeleted = false) { FlightNumber = flightNumber; @@ -75,9 +75,9 @@ public record Flight : Aggregate AddDomainEvent(@event); } - public void Delete(long id, string flightNumber, long aircraftId, - long departureAirportId, DateTime departureDate, DateTime arriveDate, - long arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, + public void Delete(Guid id, string flightNumber, Guid aircraftId, + Guid departureAirportId, DateTime departureDate, DateTime arriveDate, + Guid arriveAirportId, decimal durationMinutes, DateTime flightDate, Enums.FlightStatus status, decimal price, bool isDeleted = true) { FlightNumber = flightNumber; diff --git a/src/Services/Flight/src/Flight/Flights/Models/FlightReadModel.cs b/src/Services/Flight/src/Flight/Flights/Models/FlightReadModel.cs index cd51d06..e11c22d 100644 --- a/src/Services/Flight/src/Flight/Flights/Models/FlightReadModel.cs +++ b/src/Services/Flight/src/Flight/Flights/Models/FlightReadModel.cs @@ -4,14 +4,14 @@ using System; public class FlightReadModel { - public long Id { get; init; } - public long FlightId { get; init; } + public Guid Id { get; init; } + public Guid FlightId { get; init; } public string FlightNumber { get; init; } - public long AircraftId { get; init; } + public Guid AircraftId { get; init; } public DateTime DepartureDate { get; init; } - public long DepartureAirportId { get; init; } + public Guid DepartureAirportId { get; init; } public DateTime ArriveDate { get; init; } - public long ArriveAirportId { get; init; } + public Guid ArriveAirportId { get; init; } public decimal DurationMinutes { get; init; } public DateTime FlightDate { get; init; } public Enums.FlightStatus Status { get; init; } diff --git a/src/Services/Flight/src/Flight/GrpcServer/Protos/flight.proto b/src/Services/Flight/src/Flight/GrpcServer/Protos/flight.proto index 549b7d7..aba77c4 100644 --- a/src/Services/Flight/src/Flight/GrpcServer/Protos/flight.proto +++ b/src/Services/Flight/src/Flight/GrpcServer/Protos/flight.proto @@ -11,7 +11,7 @@ service FlightGrpcService { } message GetByIdRequest { - int64 Id = 1; + string Id = 1; } message GetFlightByIdResult{ @@ -23,39 +23,39 @@ repeated SeatDtoResponse SeatDtos = 1; } message ReserveSeatResult{ - int64 Id = 1; + string Id = 1; } message FlightResponse { - int64 Id = 1; + string Id = 1; string FlightNumber = 2; - int64 AircraftId = 3; - int64 DepartureAirportId = 4; + string AircraftId = 3; + string DepartureAirportId = 4; google.protobuf.Timestamp DepartureDate = 5; google.protobuf.Timestamp ArriveDate = 6; - int64 ArriveAirportId = 7; + string ArriveAirportId = 7; double DurationMinutes = 8; google.protobuf.Timestamp FlightDate = 9; FlightStatus Status = 10; double Price = 11; - int64 FlightId = 12; + string FlightId = 12; } message GetAvailableSeatsRequest { - int64 FlightId = 1; + string FlightId = 1; } message SeatDtoResponse { - int64 Id = 1; + string Id = 1; string SeatNumber = 2; SeatType Type = 3; SeatClass Class = 4; - int64 FlightId = 5; + string FlightId = 5; } message ReserveSeatRequest { - int64 FlightId = 1; + string FlightId = 1; string SeatNumber = 2; } diff --git a/src/Services/Flight/src/Flight/GrpcServer/Services/FlightGrpcServices.cs b/src/Services/Flight/src/Flight/GrpcServer/Services/FlightGrpcServices.cs index 71c75f0..d67bf57 100644 --- a/src/Services/Flight/src/Flight/GrpcServer/Services/FlightGrpcServices.cs +++ b/src/Services/Flight/src/Flight/GrpcServer/Services/FlightGrpcServices.cs @@ -5,6 +5,7 @@ using MediatR; namespace Flight.GrpcServer.Services; +using System; using Flights.Features.GettingFlightById.V1; using Seats.Features.GettingAvailableSeats.V1; using Seats.Features.ReservingSeat.Commands.V1; @@ -23,7 +24,7 @@ public class FlightGrpcServices : FlightGrpcService.FlightGrpcServiceBase public override async Task GetById(GetByIdRequest request, ServerCallContext context) { - var result = await _mediator.Send(new GetFlightById(request.Id)); + var result = await _mediator.Send(new GetFlightById(new Guid(request.Id))); return result.Adapt(); } @@ -31,7 +32,7 @@ public class FlightGrpcServices : FlightGrpcService.FlightGrpcServiceBase { var result = new GetAvailableSeatsResult(); - var availableSeats = await _mediator.Send(new GetAvailableSeats(request.FlightId)); + var availableSeats = await _mediator.Send(new GetAvailableSeats(new Guid(request.FlightId))); if (availableSeats?.SeatDtos == null) { @@ -48,7 +49,7 @@ public class FlightGrpcServices : FlightGrpcService.FlightGrpcServiceBase public override async Task ReserveSeat(ReserveSeatRequest request, ServerCallContext context) { - var result = await _mediator.Send(new ReserveSeat(request.FlightId, request.SeatNumber)); + var result = await _mediator.Send(new ReserveSeat(new Guid(request.FlightId), request.SeatNumber)); return result.Adapt(); } } diff --git a/src/Services/Flight/src/Flight/Seats/Dtos/SeatDto.cs b/src/Services/Flight/src/Flight/Seats/Dtos/SeatDto.cs index 9fcc68f..0547616 100644 --- a/src/Services/Flight/src/Flight/Seats/Dtos/SeatDto.cs +++ b/src/Services/Flight/src/Flight/Seats/Dtos/SeatDto.cs @@ -1,3 +1,5 @@ namespace Flight.Seats.Dtos; -public record SeatDto(long Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId); +using System; + +public record SeatDto(Guid Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, Guid FlightId); diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeat.cs b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeat.cs index fff3194..5034ad0 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeat.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeat.cs @@ -1,26 +1,25 @@ namespace Flight.Seats.Features.CreatingSeat.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; using Flight.Data; -using Flight.Seats.Dtos; using Flight.Seats.Exceptions; using Flight.Seats.Models; using FluentValidation; -using MapsterMapper; +using MassTransit; using MediatR; using Microsoft.EntityFrameworkCore; -public record CreateSeat(string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId) : ICommand, IInternalCommand +public record CreateSeat(string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, Guid FlightId) : ICommand, IInternalCommand { - public long Id { get; init; } = SnowflakeIdGenerator.NewId(); + public Guid Id { get; init; } = NewId.NextGuid(); } -public record CreateSeatResult(long Id); +public record CreateSeatResult(Guid Id); internal class CreateSeatValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatEndpoint.cs b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatEndpoint.cs index 0760d98..fdccb07 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatEndpoint.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.CreatingSeat.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -10,8 +11,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; -public record CreateSeatRequestDto(string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId); -public record CreateSeatResponseDto(long Id); +public record CreateSeatRequestDto(string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, Guid FlightId); +public record CreateSeatResponseDto(Guid Id); public class CreateSeatEndpoint : IMinimalEndpoint { diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatMongo.cs b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatMongo.cs index 6d93f6d..018be0b 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatMongo.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/CreateSeatMongo.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.CreatingSeat.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; @@ -13,8 +14,8 @@ using MediatR; using MongoDB.Driver; using MongoDB.Driver.Linq; -public record CreateSeatMongo(long Id, string SeatNumber, Enums.SeatType Type, - Enums.SeatClass Class, long FlightId, bool IsDeleted) : InternalCommand; +public record CreateSeatMongo(Guid Id, string SeatNumber, Enums.SeatType Type, + Enums.SeatClass Class, Guid FlightId, bool IsDeleted) : InternalCommand; public class CreateSeatMongoHandler : ICommandHandler { diff --git a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/SeatCreatedDomainEvent.cs b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/SeatCreatedDomainEvent.cs index 3f80f56..1a1e04a 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/SeatCreatedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/CreatingSeat/V1/SeatCreatedDomainEvent.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.CreatingSeat.V1; +using System; using BuildingBlocks.Core.Event; -public record SeatCreatedDomainEvent(long Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId, bool IsDeleted) : IDomainEvent; +public record SeatCreatedDomainEvent(Guid Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, Guid FlightId, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeats.cs b/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeats.cs index 10a6e8c..3c2c07f 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeats.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeats.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.GettingAvailableSeats.V1; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -14,7 +15,7 @@ using MapsterMapper; using MediatR; using MongoDB.Driver; -public record GetAvailableSeats(long FlightId) : IQuery; +public record GetAvailableSeats(Guid FlightId) : IQuery; public record GetAvailableSeatsResult(IEnumerable SeatDtos); diff --git a/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeatsEndpoint.cs b/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeatsEndpoint.cs index 972965a..bd4f15c 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeatsEndpoint.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/GettingAvailableSeats/V1/GetAvailableSeatsEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.GettingAvailableSeats.V1; +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -29,7 +30,7 @@ public class GetAvailableSeatsEndpoint : IMinimalEndpoint return builder; } - private async Task GetAvailableSeats(long id, IMediator mediator, CancellationToken cancellationToken) + private async Task GetAvailableSeats(Guid id, IMediator mediator, CancellationToken cancellationToken) { var result = await mediator.Send(new GetAvailableSeats(id), cancellationToken); diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeat.cs b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeat.cs index d35f679..5cbf019 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeat.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeat.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.ReservingSeat.Commands.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; @@ -11,9 +12,9 @@ using FluentValidation; using MediatR; using Microsoft.EntityFrameworkCore; -public record ReserveSeat(long FlightId, string SeatNumber) : ICommand, IInternalCommand; +public record ReserveSeat(Guid FlightId, string SeatNumber) : ICommand, IInternalCommand; -public record ReserveSeatResult(long Id); +public record ReserveSeatResult(Guid Id); internal class ReserveSeatValidator : AbstractValidator { diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatEndpoint.cs b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatEndpoint.cs index 3a98d0c..766b3fb 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatEndpoint.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatEndpoint.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.ReservingSeat.Commands.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -10,8 +11,8 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Swashbuckle.AspNetCore.Annotations; -public record ReserveSeatRequestDto(long FlightId, string SeatNumber); -public record ReserveSeatResponseDto(long Id); +public record ReserveSeatRequestDto(Guid FlightId, string SeatNumber); +public record ReserveSeatResponseDto(Guid Id); public class ReserveSeatEndpoint : IMinimalEndpoint { diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatMongo.cs b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatMongo.cs index 6377e72..c4eab79 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatMongo.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/ReserveSeatMongo.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.ReservingSeat.Commands.V1; +using System; using System.Threading; using System.Threading.Tasks; using Ardalis.GuardClauses; @@ -11,8 +12,8 @@ using MapsterMapper; using MediatR; using MongoDB.Driver; -public record ReserveSeatMongo(long Id, string SeatNumber, Enums.SeatType Type, - Enums.SeatClass Class, long FlightId, bool IsDeleted) : InternalCommand; +public record ReserveSeatMongo(Guid Id, string SeatNumber, Enums.SeatType Type, + Enums.SeatClass Class, Guid FlightId, bool IsDeleted) : InternalCommand; internal class ReserveSeatMongoHandler : ICommandHandler { diff --git a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/SeatReservedDomainEvent.cs b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/SeatReservedDomainEvent.cs index 1ccc1a7..f83b721 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/SeatReservedDomainEvent.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/ReservingSeat/Commands/V1/SeatReservedDomainEvent.cs @@ -1,5 +1,6 @@ namespace Flight.Seats.Features.ReservingSeat.Commands.V1; +using System; using BuildingBlocks.Core.Event; -public record SeatReservedDomainEvent(long Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, long FlightId, bool IsDeleted) : IDomainEvent; +public record SeatReservedDomainEvent(Guid Id, string SeatNumber, Enums.SeatType Type, Enums.SeatClass Class, Guid FlightId, bool IsDeleted) : IDomainEvent; diff --git a/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs b/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs index 4321875..d8a0d56 100644 --- a/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs +++ b/src/Services/Flight/src/Flight/Seats/Features/SeatMappings.cs @@ -1,4 +1,3 @@ -using BuildingBlocks.IdsGenerator; using Flight.Seats.Dtos; using Flight.Seats.Models; using Mapster; @@ -6,6 +5,7 @@ using Mapster; namespace Flight.Seats.Features; using CreatingSeat.V1; +using MassTransit; using ReservingSeat.Commands.V1; public class SeatMappings : IRegister @@ -16,11 +16,11 @@ public class SeatMappings : IRegister .ConstructUsing(x => new SeatDto(x.Id, x.SeatNumber, x.Type, x.Class, x.FlightId)); config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.SeatId, s => s.Id); config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.SeatId, s => s.Id); config.NewConfig() diff --git a/src/Services/Flight/src/Flight/Seats/Models/Seat.cs b/src/Services/Flight/src/Flight/Seats/Models/Seat.cs index fb74d9f..96ad13c 100644 --- a/src/Services/Flight/src/Flight/Seats/Models/Seat.cs +++ b/src/Services/Flight/src/Flight/Seats/Models/Seat.cs @@ -7,9 +7,9 @@ namespace Flight.Seats.Models; using Features.CreatingSeat.V1; using Features.ReservingSeat.Commands.V1; -public record Seat : Aggregate +public record Seat : Aggregate { - public static Seat Create(long id, string seatNumber, Enums.SeatType type, Enums.SeatClass @class, long flightId, + public static Seat Create(Guid id, string seatNumber, Enums.SeatType type, Enums.SeatClass @class, Guid flightId, bool isDeleted = false) { var seat = new Seat() @@ -56,5 +56,5 @@ public record Seat : Aggregate public string SeatNumber { get; private set; } public Enums.SeatType Type { get; private set; } public Enums.SeatClass Class { get; private set; } - public long FlightId { get; private set; } + public Guid FlightId { get; private set; } } diff --git a/src/Services/Flight/src/Flight/Seats/Models/SeatReadModel.cs b/src/Services/Flight/src/Flight/Seats/Models/SeatReadModel.cs index 8662267..b2ef7d3 100644 --- a/src/Services/Flight/src/Flight/Seats/Models/SeatReadModel.cs +++ b/src/Services/Flight/src/Flight/Seats/Models/SeatReadModel.cs @@ -1,12 +1,14 @@ namespace Flight.Seats.Models; +using System; + public class SeatReadModel { - public long Id { get; init; } - public long SeatId { get; init; } + public Guid Id { get; init; } + public Guid SeatId { get; init; } public string SeatNumber { get; init; } public Enums.SeatType Type { get; init; } public Enums.SeatClass Class { get; init; } - public long FlightId { get; init; } + public Guid FlightId { get; init; } public bool IsDeleted { get; init; } } diff --git a/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs b/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs index 1739ad4..e693899 100644 --- a/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs +++ b/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs @@ -1,20 +1,21 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; using Flight.Flights.Enums; namespace EndToEnd.Test.Fakes; +using global::Flight.Data.Seed; using global::Flight.Flights.Features.CreatingFlight.V1; +using MassTransit; public sealed class FakeCreateFlightCommand : AutoFaker { public FakeCreateFlightCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); RuleFor(r => r.FlightNumber, r => "12FF"); - RuleFor(r => r.DepartureAirportId, _ => 1); - RuleFor(r => r.ArriveAirportId, _ => 2); + RuleFor(r => r.DepartureAirportId, _ => InitialData.Airports.First().Id); + RuleFor(r => r.ArriveAirportId, _ => InitialData.Airports.Last().Id); RuleFor(r => r.Status, _ => FlightStatus.Flying); - RuleFor(r => r.AircraftId, _ => 1); + RuleFor(r => r.AircraftId, _ => InitialData.Aircrafts.First().Id); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAircraftCommand.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAircraftCommand.cs index 6b322db..530326f 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAircraftCommand.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAircraftCommand.cs @@ -1,14 +1,14 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; namespace Integration.Test.Fakes; using global::Flight.Aircrafts.Features.CreatingAircraft.V1; +using MassTransit; public class FakeCreateAircraftCommand : AutoFaker { public FakeCreateAircraftCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAirportCommand.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAirportCommand.cs index 8d746c2..9c387b7 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAirportCommand.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateAirportCommand.cs @@ -1,14 +1,14 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; namespace Integration.Test.Fakes; using global::Flight.Airports.Features.CreatingAirport.V1; +using MassTransit; public class FakeCreateAirportCommand : AutoFaker { public FakeCreateAirportCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs index 20a133f..6655103 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs @@ -1,20 +1,22 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; using Flight.Flights.Enums; namespace Integration.Test.Fakes; +using System.Linq; +using global::Flight.Data.Seed; using global::Flight.Flights.Features.CreatingFlight.V1; +using MassTransit; public sealed class FakeCreateFlightCommand : AutoFaker { public FakeCreateFlightCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); - RuleFor(r => r.DepartureAirportId, _ => 1); - RuleFor(r => r.ArriveAirportId, _ => 2); + RuleFor(r => r.DepartureAirportId, _ => InitialData.Airports.First().Id); + RuleFor(r => r.ArriveAirportId, _ => InitialData.Airports.Last().Id); RuleFor(r => r.Status, _ => FlightStatus.Flying); - RuleFor(r => r.AircraftId, _ => 1); + RuleFor(r => r.AircraftId, _ => InitialData.Aircrafts.First().Id); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateSeatCommand.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateSeatCommand.cs index 28a6fa7..6ce1da0 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateSeatCommand.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateSeatCommand.cs @@ -1,16 +1,17 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; using Flight.Seats.Enums; namespace Integration.Test.Fakes; +using System; using global::Flight.Seats.Features.CreatingSeat.V1; +using MassTransit; public class FakeCreateSeatCommand : AutoFaker { - public FakeCreateSeatCommand(long flightId) + public FakeCreateSeatCommand(Guid flightId) { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); RuleFor(r => r.FlightId, _ => flightId); RuleFor(r => r.Class, _ => SeatClass.Economy); RuleFor(r => r.Type, _ => SeatType.Middle); diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs index 675d8ec..2566e5d 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/DeleteFlightTests.cs @@ -10,6 +10,7 @@ using Xunit; namespace Integration.Test.Flight.Features; +using global::Flight.Data.Seed; using global::Flight.Flights.Features.DeletingFlight.V1; public class DeleteFlightTests : FlightIntegrationTestBase @@ -23,7 +24,7 @@ public class DeleteFlightTests : FlightIntegrationTestBase public async Task should_delete_flight_from_db() { // Arrange - var flightEntity = await Fixture.FindAsync(1); + var flightEntity = await Fixture.FindAsync( InitialData.Flights.First().Id); var command = new DeleteFlight(flightEntity.Id); // Act diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs index 2d08ca6..b4016d0 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/GetFlightByIdTests.cs @@ -11,6 +11,7 @@ namespace Integration.Test.Flight.Features; using global::Flight.Flights.Features.CreatingFlight.V1; using global::Flight.Flights.Features.GettingFlightById.V1; +using Thrift.Protocol; public class GetFlightByIdTests : FlightIntegrationTestBase { @@ -50,10 +51,10 @@ public class GetFlightByIdTests : FlightIntegrationTestBase var flightGrpcClient = new FlightGrpcService.FlightGrpcServiceClient(Fixture.Channel); // Act - var response = await flightGrpcClient.GetByIdAsync(new GetByIdRequest {Id = 1}).ResponseAsync; + var response = await flightGrpcClient.GetByIdAsync(new GetByIdRequest {Id = command.Id.ToString()}).ResponseAsync; // Assert response?.Should().NotBeNull(); - // response?.Id.Should().Be(command.Id); + response?.FlightDto.Id.Should().Be(command.Id.ToString()); } } diff --git a/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs b/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs index 971ea25..20379e9 100644 --- a/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Flight/Features/UpdateFlightTests.cs @@ -9,6 +9,8 @@ using Xunit; namespace Integration.Test.Flight.Features; +using System.Linq; +using global::Flight.Data.Seed; using global::Flight.Flights.Features.UpdatingFlight.V1; public class UpdateFlightTests : FlightIntegrationTestBase @@ -22,7 +24,7 @@ public class UpdateFlightTests : FlightIntegrationTestBase public async Task should_update_flight_to_db_and_publish_message_to_broker() { // Arrange - var flightEntity = await Fixture.FindAsync(1); + var flightEntity = await Fixture.FindAsync( InitialData.Flights.First().Id); var command = new FakeUpdateFlightCommand(flightEntity).Generate(); // Act @@ -30,7 +32,7 @@ public class UpdateFlightTests : FlightIntegrationTestBase // Assert response.Should().NotBeNull(); - response?.Id.Should().Be(flightEntity?.Id); + response?.Id.Should().Be(flightEntity.Id); (await Fixture.WaitForPublishing()).Should().Be(true); diff --git a/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs b/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs index 5fd55b6..5b57ef4 100644 --- a/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Seat/Features/GetAvailableSeatsTests.cs @@ -38,7 +38,7 @@ public class GetAvailableSeatsTests : FlightIntegrationTestBase var flightGrpcClient = new FlightGrpcService.FlightGrpcServiceClient(Fixture.Channel); // Act - var response = await flightGrpcClient.GetAvailableSeatsAsync(new GetAvailableSeatsRequest{FlightId = flightCommand.Id}); + var response = await flightGrpcClient.GetAvailableSeatsAsync(new GetAvailableSeatsRequest{FlightId = flightCommand.Id.ToString()}); // Assert response?.Should().NotBeNull(); diff --git a/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs b/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs index 851efaa..3c04216 100644 --- a/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs +++ b/src/Services/Flight/tests/IntegrationTest/Seat/Features/ReserveSeatTests.cs @@ -40,11 +40,11 @@ public class ReserveSeatTests : FlightIntegrationTestBase // Act var response = await flightGrpcClient.ReserveSeatAsync(new ReserveSeatRequest() { - FlightId = seatCommand.FlightId, SeatNumber = seatCommand.SeatNumber + FlightId = seatCommand.FlightId.ToString(), SeatNumber = seatCommand.SeatNumber }); // Assert response?.Should().NotBeNull(); - response?.Id.Should().Be(seatCommand.Id); + response?.Id.Should().Be(seatCommand.Id.ToString()); } } diff --git a/src/Services/Flight/tests/UnitTest/Aircraft/Features/CreateAircraftTests/CreateAircraftCommandHandlerTests.cs b/src/Services/Flight/tests/UnitTest/Aircraft/Features/CreateAircraftTests/CreateAircraftCommandHandlerTests.cs index c7f869e..041aab1 100644 --- a/src/Services/Flight/tests/UnitTest/Aircraft/Features/CreateAircraftTests/CreateAircraftCommandHandlerTests.cs +++ b/src/Services/Flight/tests/UnitTest/Aircraft/Features/CreateAircraftTests/CreateAircraftCommandHandlerTests.cs @@ -39,7 +39,7 @@ public class CreateAircraftCommandHandlerTests var entity = await _fixture.DbContext.Aircraft.FindAsync(response?.Id); entity?.Should().NotBeNull(); - response?.Id.Should().Be(entity?.Id); + response?.Id.Should().Be(entity.Id); } [Fact] diff --git a/src/Services/Flight/tests/UnitTest/Airport/Features/CreateAirportTests/CreateAirportCommandHandlerTests.cs b/src/Services/Flight/tests/UnitTest/Airport/Features/CreateAirportTests/CreateAirportCommandHandlerTests.cs index 43e43c2..351eca0 100644 --- a/src/Services/Flight/tests/UnitTest/Airport/Features/CreateAirportTests/CreateAirportCommandHandlerTests.cs +++ b/src/Services/Flight/tests/UnitTest/Airport/Features/CreateAirportTests/CreateAirportCommandHandlerTests.cs @@ -40,7 +40,7 @@ public class CreateAirportCommandHandlerTests var entity = await _fixture.DbContext.Airports.FindAsync(response?.Id); entity?.Should().NotBeNull(); - response?.Id.Should().Be(entity?.Id); + response?.Id.Should().Be(entity.Id); } [Fact] diff --git a/src/Services/Flight/tests/UnitTest/Common/DbContextFactory.cs b/src/Services/Flight/tests/UnitTest/Common/DbContextFactory.cs index 50331a8..cdfa957 100644 --- a/src/Services/Flight/tests/UnitTest/Common/DbContextFactory.cs +++ b/src/Services/Flight/tests/UnitTest/Common/DbContextFactory.cs @@ -7,8 +7,17 @@ using Microsoft.EntityFrameworkCore; namespace Unit.Test.Common { + using MassTransit; + public static class DbContextFactory { + private static readonly Guid _airportId1 = NewId.NextGuid(); + private static readonly Guid _airportId2 = NewId.NextGuid(); + private static readonly Guid _aircraft1 = NewId.NextGuid(); + private static readonly Guid _aircraft2 = NewId.NextGuid(); + private static readonly Guid _aircraft3 = NewId.NextGuid(); + private static readonly Guid _flightId1 = NewId.NextGuid(); + public static FlightDbContext Create() { var options = new DbContextOptionsBuilder() @@ -26,26 +35,26 @@ namespace Unit.Test.Common { var airports = new List { - global::Flight.Airports.Models.Airport.Create(1, "Lisbon International Airport", "LIS", "12988"), - global::Flight.Airports.Models.Airport.Create(2, "Sao Paulo International Airport", "BRZ", "11200") + global::Flight.Airports.Models.Airport.Create(_airportId1, "Lisbon International Airport", "LIS", "12988"), + global::Flight.Airports.Models.Airport.Create(_airportId2, "Sao Paulo International Airport", "BRZ", "11200") }; context.Airports.AddRange(airports); var aircrafts = new List { - global::Flight.Aircrafts.Models.Aircraft.Create(1, "Boeing 737", "B737", 2005), - global::Flight.Aircrafts.Models.Aircraft.Create(2, "Airbus 300", "A300", 2000), - global::Flight.Aircrafts.Models.Aircraft.Create(3, "Airbus 320", "A320", 2003) + global::Flight.Aircrafts.Models.Aircraft.Create(_aircraft1, "Boeing 737", "B737", 2005), + global::Flight.Aircrafts.Models.Aircraft.Create(_aircraft2, "Airbus 300", "A300", 2000), + global::Flight.Aircrafts.Models.Aircraft.Create(_aircraft3, "Airbus 320", "A320", 2003) }; context.Aircraft.AddRange(aircrafts); var flights = new List { - global::Flight.Flights.Models.Flight.Create(1, "BD467", 1, 1, new DateTime(2022, 1, 31, 12, 0, 0), + global::Flight.Flights.Models.Flight.Create(_flightId1, "BD467", _aircraft1, _airportId1, new DateTime(2022, 1, 31, 12, 0, 0), new DateTime(2022, 1, 31, 14, 0, 0), - 2, 120m, + _airportId2, 120m, new DateTime(2022, 1, 31), FlightStatus.Completed, 8000) }; @@ -53,12 +62,12 @@ namespace Unit.Test.Common var seats = new List { - global::Flight.Seats.Models.Seat.Create(1, "12A", SeatType.Window, SeatClass.Economy, 1), - global::Flight.Seats.Models.Seat.Create(2, "12B", SeatType.Window, SeatClass.Economy, 1), - global::Flight.Seats.Models.Seat.Create(3, "12C", SeatType.Middle, SeatClass.Economy, 1), - global::Flight.Seats.Models.Seat.Create(4, "12D", SeatType.Middle, SeatClass.Economy, 1), - global::Flight.Seats.Models.Seat.Create(5, "12E", SeatType.Aisle, SeatClass.Economy, 1), - global::Flight.Seats.Models.Seat.Create(6, "12F", SeatType.Aisle, SeatClass.Economy, 1) + global::Flight.Seats.Models.Seat.Create(NewId.NextGuid(), "12A", SeatType.Window, SeatClass.Economy, _flightId1), + global::Flight.Seats.Models.Seat.Create(NewId.NextGuid(), "12B", SeatType.Window, SeatClass.Economy, _flightId1), + global::Flight.Seats.Models.Seat.Create(NewId.NextGuid(), "12C", SeatType.Middle, SeatClass.Economy, _flightId1), + global::Flight.Seats.Models.Seat.Create(NewId.NextGuid(), "12D", SeatType.Middle, SeatClass.Economy, _flightId1), + global::Flight.Seats.Models.Seat.Create(NewId.NextGuid(), "12E", SeatType.Aisle, SeatClass.Economy, _flightId1), + global::Flight.Seats.Models.Seat.Create(NewId.NextGuid(), "12F", SeatType.Aisle, SeatClass.Economy, _flightId1) }; context.Seats.AddRange(seats); diff --git a/src/Services/Flight/tests/UnitTest/Common/UnitTestFixture.cs b/src/Services/Flight/tests/UnitTest/Common/UnitTestFixture.cs index 0cfea73..08c9e44 100644 --- a/src/Services/Flight/tests/UnitTest/Common/UnitTestFixture.cs +++ b/src/Services/Flight/tests/UnitTest/Common/UnitTestFixture.cs @@ -1,5 +1,4 @@ using System; -using BuildingBlocks.IdsGenerator; using Flight.Data; using MapsterMapper; using Xunit; diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAircraftCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAircraftCommand.cs index 35326c3..913c900 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAircraftCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAircraftCommand.cs @@ -1,14 +1,14 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; namespace Unit.Test.Fakes; using global::Flight.Aircrafts.Features.CreatingAircraft.V1; +using MassTransit; public class FakeCreateAircraftCommand : AutoFaker { public FakeCreateAircraftCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); } } diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAirportCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAirportCommand.cs index 02c0be2..776a276 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAirportCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateAirportCommand.cs @@ -1,14 +1,14 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; namespace Unit.Test.Fakes; using global::Flight.Airports.Features.CreatingAirport.V1; +using MassTransit; public class FakeCreateAirportCommand : AutoFaker { public FakeCreateAirportCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); } } diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs index 7778b1d..d16dae7 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs @@ -1,18 +1,20 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; namespace Unit.Test.Fakes; +using System.Linq; +using global::Flight.Data.Seed; using global::Flight.Flights.Features.CreatingFlight.V1; +using MassTransit; public sealed class FakeCreateFlightCommand : AutoFaker { public FakeCreateFlightCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); - RuleFor(r => r.DepartureAirportId, _ => 1); - RuleFor(r => r.ArriveAirportId, _ => 2); - RuleFor(r => r.AircraftId, _ => 1); + RuleFor(r => r.DepartureAirportId, _ => InitialData.Airports.First().Id); + RuleFor(r => r.ArriveAirportId, _ => InitialData.Airports.Last().Id); + RuleFor(r => r.AircraftId, _ => InitialData.Aircrafts.First().Id); } } diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateSeatCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateSeatCommand.cs index edc3694..4cab5f0 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateSeatCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateSeatCommand.cs @@ -1,17 +1,19 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; using Flight.Seats.Enums; namespace Unit.Test.Fakes; +using System.Linq; +using global::Flight.Data.Seed; using global::Flight.Seats.Features.CreatingSeat.V1; +using MassTransit; public class FakeCreateSeatCommand : AutoFaker { public FakeCreateSeatCommand() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); - RuleFor(r => r.FlightId, _ => 1); + RuleFor(r => r.Id, _ => NewId.NextGuid()); + RuleFor(r => r.FlightId, _ => InitialData.Flights.First().Id); RuleFor(r => r.SeatNumber, _ => "F99"); RuleFor(r => r.Type, _ => SeatType.Window); RuleFor(r => r.Class, _ => SeatClass.Economy); diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeFlightUpdate.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeFlightUpdate.cs index b1e5087..ad3bc7f 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeFlightUpdate.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeFlightUpdate.cs @@ -6,7 +6,7 @@ public static class FakeFlightUpdate { public static void Generate(Flight flight) { - flight.Update(flight.Id, flight.FlightNumber, 3, flight.DepartureAirportId, flight.DepartureDate, - flight.ArriveDate, 3, flight.DurationMinutes, flight.FlightDate, flight.Status, flight.Price, flight.IsDeleted);; + flight.Update(flight.Id, flight.FlightNumber, flight.AircraftId, flight.DepartureAirportId, flight.DepartureDate, + flight.ArriveDate, flight.ArriveAirportId, flight.DurationMinutes, flight.FlightDate, flight.Status, 1000, flight.IsDeleted); } } diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateFlightCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateFlightCommand.cs index b869c6d..076045b 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateFlightCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateFlightCommand.cs @@ -12,9 +12,9 @@ public class FakeValidateCreateFlightCommand : AutoFaker { RuleFor(r => r.Price, _ => -10); RuleFor(r => r.Status, _ => (FlightStatus)10); - RuleFor(r => r.AircraftId, _ => 0); - RuleFor(r => r.DepartureAirportId, _ => 0); - RuleFor(r => r.ArriveAirportId, _ => 0); + RuleFor(r => r.AircraftId, _ => Guid.Empty); + RuleFor(r => r.DepartureAirportId, _ => Guid.Empty); + RuleFor(r => r.ArriveAirportId, _ => Guid.Empty); RuleFor(r => r.DurationMinutes, _ => 0); RuleFor(r => r.FlightDate, _ => new DateTime()); } diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateSeatCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateSeatCommand.cs index 7fd41f1..67e74be 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateSeatCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeValidateCreateSeatCommand.cs @@ -3,6 +3,7 @@ using Flight.Seats.Enums; namespace Unit.Test.Fakes; +using System; using global::Flight.Seats.Features.CreatingSeat.V1; public class FakeValidateCreateSeatCommand : AutoFaker @@ -10,7 +11,7 @@ public class FakeValidateCreateSeatCommand : AutoFaker public FakeValidateCreateSeatCommand() { RuleFor(r => r.SeatNumber, _ => null); - RuleFor(r => r.FlightId, _ => 0); + RuleFor(r => r.FlightId, _ => Guid.Empty); RuleFor(r => r.Class, _ => (SeatClass)10); } } diff --git a/src/Services/Flight/tests/UnitTest/Flight/Features/Commands/CreateFlight/CreateFlightCommandHandlerTests.cs b/src/Services/Flight/tests/UnitTest/Flight/Features/Commands/CreateFlight/CreateFlightCommandHandlerTests.cs index 3d2ecf3..bf6ccf0 100644 --- a/src/Services/Flight/tests/UnitTest/Flight/Features/Commands/CreateFlight/CreateFlightCommandHandlerTests.cs +++ b/src/Services/Flight/tests/UnitTest/Flight/Features/Commands/CreateFlight/CreateFlightCommandHandlerTests.cs @@ -38,7 +38,7 @@ public class CreateFlightCommandHandlerTests var entity = await _fixture.DbContext.Flights.FindAsync(response?.Id); entity?.Should().NotBeNull(); - response?.Id.Should().Be(entity?.Id); + response?.Id.Should().Be(entity.Id); } [Fact] diff --git a/src/Services/Flight/tests/UnitTest/Flight/Features/Domain/UpdateFlightTests.cs b/src/Services/Flight/tests/UnitTest/Flight/Features/Domain/UpdateFlightTests.cs index de5b5bc..37e46fa 100644 --- a/src/Services/Flight/tests/UnitTest/Flight/Features/Domain/UpdateFlightTests.cs +++ b/src/Services/Flight/tests/UnitTest/Flight/Features/Domain/UpdateFlightTests.cs @@ -20,8 +20,7 @@ public class UpdateFlightTests FakeFlightUpdate.Generate(fakeFlight); // Assert - fakeFlight.ArriveAirportId.Should().Be(3); - fakeFlight.AircraftId.Should().Be(3); + fakeFlight.Price.Should().Be(1000); } [Fact] diff --git a/src/Services/Flight/tests/UnitTest/Seat/Features/CreateSeatCommandHandlerTests.cs b/src/Services/Flight/tests/UnitTest/Seat/Features/CreateSeatCommandHandlerTests.cs index 72a6281..3a8488b 100644 --- a/src/Services/Flight/tests/UnitTest/Seat/Features/CreateSeatCommandHandlerTests.cs +++ b/src/Services/Flight/tests/UnitTest/Seat/Features/CreateSeatCommandHandlerTests.cs @@ -42,7 +42,7 @@ public class CreateSeatCommandHandlerTests var entity = await _fixture.DbContext.Seats.FindAsync(response?.Id); entity?.Should().NotBeNull(); - response?.Id.Should().Be(entity?.Id); + response?.Id.Should().Be(entity.Id); } [Fact] diff --git a/src/Services/Identity/src/Identity.Api/.env b/src/Services/Identity/src/Identity.Api/.env deleted file mode 100644 index 8f92016..0000000 --- a/src/Services/Identity/src/Identity.Api/.env +++ /dev/null @@ -1 +0,0 @@ -GENERATOR_ID=2 diff --git a/src/Services/Identity/src/Identity/Data/IdentityContext.cs b/src/Services/Identity/src/Identity/Data/IdentityContext.cs index b0c5753..8dbf27f 100644 --- a/src/Services/Identity/src/Identity/Data/IdentityContext.cs +++ b/src/Services/Identity/src/Identity/Data/IdentityContext.cs @@ -18,7 +18,7 @@ namespace Identity.Data; using System; -public sealed class IdentityContext : IdentityDbContext, IDbContext { public IdentityContext(DbContextOptions options) : base(options) diff --git a/src/Services/Identity/src/Identity/Data/Migrations/20230122204905_initial.Designer.cs b/src/Services/Identity/src/Identity/Data/Migrations/20230331193410_initial.Designer.cs similarity index 92% rename from src/Services/Identity/src/Identity/Data/Migrations/20230122204905_initial.Designer.cs rename to src/Services/Identity/src/Identity/Data/Migrations/20230331193410_initial.Designer.cs index b61807d..40c2889 100644 --- a/src/Services/Identity/src/Identity/Data/Migrations/20230122204905_initial.Designer.cs +++ b/src/Services/Identity/src/Identity/Data/Migrations/20230331193410_initial.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace Identity.Data.Migrations { [DbContext(typeof(IdentityContext))] - [Migration("20230122204905_initial")] + [Migration("20230331193410_initial")] partial class initial { /// @@ -20,20 +20,18 @@ namespace Identity.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Identity.Identity.Models.Role", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint") + .HasColumnType("uuid") .HasColumnName("id"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasColumnType("text") @@ -81,8 +79,8 @@ namespace Identity.Data.Migrations .HasColumnType("text") .HasColumnName("claim_value"); - b.Property("RoleId") - .HasColumnType("bigint") + b.Property("RoleId") + .HasColumnType("uuid") .HasColumnName("role_id"); b.Property("Version") @@ -101,13 +99,11 @@ namespace Identity.Data.Migrations modelBuilder.Entity("Identity.Identity.Models.User", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint") + .HasColumnType("uuid") .HasColumnName("id"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("AccessFailedCount") .HasColumnType("integer") .HasColumnName("access_failed_count"); @@ -216,8 +212,8 @@ namespace Identity.Data.Migrations .HasColumnType("text") .HasColumnName("claim_value"); - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); b.Property("Version") @@ -248,8 +244,8 @@ namespace Identity.Data.Migrations .HasColumnType("text") .HasColumnName("provider_display_name"); - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); b.Property("Version") @@ -268,12 +264,12 @@ namespace Identity.Data.Migrations modelBuilder.Entity("Identity.Identity.Models.UserRole", b => { - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); - b.Property("RoleId") - .HasColumnType("bigint") + b.Property("RoleId") + .HasColumnType("uuid") .HasColumnName("role_id"); b.Property("Version") @@ -292,8 +288,8 @@ namespace Identity.Data.Migrations modelBuilder.Entity("Identity.Identity.Models.UserToken", b => { - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); b.Property("LoginProvider") diff --git a/src/Services/Identity/src/Identity/Data/Migrations/20230122204905_initial.cs b/src/Services/Identity/src/Identity/Data/Migrations/20230331193410_initial.cs similarity index 91% rename from src/Services/Identity/src/Identity/Data/Migrations/20230122204905_initial.cs rename to src/Services/Identity/src/Identity/Data/Migrations/20230331193410_initial.cs index be11c3a..ec60a88 100644 --- a/src/Services/Identity/src/Identity/Data/Migrations/20230122204905_initial.cs +++ b/src/Services/Identity/src/Identity/Data/Migrations/20230331193410_initial.cs @@ -16,8 +16,7 @@ namespace Identity.Data.Migrations name: "asp_net_roles", columns: table => new { - id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + id = table.Column(type: "uuid", nullable: false), version = table.Column(type: "bigint", nullable: false), name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), normalizedname = table.Column(name: "normalized_name", type: "character varying(256)", maxLength: 256, nullable: true), @@ -32,8 +31,7 @@ namespace Identity.Data.Migrations name: "asp_net_users", columns: table => new { - id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + id = table.Column(type: "uuid", nullable: false), firstname = table.Column(name: "first_name", type: "text", nullable: true), lastname = table.Column(name: "last_name", type: "text", nullable: true), passportnumber = table.Column(name: "pass_port_number", type: "text", nullable: true), @@ -65,7 +63,7 @@ namespace Identity.Data.Migrations id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), version = table.Column(type: "bigint", nullable: false), - roleid = table.Column(name: "role_id", type: "bigint", nullable: false), + roleid = table.Column(name: "role_id", type: "uuid", nullable: false), claimtype = table.Column(name: "claim_type", type: "text", nullable: true), claimvalue = table.Column(name: "claim_value", type: "text", nullable: true) }, @@ -87,7 +85,7 @@ namespace Identity.Data.Migrations id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), version = table.Column(type: "bigint", nullable: false), - userid = table.Column(name: "user_id", type: "bigint", nullable: false), + userid = table.Column(name: "user_id", type: "uuid", nullable: false), claimtype = table.Column(name: "claim_type", type: "text", nullable: true), claimvalue = table.Column(name: "claim_value", type: "text", nullable: true) }, @@ -110,7 +108,7 @@ namespace Identity.Data.Migrations providerkey = table.Column(name: "provider_key", type: "text", nullable: false), version = table.Column(type: "bigint", nullable: false), providerdisplayname = table.Column(name: "provider_display_name", type: "text", nullable: true), - userid = table.Column(name: "user_id", type: "bigint", nullable: false) + userid = table.Column(name: "user_id", type: "uuid", nullable: false) }, constraints: table => { @@ -127,8 +125,8 @@ namespace Identity.Data.Migrations name: "asp_net_user_roles", columns: table => new { - userid = table.Column(name: "user_id", type: "bigint", nullable: false), - roleid = table.Column(name: "role_id", type: "bigint", nullable: false), + userid = table.Column(name: "user_id", type: "uuid", nullable: false), + roleid = table.Column(name: "role_id", type: "uuid", nullable: false), version = table.Column(type: "bigint", nullable: false) }, constraints: table => @@ -152,7 +150,7 @@ namespace Identity.Data.Migrations name: "asp_net_user_tokens", columns: table => new { - userid = table.Column(name: "user_id", type: "bigint", nullable: false), + userid = table.Column(name: "user_id", type: "uuid", nullable: false), loginprovider = table.Column(name: "login_provider", type: "text", nullable: false), name = table.Column(type: "text", nullable: false), version = table.Column(type: "bigint", nullable: false), diff --git a/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs b/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs index 8d2b002..ce8faa3 100644 --- a/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs +++ b/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs @@ -17,20 +17,18 @@ namespace Identity.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Identity.Identity.Models.Role", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint") + .HasColumnType("uuid") .HasColumnName("id"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasColumnType("text") @@ -78,8 +76,8 @@ namespace Identity.Data.Migrations .HasColumnType("text") .HasColumnName("claim_value"); - b.Property("RoleId") - .HasColumnType("bigint") + b.Property("RoleId") + .HasColumnType("uuid") .HasColumnName("role_id"); b.Property("Version") @@ -98,13 +96,11 @@ namespace Identity.Data.Migrations modelBuilder.Entity("Identity.Identity.Models.User", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint") + .HasColumnType("uuid") .HasColumnName("id"); - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("AccessFailedCount") .HasColumnType("integer") .HasColumnName("access_failed_count"); @@ -213,8 +209,8 @@ namespace Identity.Data.Migrations .HasColumnType("text") .HasColumnName("claim_value"); - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); b.Property("Version") @@ -245,8 +241,8 @@ namespace Identity.Data.Migrations .HasColumnType("text") .HasColumnName("provider_display_name"); - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); b.Property("Version") @@ -265,12 +261,12 @@ namespace Identity.Data.Migrations modelBuilder.Entity("Identity.Identity.Models.UserRole", b => { - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); - b.Property("RoleId") - .HasColumnType("bigint") + b.Property("RoleId") + .HasColumnType("uuid") .HasColumnName("role_id"); b.Property("Version") @@ -289,8 +285,8 @@ namespace Identity.Data.Migrations modelBuilder.Entity("Identity.Identity.Models.UserToken", b => { - b.Property("UserId") - .HasColumnType("bigint") + b.Property("UserId") + .HasColumnType("uuid") .HasColumnName("user_id"); b.Property("LoginProvider") diff --git a/src/Services/Identity/src/Identity/Data/Seed/IdentityDataSeeder.cs b/src/Services/Identity/src/Identity/Data/Seed/IdentityDataSeeder.cs index a953735..e1abb61 100644 --- a/src/Services/Identity/src/Identity/Data/Seed/IdentityDataSeeder.cs +++ b/src/Services/Identity/src/Identity/Data/Seed/IdentityDataSeeder.cs @@ -9,6 +9,8 @@ using Microsoft.AspNetCore.Identity; namespace Identity.Data.Seed; +using System.Linq; + public class IdentityDataSeeder : IDataSeeder { private readonly UserManager _userManager; @@ -33,55 +35,39 @@ public class IdentityDataSeeder : IDataSeeder private async Task SeedRoles() { if (await _roleManager.RoleExistsAsync(Constants.Role.Admin) == false) + { await _roleManager.CreateAsync(new Role {Name = Constants.Role.Admin}); + } if (await _roleManager.RoleExistsAsync(Constants.Role.User) == false) + { await _roleManager.CreateAsync(new Role {Name = Constants.Role.User}); + } } private async Task SeedUsers() { if (await _userManager.FindByNameAsync("samh") == null) { - var user = new User - { - FirstName = "Sam", - LastName = "H", - UserName = "samh", - PassPortNumber = "123456789", - Email = "sam@test.com", - SecurityStamp = Guid.NewGuid().ToString() - }; - - var result = await _userManager.CreateAsync(user, "Admin@123456"); + var result = await _userManager.CreateAsync(InitialData.Users.First(), "Admin@123456"); if (result.Succeeded) { - await _userManager.AddToRoleAsync(user, Constants.Role.Admin); + await _userManager.AddToRoleAsync(InitialData.Users.First(), Constants.Role.Admin); - await _eventDispatcher.SendAsync(new UserCreated(user.Id, user.FirstName + " " + user.LastName, user.PassPortNumber)); + await _eventDispatcher.SendAsync(new UserCreated(InitialData.Users.First().Id, InitialData.Users.First().FirstName + " " + InitialData.Users.First().LastName, InitialData.Users.First().PassPortNumber)); } } if (await _userManager.FindByNameAsync("meysamh2") == null) { - var user = new User - { - FirstName = "Sam2", - LastName = "H2", - UserName = "samh2", - PassPortNumber = "987654321", - Email = "sam2@test.com", - SecurityStamp = Guid.NewGuid().ToString() - }; - - var result = await _userManager.CreateAsync(user, "User@123456"); + var result = await _userManager.CreateAsync(InitialData.Users.Last(), "User@123456"); if (result.Succeeded) { - await _userManager.AddToRoleAsync(user, Constants.Role.User); + await _userManager.AddToRoleAsync(InitialData.Users.Last(), Constants.Role.User); - await _eventDispatcher.SendAsync(new UserCreated(user.Id, user.FirstName + " " + user.LastName, user.PassPortNumber)); + await _eventDispatcher.SendAsync(new UserCreated(InitialData.Users.Last().Id, InitialData.Users.Last().FirstName + " " + InitialData.Users.Last().LastName, InitialData.Users.Last().PassPortNumber)); } } } diff --git a/src/Services/Identity/src/Identity/Data/Seed/InitialData.cs b/src/Services/Identity/src/Identity/Data/Seed/InitialData.cs new file mode 100644 index 0000000..8ff1bd1 --- /dev/null +++ b/src/Services/Identity/src/Identity/Data/Seed/InitialData.cs @@ -0,0 +1,38 @@ +namespace Identity.Data.Seed; + +using System; +using System.Collections.Generic; +using Identity.Models; +using MassTransit; + +public static class InitialData +{ + public static List Users { get; } + + static InitialData() + { + Users = new List + { + new User + { + Id = NewId.NextGuid(), + FirstName = "Sam", + LastName = "H", + UserName = "samh", + PassPortNumber = "123456789", + Email = "sam@test.com", + SecurityStamp = Guid.NewGuid().ToString() + }, + new User + { + Id = NewId.NextGuid(), + FirstName = "Sam2", + LastName = "H2", + UserName = "samh2", + PassPortNumber = "987654321", + Email = "sam2@test.com", + SecurityStamp = Guid.NewGuid().ToString() + } + }; + } +} diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index 563c523..dda6493 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -35,9 +35,6 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - // https://github.com/tonerdo/dotnet-env - DotNetEnv.Env.TraversePath().Load(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUser.cs b/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUser.cs index df331d3..b3fddd1 100644 --- a/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUser.cs +++ b/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUser.cs @@ -1,5 +1,6 @@ namespace Identity.Identity.Features.RegisteringNewUser.V1; +using System; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -15,7 +16,7 @@ using Models; public record RegisterNewUser(string FirstName, string LastName, string Username, string Email, string Password, string ConfirmPassword, string PassportNumber) : ICommand; -public record RegisterNewUserResult(long Id, string FirstName, string LastName, string Username, string PassportNumber); +public record RegisterNewUserResult(Guid Id, string FirstName, string LastName, string Username, string PassportNumber); internal class RegisterNewUserValidator : AbstractValidator { diff --git a/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUserEndpoint.cs b/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUserEndpoint.cs index 8dc3d14..a3b11ca 100644 --- a/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUserEndpoint.cs +++ b/src/Services/Identity/src/Identity/Identity/Features/RegisteringNewUser/V1/RegisterNewUserEndpoint.cs @@ -1,5 +1,6 @@ namespace Identity.Identity.Features.RegisteringNewUser.V1; +using System; using System.Threading; using System.Threading.Tasks; using BuildingBlocks.Web; @@ -13,7 +14,7 @@ using Swashbuckle.AspNetCore.Annotations; public record RegisterNewUserRequestDto(string FirstName, string LastName, string Username, string Email, string Password, string ConfirmPassword, string PassportNumber); -public record RegisterNewUserResponseDto(long Id, string FirstName, string LastName, string Username, string PassportNumber); +public record RegisterNewUserResponseDto(Guid Id, string FirstName, string LastName, string Username, string PassportNumber); public class RegisterNewUserEndpoint : IMinimalEndpoint { diff --git a/src/Services/Identity/src/Identity/Identity/Models/Role.cs b/src/Services/Identity/src/Identity/Identity/Models/Role.cs index 97e9333..832db45 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/Role.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/Role.cs @@ -1,9 +1,10 @@ namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; using Microsoft.AspNetCore.Identity; -public class Role: IdentityRole, IVersion +public class Role: IdentityRole, IVersion { public long Version { get; set; } } diff --git a/src/Services/Identity/src/Identity/Identity/Models/RoleClaim.cs b/src/Services/Identity/src/Identity/Identity/Models/RoleClaim.cs index 0ad6972..1e2110f 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/RoleClaim.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/RoleClaim.cs @@ -1,9 +1,10 @@ namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; using Microsoft.AspNetCore.Identity; -public class RoleClaim: IdentityRoleClaim, IVersion +public class RoleClaim: IdentityRoleClaim, IVersion { public long Version { get; set; } } diff --git a/src/Services/Identity/src/Identity/Identity/Models/User.cs b/src/Services/Identity/src/Identity/Identity/Models/User.cs index bfc999f..1227223 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/User.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/User.cs @@ -2,9 +2,10 @@ using Microsoft.AspNetCore.Identity; namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; -public class User : IdentityUser, IVersion +public class User : IdentityUser, IVersion { public string FirstName { get; init; } public string LastName { get; init; } diff --git a/src/Services/Identity/src/Identity/Identity/Models/UserClaim.cs b/src/Services/Identity/src/Identity/Identity/Models/UserClaim.cs index 2e1fa22..1f9398e 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/UserClaim.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/UserClaim.cs @@ -1,9 +1,10 @@ namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; using Microsoft.AspNetCore.Identity; -public class UserClaim: IdentityUserClaim, IVersion +public class UserClaim: IdentityUserClaim, IVersion { public long Version { get; set; } } diff --git a/src/Services/Identity/src/Identity/Identity/Models/UserLogin.cs b/src/Services/Identity/src/Identity/Identity/Models/UserLogin.cs index ffe9e42..e3191d5 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/UserLogin.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/UserLogin.cs @@ -1,9 +1,10 @@ namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; using Microsoft.AspNetCore.Identity; -public class UserLogin: IdentityUserLogin, IVersion +public class UserLogin: IdentityUserLogin, IVersion { public long Version { get; set; } } diff --git a/src/Services/Identity/src/Identity/Identity/Models/UserRole.cs b/src/Services/Identity/src/Identity/Identity/Models/UserRole.cs index 403a1e4..6de6778 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/UserRole.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/UserRole.cs @@ -1,9 +1,10 @@ namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; using Microsoft.AspNetCore.Identity; -public class UserRole: IdentityUserRole, IVersion +public class UserRole: IdentityUserRole, IVersion { public long Version { get; set; } } diff --git a/src/Services/Identity/src/Identity/Identity/Models/UserToken.cs b/src/Services/Identity/src/Identity/Identity/Models/UserToken.cs index 8b3a8c6..ae43e28 100644 --- a/src/Services/Identity/src/Identity/Identity/Models/UserToken.cs +++ b/src/Services/Identity/src/Identity/Identity/Models/UserToken.cs @@ -1,9 +1,10 @@ namespace Identity.Identity.Models; +using System; using BuildingBlocks.Core.Model; using Microsoft.AspNetCore.Identity; -public class UserToken: IdentityUserToken, IVersion +public class UserToken: IdentityUserToken, IVersion { public long Version { get; set; } } diff --git a/src/Services/Passenger/src/Passenger.Api/.env b/src/Services/Passenger/src/Passenger.Api/.env deleted file mode 100644 index 2b3b264..0000000 --- a/src/Services/Passenger/src/Passenger.Api/.env +++ /dev/null @@ -1 +0,0 @@ -GENERATOR_ID=3 diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20230120222631_initial.Designer.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20230331204805_initial.Designer.cs similarity index 93% rename from src/Services/Passenger/src/Passenger/Data/Migrations/20230120222631_initial.Designer.cs rename to src/Services/Passenger/src/Passenger/Data/Migrations/20230331204805_initial.Designer.cs index 4a9eca5..dd13574 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20230120222631_initial.Designer.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/20230331204805_initial.Designer.cs @@ -12,7 +12,7 @@ using Passenger.Data; namespace Passenger.Data.Migrations { [DbContext(typeof(PassengerDbContext))] - [Migration("20230120222631_initial")] + [Migration("20230331204805_initial")] partial class initial { /// @@ -20,15 +20,15 @@ namespace Passenger.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Age") diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20230120222631_initial.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20230331204805_initial.cs similarity index 95% rename from src/Services/Passenger/src/Passenger/Data/Migrations/20230120222631_initial.cs rename to src/Services/Passenger/src/Passenger/Data/Migrations/20230331204805_initial.cs index 9c98b8f..76644b2 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20230120222631_initial.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/20230331204805_initial.cs @@ -15,7 +15,7 @@ namespace Passenger.Data.Migrations name: "passenger", columns: table => new { - id = table.Column(type: "bigint", nullable: false), + id = table.Column(type: "uuid", nullable: false), passportnumber = table.Column(name: "passport_number", type: "text", nullable: true), name = table.Column(type: "text", nullable: true), passengertype = table.Column(name: "passenger_type", type: "integer", nullable: false), diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs index 6612a81..2614a28 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs @@ -17,15 +17,15 @@ namespace Passenger.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("ProductVersion", "7.0.2") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => { - b.Property("Id") - .HasColumnType("bigint") + b.Property("Id") + .HasColumnType("uuid") .HasColumnName("id"); b.Property("Age") diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index 27faf7a..baac1d9 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -35,9 +35,6 @@ public static class InfrastructureExtensions var configuration = builder.Configuration; var env = builder.Environment; - // https://github.com/tonerdo/dotnet-env - DotNetEnv.Env.TraversePath().Load(); - builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/src/Services/Passenger/src/Passenger/GrpcServer/Protos/passenger.proto b/src/Services/Passenger/src/Passenger/GrpcServer/Protos/passenger.proto index 61e0d49..bb98c29 100644 --- a/src/Services/Passenger/src/Passenger/GrpcServer/Protos/passenger.proto +++ b/src/Services/Passenger/src/Passenger/GrpcServer/Protos/passenger.proto @@ -8,11 +8,15 @@ service PassengerGrpcService { } message GetByIdRequest { - int64 Id = 1; + string Id = 1; +} + +message GetPassengerByIdResult { + PassengerResponse PassengerDto = 1; } message PassengerResponse { - int64 Id = 1; + string Id = 1; string Name = 2; string PassportNumber = 3; PassengerType PassengerType = 4; @@ -20,10 +24,6 @@ message PassengerResponse { string Email = 6; } -message GetPassengerByIdResult { - PassengerResponse PassengerDto = 1; -} - enum PassengerType { PASSENGER_TYPE_UNKNOWN = 0; diff --git a/src/Services/Passenger/src/Passenger/GrpcServer/Services/PassengerGrpcServices.cs b/src/Services/Passenger/src/Passenger/GrpcServer/Services/PassengerGrpcServices.cs index 1a7dca6..b30c634 100644 --- a/src/Services/Passenger/src/Passenger/GrpcServer/Services/PassengerGrpcServices.cs +++ b/src/Services/Passenger/src/Passenger/GrpcServer/Services/PassengerGrpcServices.cs @@ -1,11 +1,11 @@ using Grpc.Core; -using Mapster; using MediatR; namespace Passenger.GrpcServer.Services; +using Mapster; using Passengers.Features.GettingPassengerById.Queries.V1; -using GetPassengerByIdResult = GetPassengerByIdResult; +using GetPassengerByIdResult = Passenger.GetPassengerByIdResult; public class PassengerGrpcServices : PassengerGrpcService.PassengerGrpcServiceBase { @@ -18,7 +18,7 @@ public class PassengerGrpcServices : PassengerGrpcService.PassengerGrpcServiceBa public override async Task GetById(GetByIdRequest request, ServerCallContext context) { - var result = await _mediator.Send(new GetPassengerById(request.Id)); - return result.Adapt(); + var result = await _mediator.Send(new GetPassengerById(new Guid(request.Id))); + return result?.Adapt(); } } diff --git a/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/PassengerCreatedDomainEvent.cs b/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/PassengerCreatedDomainEvent.cs index 78ec968..ce31b86 100644 --- a/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/PassengerCreatedDomainEvent.cs +++ b/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/PassengerCreatedDomainEvent.cs @@ -2,4 +2,4 @@ using BuildingBlocks.Core.Event; -public record PassengerCreatedDomainEvent(long Id, string Name, string PassportNumber, bool IsDeleted = false) : IDomainEvent; +public record PassengerCreatedDomainEvent(Guid Id, string Name, string PassportNumber, bool IsDeleted = false) : IDomainEvent; diff --git a/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/RegisterNewUser.cs b/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/RegisterNewUser.cs index 08c417c..27456a8 100644 --- a/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/RegisterNewUser.cs +++ b/src/Services/Passenger/src/Passenger/Identity/Consumers/RegisteringNewUser/V1/RegisterNewUser.cs @@ -4,14 +4,13 @@ using Ardalis.GuardClauses; using BuildingBlocks.Contracts.EventBus.Messages; using BuildingBlocks.Core; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; using BuildingBlocks.Web; using Humanizer; using MassTransit; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Passenger.Data; +using Data; public class RegisterNewUserHandler : IConsumer { @@ -45,7 +44,7 @@ public class RegisterNewUserHandler : IConsumer return; } - var passenger = Passengers.Models.Passenger.Create(SnowflakeIdGenerator.NewId(), context.Message.Name, + var passenger = Passengers.Models.Passenger.Create(NewId.NextGuid(), context.Message.Name, context.Message.PassportNumber); await _passengerDbContext.AddAsync(passenger); diff --git a/src/Services/Passenger/src/Passenger/Passengers/Dtos/PassengerDto.cs b/src/Services/Passenger/src/Passenger/Passengers/Dtos/PassengerDto.cs index e534d2f..6038e9f 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Dtos/PassengerDto.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Dtos/PassengerDto.cs @@ -2,7 +2,7 @@ namespace Passenger.Passengers.Dtos; public record PassengerDto { - public long Id { get; init; } + public Guid Id { get; init; } public string Name { get; init; } public string PassportNumber { get; init; } public Enums.PassengerType PassengerType { get; init; } diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassenger.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassenger.cs index 62411ea..2deb275 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassenger.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassenger.cs @@ -3,17 +3,17 @@ namespace Passenger.Passengers.Features.CompletingRegisterPassenger.V1; using Ardalis.GuardClauses; using BuildingBlocks.Core.CQRS; using BuildingBlocks.Core.Event; -using BuildingBlocks.IdsGenerator; using Exceptions; using FluentValidation; using MapsterMapper; using Microsoft.EntityFrameworkCore; using Data; using Dtos; +using MassTransit; public record CompleteRegisterPassenger(string PassportNumber, Enums.PassengerType PassengerType, int Age) : ICommand, IInternalCommand { - public long Id { get; init; } = SnowflakeIdGenerator.NewId(); + public Guid Id { get; init; } = NewId.NextGuid(); } public record CompleteRegisterPassengerResult(PassengerDto PassengerDto); diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassengerMongo.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassengerMongo.cs index a7a0b9a..226153d 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassengerMongo.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/CompleteRegisterPassengerMongo.cs @@ -8,9 +8,9 @@ using MediatR; using Models; using MongoDB.Driver; using MongoDB.Driver.Linq; -using Passenger.Data; +using Data; -public record CompleteRegisterPassengerMongoCommand(long Id, string PassportNumber, string Name, +public record CompleteRegisterPassengerMongoCommand(Guid Id, string PassportNumber, string Name, Enums.PassengerType PassengerType, int Age, bool IsDeleted) : InternalCommand; diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/PassengerRegistrationCompletedDomainEvent.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/PassengerRegistrationCompletedDomainEvent.cs index 1adee6f..0e95529 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/PassengerRegistrationCompletedDomainEvent.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/CompletingRegisterPassenger/V1/PassengerRegistrationCompletedDomainEvent.cs @@ -2,5 +2,5 @@ namespace Passenger.Passengers.Features.CompletingRegisterPassenger.V1; using BuildingBlocks.Core.Event; -public record PassengerRegistrationCompletedDomainEvent(long Id, string Name, string PassportNumber, +public record PassengerRegistrationCompletedDomainEvent(Guid Id, string Name, string PassportNumber, Enums.PassengerType PassengerType, int Age, bool IsDeleted = false) : IDomainEvent; diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerById.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerById.cs index 6198289..3390841 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerById.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerById.cs @@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore; using Ardalis.GuardClauses; using Exceptions; -public record GetPassengerById(long Id) : IQuery; +public record GetPassengerById(Guid Id) : IQuery; public record GetPassengerByIdResult(PassengerDto PassengerDto); diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerByIdEndpoint.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerByIdEndpoint.cs index 581a27e..79cb838 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerByIdEndpoint.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/GettingPassengerById/Queries/V1/GetPassengerByIdEndpoint.cs @@ -26,7 +26,7 @@ public class GetPassengerByIdEndpoint : IMinimalEndpoint return builder; } - private async Task GetById(long id, IMediator mediator, CancellationToken cancellationToken) + private async Task GetById(Guid id, IMediator mediator, CancellationToken cancellationToken) { var result = await mediator.Send(new GetPassengerById(id), cancellationToken); diff --git a/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs b/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs index 42bcbc3..0dc5b45 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Features/PassengerMappings.cs @@ -1,9 +1,9 @@ -using BuildingBlocks.IdsGenerator; using Mapster; namespace Passenger.Passengers.Features; using CompletingRegisterPassenger.V1; +using MassTransit; using Models; public class PassengerMappings : IRegister @@ -11,7 +11,7 @@ public class PassengerMappings : IRegister public void Register(TypeAdapterConfig config) { config.NewConfig() - .Map(d => d.Id, s => SnowflakeIdGenerator.NewId()) + .Map(d => d.Id, s => NewId.NextGuid()) .Map(d => d.PassengerId, s => s.Id); config.NewConfig() diff --git a/src/Services/Passenger/src/Passenger/Passengers/Models/Passenger.cs b/src/Services/Passenger/src/Passenger/Passengers/Models/Passenger.cs index 79258dd..638218e 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Models/Passenger.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Models/Passenger.cs @@ -5,9 +5,9 @@ namespace Passenger.Passengers.Models; using Features.CompletingRegisterPassenger.V1; using Identity.Consumers.RegisteringNewUser.V1; -public record Passenger : Aggregate +public record Passenger : Aggregate { - public Passenger CompleteRegistrationPassenger(long id, string name, string passportNumber, Enums.PassengerType passengerType, int age, bool isDeleted = false) + public Passenger CompleteRegistrationPassenger(Guid id, string name, string passportNumber, Enums.PassengerType passengerType, int age, bool isDeleted = false) { var passenger = new Passenger { @@ -28,7 +28,7 @@ public record Passenger : Aggregate } - public static Passenger Create(long id, string name, string passportNumber, bool isDeleted = false) + public static Passenger Create(Guid id, string name, string passportNumber, bool isDeleted = false) { var passenger = new Passenger { Id = id, Name = name, PassportNumber = passportNumber, IsDeleted = isDeleted }; diff --git a/src/Services/Passenger/src/Passenger/Passengers/Models/PassengerReadModel.cs b/src/Services/Passenger/src/Passenger/Passengers/Models/PassengerReadModel.cs index a9f24a2..2cca579 100644 --- a/src/Services/Passenger/src/Passenger/Passengers/Models/PassengerReadModel.cs +++ b/src/Services/Passenger/src/Passenger/Passengers/Models/PassengerReadModel.cs @@ -2,8 +2,8 @@ public class PassengerReadModel { - public long Id { get; init; } - public long PassengerId { get; init; } + public Guid Id { get; init; } + public Guid PassengerId { get; init; } public string PassportNumber { get; init; } public string Name { get; init; } public Enums.PassengerType PassengerType { get; init; } diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs index 1ce809b..e0cdc64 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeCompleteRegisterPassengerCommand.cs @@ -1,16 +1,16 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; using Passenger.Passengers.Enums; namespace Integration.Test.Fakes; using global::Passenger.Passengers.Features.CompletingRegisterPassenger.V1; +using MassTransit; public sealed class FakeCompleteRegisterPassengerCommand : AutoFaker { public FakeCompleteRegisterPassengerCommand(string passportNumber) { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); RuleFor(r => r.PassportNumber, _ => passportNumber); RuleFor(r => r.PassengerType, _ => PassengerType.Male); RuleFor(r => r.Age, _ => 30); diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs index 2a84a36..bbde1f7 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerCreated.cs @@ -1,12 +1,13 @@ using BuildingBlocks.Contracts.EventBus.Messages; -using BuildingBlocks.IdsGenerator; namespace Integration.Test.Fakes; +using MassTransit; + public static class FakePassengerCreated { public static global::Passenger.Passengers.Models.Passenger Generate(UserCreated userCreated) { - return global::Passenger.Passengers.Models.Passenger.Create(SnowflakeIdGenerator.NewId(), userCreated.Name, userCreated.PassportNumber); + return global::Passenger.Passengers.Models.Passenger.Create(NewId.NextGuid(), userCreated.Name, userCreated.PassportNumber); } } diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerResponseDto.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerResponseDto.cs index a525e8a..fbe9642 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerResponseDto.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakePassengerResponseDto.cs @@ -1,13 +1,14 @@ using AutoBogus; -using BuildingBlocks.IdsGenerator; -using Passenger; namespace Integration.Test.Fakes; +using global::Passenger; +using MassTransit; + public class FakePassengerResponse : AutoFaker { public FakePassengerResponse() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid().ToString()); } } diff --git a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs index e4b9fa3..7337754 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Fakes/FakeUserCreated.cs @@ -1,14 +1,15 @@ using AutoBogus; using BuildingBlocks.Contracts.EventBus.Messages; -using BuildingBlocks.IdsGenerator; namespace Integration.Test.Fakes; +using MassTransit; + public class FakeUserCreated : AutoFaker { public FakeUserCreated() { - RuleFor(r => r.Id, _ => SnowflakeIdGenerator.NewId()); + RuleFor(r => r.Id, _ => NewId.NextGuid()); RuleFor(r => r.Name, _ => "Sam"); RuleFor(r => r.PassportNumber, _ => "123456789"); } diff --git a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs index c29c23e..5c6e7fc 100644 --- a/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs +++ b/src/Services/Passenger/tests/IntegrationTest/Passenger/Features/GetPassengerByIdTests.cs @@ -10,6 +10,7 @@ using Xunit; namespace Integration.Test.Passenger.Features; using global::Passenger.Passengers.Features.GettingPassengerById.Queries.V1; +using Thrift.Protocol; public class GetPassengerByIdTests : PassengerIntegrationTestBase { @@ -49,10 +50,10 @@ public class GetPassengerByIdTests : PassengerIntegrationTestBase var passengerGrpcClient = new PassengerGrpcService.PassengerGrpcServiceClient(Fixture.Channel); // Act - var response = await passengerGrpcClient.GetByIdAsync(new GetByIdRequest {Id = passengerEntity.Id}); + var response = await passengerGrpcClient.GetByIdAsync(new GetByIdRequest {Id = passengerEntity.Id.ToString()}); // Assert response?.Should().NotBeNull(); - response?.PassengerDto?.Id.Should().Be(passengerEntity.Id); + response?.PassengerDto?.Id.Should().Be(passengerEntity.Id.ToString()); } }