mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-05-02 19:02:55 +08:00
Apply Chnages in Comment
This commit is contained in:
parent
f639619940
commit
78f4a764f7
@ -0,0 +1,10 @@
|
|||||||
|
namespace Flight.Aircrafts.Exceptions;
|
||||||
|
using BuildingBlocks.Exception;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidManufacturingYearException : BadRequestException
|
||||||
|
{
|
||||||
|
public InvalidManufacturingYearException() : base("ManufacturingYear cannot be empty or whitespace.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
namespace Flight.Aircrafts.Exceptions;
|
||||||
|
using BuildingBlocks.Exception;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidModelException : BadRequestException
|
||||||
|
{
|
||||||
|
public InvalidModelException() : base("Model cannot be empty or whitespace.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
namespace Flight.Aircrafts.Exceptions;
|
||||||
|
using BuildingBlocks.Exception;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidNameException : BadRequestException
|
||||||
|
{
|
||||||
|
public InvalidNameException() : base("Name cannot be empty or whitespace.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,6 +18,7 @@ using MediatR;
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Models;
|
using Models;
|
||||||
using Models.ValueObjects;
|
using Models.ValueObjects;
|
||||||
|
|
||||||
@ -89,11 +90,8 @@ internal class CreateAircraftHandler : IRequestHandler<CreateAircraft, CreateAir
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(request, nameof(request));
|
Guard.Against.Null(request, nameof(request));
|
||||||
|
|
||||||
//var aircraft =
|
var aircraft = await _flightDbContext.Aircraft.AsNoTracking().SingleOrDefaultAsync(
|
||||||
// await _flightDbContext.Aircraft.SingleOrDefaultAsync(x => x.Model == Model.Of(request.Model), cancellationToken);
|
a => a.Model.Value.Equals(Model.Of(request.Model)), cancellationToken);
|
||||||
|
|
||||||
var aircraft = _flightDbContext.Aircraft.AsEnumerable()
|
|
||||||
.FirstOrDefault(a => a.Model.Equals(Model.Of(request.Model)));
|
|
||||||
|
|
||||||
|
|
||||||
if (aircraft is not null)
|
if (aircraft is not null)
|
||||||
|
|||||||
@ -1,19 +1,26 @@
|
|||||||
namespace Flight.Aircrafts.Models.ValueObjects;
|
namespace Flight.Aircrafts.Models.ValueObjects;
|
||||||
|
|
||||||
using System;
|
using Flight.Aircrafts.Exceptions;
|
||||||
|
|
||||||
public record ManufacturingYear : GenericValueObject<int>
|
public record ManufacturingYear
|
||||||
{
|
{
|
||||||
public ManufacturingYear(int value) : base(value)
|
public int Value { get; }
|
||||||
|
public ManufacturingYear(int value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value.ToString()))
|
if (string.IsNullOrWhiteSpace(value.ToString()))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("ManufacturingYear cannot be empty or whitespace.");
|
throw new InvalidManufacturingYearException();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
public static ManufacturingYear Of(int value)
|
public static ManufacturingYear Of(int value)
|
||||||
{
|
{
|
||||||
return new ManufacturingYear(value);
|
return new ManufacturingYear(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator int(ManufacturingYear manufacturingYear)
|
||||||
|
{
|
||||||
|
return manufacturingYear.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,24 @@
|
|||||||
namespace Flight.Aircrafts.Models.ValueObjects;
|
namespace Flight.Aircrafts.Models.ValueObjects;
|
||||||
using System;
|
using Flight.Aircrafts.Exceptions;
|
||||||
public record Model : GenericValueObject<string>
|
|
||||||
|
public record Model
|
||||||
{
|
{
|
||||||
public Model(string value) : base(value)
|
public string Value { get; }
|
||||||
|
public Model(string value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Model cannot be empty or whitespace.");
|
throw new InvalidModelException();
|
||||||
}
|
}
|
||||||
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Model Of(string value)
|
public static Model Of(string value)
|
||||||
{
|
{
|
||||||
return new Model(value);
|
return new Model(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator string(Model model)
|
||||||
|
{
|
||||||
|
return model.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,24 @@
|
|||||||
namespace Flight.Aircrafts.Models.ValueObjects;
|
namespace Flight.Aircrafts.Models.ValueObjects;
|
||||||
using System;
|
using Exceptions;
|
||||||
|
|
||||||
public record Name : GenericValueObject<string>
|
public record Name
|
||||||
{
|
{
|
||||||
public Name(string value) : base(value)
|
public string Value { get; }
|
||||||
|
public Name(string value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Name cannot be empty or whitespace.");
|
throw new InvalidNameException();
|
||||||
}
|
}
|
||||||
|
Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Name Of(string value)
|
public static Name Of(string value)
|
||||||
{
|
{
|
||||||
return new Name(value);
|
return new Name(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator string(Name name)
|
||||||
|
{
|
||||||
|
return name.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,363 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Flight.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Flight.Data.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(FlightDbContext))]
|
|
||||||
[Migration("20230526093041_aircraftValueObject")]
|
|
||||||
partial class aircraftValueObject
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.2")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<long?>("CreatedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("created_by");
|
|
||||||
|
|
||||||
b.Property<bool>("IsDeleted")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_deleted");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("LastModified")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("last_modified");
|
|
||||||
|
|
||||||
b.Property<long?>("LastModifiedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("last_modified_by");
|
|
||||||
|
|
||||||
b.Property<long>("Version")
|
|
||||||
.IsConcurrencyToken()
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("version");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_aircraft");
|
|
||||||
|
|
||||||
b.ToTable("aircraft", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Airports.Models.Airport", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<string>("Address")
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasColumnName("address");
|
|
||||||
|
|
||||||
b.Property<string>("Code")
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasColumnName("code");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<long?>("CreatedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("created_by");
|
|
||||||
|
|
||||||
b.Property<bool>("IsDeleted")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_deleted");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("LastModified")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("last_modified");
|
|
||||||
|
|
||||||
b.Property<long?>("LastModifiedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("last_modified_by");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasColumnName("name");
|
|
||||||
|
|
||||||
b.Property<long>("Version")
|
|
||||||
.IsConcurrencyToken()
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("version");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_airport");
|
|
||||||
|
|
||||||
b.ToTable("airport", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<Guid?>("AircraftId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("aircraft_id");
|
|
||||||
|
|
||||||
b.Property<Guid>("ArriveAirportId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("arrive_airport_id");
|
|
||||||
|
|
||||||
b.Property<DateTime>("ArriveDate")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("arrive_date");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<long?>("CreatedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("created_by");
|
|
||||||
|
|
||||||
b.Property<Guid>("DepartureAirportId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("departure_airport_id");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DepartureDate")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("departure_date");
|
|
||||||
|
|
||||||
b.Property<decimal>("DurationMinutes")
|
|
||||||
.HasColumnType("numeric")
|
|
||||||
.HasColumnName("duration_minutes");
|
|
||||||
|
|
||||||
b.Property<DateTime>("FlightDate")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("flight_date");
|
|
||||||
|
|
||||||
b.Property<string>("FlightNumber")
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasColumnName("flight_number");
|
|
||||||
|
|
||||||
b.Property<bool>("IsDeleted")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_deleted");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("LastModified")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("last_modified");
|
|
||||||
|
|
||||||
b.Property<long?>("LastModifiedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("last_modified_by");
|
|
||||||
|
|
||||||
b.Property<decimal>("Price")
|
|
||||||
.HasColumnType("numeric")
|
|
||||||
.HasColumnName("price");
|
|
||||||
|
|
||||||
b.Property<string>("Status")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasDefaultValue("Unknown")
|
|
||||||
.HasColumnName("status");
|
|
||||||
|
|
||||||
b.Property<long>("Version")
|
|
||||||
.IsConcurrencyToken()
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("version");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_flight");
|
|
||||||
|
|
||||||
b.HasIndex("AircraftId")
|
|
||||||
.HasDatabaseName("ix_flight_aircraft_id");
|
|
||||||
|
|
||||||
b.HasIndex("ArriveAirportId")
|
|
||||||
.HasDatabaseName("ix_flight_arrive_airport_id");
|
|
||||||
|
|
||||||
b.ToTable("flight", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<string>("Class")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasDefaultValue("Unknown")
|
|
||||||
.HasColumnName("class");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<long?>("CreatedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("created_by");
|
|
||||||
|
|
||||||
b.Property<Guid>("FlightId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("flight_id");
|
|
||||||
|
|
||||||
b.Property<bool>("IsDeleted")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_deleted");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("LastModified")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("last_modified");
|
|
||||||
|
|
||||||
b.Property<long?>("LastModifiedBy")
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("last_modified_by");
|
|
||||||
|
|
||||||
b.Property<string>("SeatNumber")
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasColumnName("seat_number");
|
|
||||||
|
|
||||||
b.Property<string>("Type")
|
|
||||||
.IsRequired()
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasDefaultValue("Unknown")
|
|
||||||
.HasColumnName("type");
|
|
||||||
|
|
||||||
b.Property<long>("Version")
|
|
||||||
.IsConcurrencyToken()
|
|
||||||
.HasColumnType("bigint")
|
|
||||||
.HasColumnName("version");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_seat");
|
|
||||||
|
|
||||||
b.HasIndex("FlightId")
|
|
||||||
.HasDatabaseName("ix_seat_flight_id");
|
|
||||||
|
|
||||||
b.ToTable("seat", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
|
|
||||||
{
|
|
||||||
b.OwnsOne("Flight.Aircrafts.Models.ValueObjects.ManufacturingYearValue", "ManufacturingYear", b1 =>
|
|
||||||
{
|
|
||||||
b1.Property<Guid>("AircraftId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b1.Property<int>("Value")
|
|
||||||
.HasMaxLength(5)
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("manufacturing_year");
|
|
||||||
|
|
||||||
b1.HasKey("AircraftId")
|
|
||||||
.HasName("pk_aircraft");
|
|
||||||
|
|
||||||
b1.ToTable("aircraft");
|
|
||||||
|
|
||||||
b1.WithOwner()
|
|
||||||
.HasForeignKey("AircraftId")
|
|
||||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.OwnsOne("Flight.Aircrafts.Models.ValueObjects.ModelValue", "Model", b1 =>
|
|
||||||
{
|
|
||||||
b1.Property<Guid>("AircraftId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b1.Property<string>("Value")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(50)
|
|
||||||
.HasColumnType("character varying(50)")
|
|
||||||
.HasColumnName("model");
|
|
||||||
|
|
||||||
b1.HasKey("AircraftId")
|
|
||||||
.HasName("pk_aircraft");
|
|
||||||
|
|
||||||
b1.ToTable("aircraft");
|
|
||||||
|
|
||||||
b1.WithOwner()
|
|
||||||
.HasForeignKey("AircraftId")
|
|
||||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.OwnsOne("Flight.Aircrafts.Models.ValueObjects.NameValue", "Name", b1 =>
|
|
||||||
{
|
|
||||||
b1.Property<Guid>("AircraftId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b1.Property<string>("Value")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(50)
|
|
||||||
.HasColumnType("character varying(50)")
|
|
||||||
.HasColumnName("name");
|
|
||||||
|
|
||||||
b1.HasKey("AircraftId")
|
|
||||||
.HasName("pk_aircraft");
|
|
||||||
|
|
||||||
b1.ToTable("aircraft");
|
|
||||||
|
|
||||||
b1.WithOwner()
|
|
||||||
.HasForeignKey("AircraftId")
|
|
||||||
.HasConstraintName("fk_aircraft_aircraft_id");
|
|
||||||
});
|
|
||||||
|
|
||||||
b.Navigation("ManufacturingYear");
|
|
||||||
|
|
||||||
b.Navigation("Model");
|
|
||||||
|
|
||||||
b.Navigation("Name");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Flight.Aircrafts.Models.Aircraft", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("AircraftId")
|
|
||||||
.HasConstraintName("fk_flight_aircraft_aircraft_id");
|
|
||||||
|
|
||||||
b.HasOne("Flight.Airports.Models.Airport", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("ArriveAirportId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired()
|
|
||||||
.HasConstraintName("fk_flight_airport_arrive_airport_id");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Flight.Flights.Models.Flight", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("FlightId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired()
|
|
||||||
.HasConstraintName("fk_seat_flight_flight_id");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Flight.Data.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class aircraftValueObject : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,6 +5,7 @@ using BuildingBlocks.Core.Event;
|
|||||||
namespace Flight;
|
namespace Flight;
|
||||||
|
|
||||||
using Aircrafts.Features.CreatingAircraft.V1;
|
using Aircrafts.Features.CreatingAircraft.V1;
|
||||||
|
using Aircrafts.Models.ValueObjects;
|
||||||
using Airports.Features.CreatingAirport.V1;
|
using Airports.Features.CreatingAirport.V1;
|
||||||
using Flights.Features.CreatingFlight.V1;
|
using Flights.Features.CreatingFlight.V1;
|
||||||
using Flights.Features.DeletingFlight.V1;
|
using Flights.Features.DeletingFlight.V1;
|
||||||
@ -34,7 +35,7 @@ public sealed class EventMapper : IEventMapper
|
|||||||
{
|
{
|
||||||
return @event switch
|
return @event switch
|
||||||
{
|
{
|
||||||
FlightCreatedDomainEvent e => new CreateFlightMongo(e.Id, e.FlightNumber, e.AircraftId, e.DepartureDate, e.DepartureAirportId,
|
FlightCreatedDomainEvent e => new CreateFlightMongo(e.Id, e.FlightNumber, AircraftId.Of(e.AircraftId), e.DepartureDate, e.DepartureAirportId,
|
||||||
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
||||||
FlightUpdatedDomainEvent e => new UpdateFlightMongo(e.Id, e.FlightNumber, e.AircraftId, e.DepartureDate, e.DepartureAirportId,
|
FlightUpdatedDomainEvent e => new UpdateFlightMongo(e.Id, e.FlightNumber, e.AircraftId, e.DepartureDate, e.DepartureAirportId,
|
||||||
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
e.ArriveDate, e.ArriveAirportId, e.DurationMinutes, e.FlightDate, e.Status, e.Price, e.IsDeleted),
|
||||||
|
|||||||
@ -2,6 +2,8 @@ using System;
|
|||||||
|
|
||||||
namespace Flight.Flights.Dtos;
|
namespace Flight.Flights.Dtos;
|
||||||
|
|
||||||
public record FlightDto(Guid Id, string FlightNumber, Guid AircraftId, Guid DepartureAirportId,
|
using Aircrafts.Models.ValueObjects;
|
||||||
|
|
||||||
|
public record FlightDto(Guid Id, string FlightNumber, AircraftId AircraftId, Guid DepartureAirportId,
|
||||||
DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate,
|
DateTime DepartureDate, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate,
|
||||||
Enums.FlightStatus Status, decimal Price);
|
Enums.FlightStatus Status, decimal Price);
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
namespace Flight.Flights.Features.CreatingFlight.V1;
|
namespace Flight.Flights.Features.CreatingFlight.V1;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Aircrafts.Models.ValueObjects;
|
||||||
using Ardalis.GuardClauses;
|
using Ardalis.GuardClauses;
|
||||||
using BuildingBlocks.Core.CQRS;
|
using BuildingBlocks.Core.CQRS;
|
||||||
using BuildingBlocks.Core.Event;
|
using BuildingBlocks.Core.Event;
|
||||||
@ -14,7 +15,7 @@ using Models;
|
|||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using MongoDB.Driver.Linq;
|
using MongoDB.Driver.Linq;
|
||||||
|
|
||||||
public record CreateFlightMongo(Guid Id, string FlightNumber, Guid AircraftId, DateTime DepartureDate,
|
public record CreateFlightMongo(Guid Id, string FlightNumber, AircraftId AircraftId, DateTime DepartureDate,
|
||||||
Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate,
|
Guid DepartureAirportId, DateTime ArriveDate, Guid ArriveAirportId, decimal DurationMinutes, DateTime FlightDate,
|
||||||
Enums.FlightStatus Status, decimal Price, bool IsDeleted = false) : InternalCommand;
|
Enums.FlightStatus Status, decimal Price, bool IsDeleted = false) : InternalCommand;
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@ namespace Flight.Flights.Features;
|
|||||||
|
|
||||||
using CreatingFlight.V1;
|
using CreatingFlight.V1;
|
||||||
using DeletingFlight.V1;
|
using DeletingFlight.V1;
|
||||||
using GettingAvailableFlights.V1;
|
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
using Models;
|
using Models;
|
||||||
using UpdatingFlight.V1;
|
using UpdatingFlight.V1;
|
||||||
@ -15,7 +14,8 @@ public class FlightMappings : IRegister
|
|||||||
public void Register(TypeAdapterConfig config)
|
public void Register(TypeAdapterConfig config)
|
||||||
{
|
{
|
||||||
config.NewConfig<Models.Flight, FlightDto>()
|
config.NewConfig<Models.Flight, FlightDto>()
|
||||||
.ConstructUsing(x => new FlightDto(x.Id, x.FlightNumber, x.AircraftId, x.DepartureAirportId, x.DepartureDate,
|
.ConstructUsing(x => new FlightDto(x.Id, x.FlightNumber, x.AircraftId, x.DepartureAirportId,
|
||||||
|
x.DepartureDate,
|
||||||
x.ArriveDate, x.ArriveAirportId, x.DurationMinutes, x.FlightDate, x.Status, x.Price));
|
x.ArriveDate, x.ArriveAirportId, x.DurationMinutes, x.FlightDate, x.Status, x.Price));
|
||||||
|
|
||||||
config.NewConfig<CreateFlightMongo, FlightReadModel>()
|
config.NewConfig<CreateFlightMongo, FlightReadModel>()
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
namespace Flight.Flights.Models;
|
namespace Flight.Flights.Models;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Aircrafts.Models.ValueObjects;
|
||||||
|
|
||||||
public class FlightReadModel
|
public class FlightReadModel
|
||||||
{
|
{
|
||||||
public required Guid Id { get; init; }
|
public required Guid Id { get; init; }
|
||||||
public required Guid FlightId { get; init; }
|
public required Guid FlightId { get; init; }
|
||||||
public required string FlightNumber { get; init; }
|
public required string FlightNumber { get; init; }
|
||||||
public required Guid AircraftId { get; init; }
|
public required AircraftId AircraftId { get; init; }
|
||||||
public required DateTime DepartureDate { get; init; }
|
public required DateTime DepartureDate { get; init; }
|
||||||
public required Guid DepartureAirportId { get; init; }
|
public required Guid DepartureAirportId { get; init; }
|
||||||
public required DateTime ArriveDate { get; init; }
|
public required DateTime ArriveDate { get; init; }
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
namespace Flight;
|
|
||||||
public record GenericValueObject<T>(T Value)
|
|
||||||
{
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator T(GenericValueObject<T> valueObject)
|
|
||||||
{
|
|
||||||
return valueObject.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||||
using BuildingBlocks.TestBase;
|
using BuildingBlocks.TestBase;
|
||||||
using Flight.Api;
|
using Flight.Api;
|
||||||
@ -26,7 +26,7 @@ public class CreateAircraftTests : FlightIntegrationTestBase
|
|||||||
var response = await Fixture.SendAsync(command);
|
var response = await Fixture.SendAsync(command);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response?.Id.Should().Be(command.Id);
|
response?.Id.Value.Should().Be(command.Id);
|
||||||
|
|
||||||
(await Fixture.WaitForPublishing<AircraftCreated>()).Should().Be(true);
|
(await Fixture.WaitForPublishing<AircraftCreated>()).Should().Be(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
namespace Passenger.Passengers.Exceptions;
|
||||||
|
using BuildingBlocks.Exception;
|
||||||
|
|
||||||
|
public class InvalidAgeException : BadRequestException
|
||||||
|
{
|
||||||
|
public InvalidAgeException() : base("Age Cannot be null or negative")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
namespace Passenger.Passengers.Exceptions;
|
||||||
|
using BuildingBlocks.Exception;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidNameException : BadRequestException
|
||||||
|
{
|
||||||
|
public InvalidNameException() : base("Name cannot be empty or whitespace.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
namespace Passenger.Passengers.Exceptions;
|
||||||
|
using BuildingBlocks.Exception;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidPassportNumberException : BadRequestException
|
||||||
|
{
|
||||||
|
public InvalidPassportNumberException() : base("Passport number cannot be empty or whitespace.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -96,11 +96,9 @@ internal class CompleteRegisterPassengerCommandHandler : ICommandHandler<Complet
|
|||||||
{
|
{
|
||||||
Guard.Against.Null(request, nameof(request));
|
Guard.Against.Null(request, nameof(request));
|
||||||
|
|
||||||
//var passenger = await _passengerDbContext.Passengers.AsNoTracking().SingleOrDefaultAsync(
|
var passenger = await _passengerDbContext.Passengers.AsNoTracking().SingleOrDefaultAsync(
|
||||||
// x => x.PassportNumber == PassportNumber.Of(request.PassportNumber), cancellationToken);
|
x => x.PassportNumber.Value.Equals(PassportNumber.Of(request.PassportNumber)), cancellationToken);
|
||||||
|
|
||||||
var passenger = _passengerDbContext.Passengers.AsEnumerable()
|
|
||||||
.FirstOrDefault(a => a.PassportNumber.Equals(PassportNumber.Of(request.PassportNumber)));
|
|
||||||
|
|
||||||
if (passenger is null)
|
if (passenger is null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,18 +1,25 @@
|
|||||||
namespace Passenger.Passengers.Models.ValueObjects;
|
namespace Passenger.Passengers.Models.ValueObjects;
|
||||||
using System;
|
using global::Passenger.Passengers.Exceptions;
|
||||||
|
|
||||||
public record Age : GenericValueObject<int>
|
public record Age
|
||||||
{
|
{
|
||||||
public Age(int value) : base(value)
|
public int Value { get; }
|
||||||
|
public Age(int value)
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value <= 0 || value == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Age cannot be negative.");
|
throw new InvalidAgeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
public static Age Of(int value)
|
public static Age Of(int value)
|
||||||
{
|
{
|
||||||
return new Age(value);
|
return new Age(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator int(Age age)
|
||||||
|
{
|
||||||
|
return age.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
namespace Passenger.Passengers.Models.ValueObjects;
|
|
||||||
public record GenericValueObject<T>(T Value)
|
|
||||||
{
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return Value.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static implicit operator T(GenericValueObject<T> valueObject)
|
|
||||||
{
|
|
||||||
return valueObject.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +1,14 @@
|
|||||||
namespace Passenger.Passengers.Models.ValueObjects;
|
namespace Passenger.Passengers.Models.ValueObjects;
|
||||||
using System;
|
using Exceptions;
|
||||||
|
|
||||||
public record Name : GenericValueObject<string>
|
public record Name
|
||||||
{
|
{
|
||||||
public Name(string value) : base(value)
|
public string Value { get; }
|
||||||
|
public Name(string value)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Name cannot be empty or whitespace.");
|
throw new InvalidNameException();
|
||||||
}
|
}
|
||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
@ -15,4 +16,9 @@ public record Name : GenericValueObject<string>
|
|||||||
{
|
{
|
||||||
return new Name(value);
|
return new Name(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static implicit operator string(Name name)
|
||||||
|
{
|
||||||
|
return name.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,46 +1,6 @@
|
|||||||
namespace Passenger.Passengers.Models.ValueObjects;
|
namespace Passenger.Passengers.Models.ValueObjects;
|
||||||
using System;
|
using Exceptions;
|
||||||
|
|
||||||
|
|
||||||
//public record PassportNumber : GenericValueObject<string>
|
|
||||||
//{
|
|
||||||
|
|
||||||
// public PassportNumber(string value) : base(value)
|
|
||||||
// {
|
|
||||||
// if (string.IsNullOrWhiteSpace(value))
|
|
||||||
// {
|
|
||||||
// throw new ArgumentException("Passport number cannot be empty or whitespace.");
|
|
||||||
// }
|
|
||||||
// Value = value;
|
|
||||||
// }
|
|
||||||
// public static PassportNumber Of(string value)
|
|
||||||
// {
|
|
||||||
// return new PassportNumber(value);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//public record PassportNumber
|
|
||||||
//{
|
|
||||||
// public string Value { get; }
|
|
||||||
|
|
||||||
// public PassportNumber(string value)
|
|
||||||
// {
|
|
||||||
// if (string.IsNullOrWhiteSpace(value))
|
|
||||||
// {
|
|
||||||
// throw new ArgumentException("Passport number cannot be empty or whitespace.");
|
|
||||||
// }
|
|
||||||
// Value = value;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static PassportNumber Of(string value)
|
|
||||||
// {
|
|
||||||
// return new PassportNumber(value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static implicit operator string(PassportNumber aircraftId)
|
|
||||||
// {
|
|
||||||
// return aircraftId.Value;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
public record PassportNumber
|
public record PassportNumber
|
||||||
{
|
{
|
||||||
public string Value { get; }
|
public string Value { get; }
|
||||||
@ -54,7 +14,7 @@ public record PassportNumber
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Passport number cannot be empty or whitespace.");
|
throw new InvalidPassportNumberException();
|
||||||
}
|
}
|
||||||
Value = value;
|
Value = value;
|
||||||
}
|
}
|
||||||
@ -63,5 +23,10 @@ public record PassportNumber
|
|||||||
{
|
{
|
||||||
return new PassportNumber(value);
|
return new PassportNumber(value);
|
||||||
}
|
}
|
||||||
public static implicit operator string(PassportNumber passportNumber) => passportNumber.Value;
|
|
||||||
|
public static implicit operator string(PassportNumber passportNumber)
|
||||||
|
{
|
||||||
|
return passportNumber.Value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,8 +23,8 @@ public class CompleteRegisterPassengerTests : PassengerIntegrationTestBase
|
|||||||
var userCreated = new FakeUserCreated().Generate();
|
var userCreated = new FakeUserCreated().Generate();
|
||||||
|
|
||||||
await Fixture.Publish(userCreated);
|
await Fixture.Publish(userCreated);
|
||||||
(await Fixture.WaitForPublishing<UserCreated>()).Should().Be(true);
|
await Fixture.WaitForPublishing<UserCreated>();
|
||||||
(await Fixture.WaitForConsuming<UserCreated>()).Should().Be(true);
|
await Fixture.WaitForConsuming<UserCreated>();
|
||||||
|
|
||||||
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
|
var command = new FakeCompleteRegisterPassengerCommand(userCreated.PassportNumber).Generate();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user