-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from amirhossein18121380/AddValueObject(Seats…
…/Flights/Airports) AddValueObjects(Seats/Flights/Airports)
- Loading branch information
Showing
56 changed files
with
2,058 additions
and
231 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/Services/Flight/src/Flight/Airports/Exceptions/InvalidAddressException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Flight.Airports.Exceptions; | ||
using BuildingBlocks.Exception; | ||
|
||
public class InvalidAddressException : BadRequestException | ||
{ | ||
public InvalidAddressException() : base("Address cannot be empty or whitespace.") | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Services/Flight/src/Flight/Airports/Exceptions/InvalidAirportIdExceptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Flight.Airports.Exceptions; | ||
using System; | ||
using BuildingBlocks.Exception; | ||
|
||
public class InvalidAirportIdExceptions : BadRequestException | ||
{ | ||
public InvalidAirportIdExceptions(Guid airportId) | ||
: base($"airportId: '{airportId}' is invalid.") | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Services/Flight/src/Flight/Airports/Exceptions/InvalidCodeException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Flight.Airports.Exceptions; | ||
using BuildingBlocks.Exception; | ||
|
||
|
||
public class InvalidCodeException : BadRequestException | ||
{ | ||
public InvalidCodeException() : base("Code cannot be empty or whitespace.") | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Services/Flight/src/Flight/Airports/Exceptions/InvalidNameException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Flight.Airports.Exceptions; | ||
using BuildingBlocks.Exception; | ||
|
||
|
||
public class InvalidNameException : BadRequestException | ||
{ | ||
public InvalidNameException() : base("Name cannot be empty or whitespace.") | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Services/Flight/src/Flight/Airports/ValueObjects/Address.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Flight.Airports.ValueObjects; | ||
using System.Linq; | ||
using Exceptions; | ||
|
||
public class Address | ||
{ | ||
public string Street { get; } | ||
public string City { get; } | ||
public string State { get; } | ||
public string ZipCode { get; } | ||
public string Country { get; } | ||
public string Value { get; } | ||
|
||
public Address(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
throw new InvalidAddressException(); | ||
} | ||
Value = value; | ||
} | ||
|
||
public Address(string street, string city, string state, string zipCode, string country) | ||
{ | ||
Street = street?.Trim(); | ||
City = city?.Trim(); | ||
State = state?.Trim(); | ||
ZipCode = zipCode?.Trim(); | ||
Country = country?.Trim(); | ||
|
||
Value = string.Join(", ", new[] { Street, City, State, ZipCode, Country }.Where(s => !string.IsNullOrWhiteSpace(s))); | ||
} | ||
|
||
public static Address Of(string value) | ||
{ | ||
return new Address(value); | ||
} | ||
|
||
public static implicit operator string(Address address) | ||
{ | ||
return address.Value; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Services/Flight/src/Flight/Airports/ValueObjects/AirportId.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Flight.Airports.ValueObjects; | ||
using System; | ||
using Flight.Airports.Exceptions; | ||
|
||
public record AirportId | ||
{ | ||
public Guid Value { get; } | ||
|
||
private AirportId(Guid value) | ||
{ | ||
if (value == Guid.Empty) | ||
{ | ||
throw new InvalidAirportIdExceptions(value); | ||
} | ||
|
||
Value = value; | ||
} | ||
|
||
public static AirportId Of(Guid value) | ||
{ | ||
return new AirportId(value); | ||
} | ||
|
||
public static implicit operator Guid(AirportId airportId) | ||
{ | ||
return airportId.Value; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Services/Flight/src/Flight/Airports/ValueObjects/Code.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Flight.Airports.ValueObjects; | ||
|
||
using Exceptions; | ||
|
||
public record Code | ||
{ | ||
public string Value { get; } | ||
public Code(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
throw new InvalidCodeException(); | ||
} | ||
Value = value; | ||
} | ||
public static Code Of(string value) | ||
{ | ||
return new Code(value); | ||
} | ||
|
||
public static implicit operator string(Code code) | ||
{ | ||
return code.Value; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Services/Flight/src/Flight/Airports/ValueObjects/Name.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Flight.Airports.ValueObjects; | ||
|
||
using Flight.Airports.Exceptions; | ||
|
||
public record Name | ||
{ | ||
public string Value { get; } | ||
public Name(string value) | ||
{ | ||
if (string.IsNullOrWhiteSpace(value)) | ||
{ | ||
throw new InvalidNameException(); | ||
} | ||
Value = value; | ||
} | ||
public static Name Of(string value) | ||
{ | ||
return new Name(value); | ||
} | ||
|
||
public static implicit operator string(Name name) | ||
{ | ||
return name.Value; | ||
} | ||
} |
44 changes: 40 additions & 4 deletions
44
src/Services/Flight/src/Flight/Data/Configurations/AirportConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,57 @@ | ||
using System; | ||
using Flight.Airports.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Flight.Data.Configurations; | ||
|
||
public class AirportConfiguration: IEntityTypeConfiguration<Airport> | ||
using Airports.ValueObjects; | ||
|
||
public class AirportConfiguration : IEntityTypeConfiguration<Airport> | ||
{ | ||
public void Configure(EntityTypeBuilder<Airport> builder) | ||
{ | ||
|
||
builder.ToTable(nameof(Airport)); | ||
|
||
builder.HasKey(r => r.Id); | ||
builder.Property(r => r.Id).ValueGeneratedNever(); | ||
|
||
|
||
builder.Property(r => r.Id).ValueGeneratedNever() | ||
.HasConversion<Guid>(airportId => airportId.Value, dbId => AirportId.Of(dbId)); | ||
// // ref: https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=fluent-api | ||
builder.Property(r => r.Version).IsConcurrencyToken(); | ||
|
||
|
||
builder.OwnsOne( | ||
x => x.Name, | ||
a => | ||
{ | ||
a.Property(p => p.Value) | ||
.HasColumnName(nameof(Airport.Name)) | ||
.HasMaxLength(50) | ||
.IsRequired(); | ||
} | ||
); | ||
|
||
builder.OwnsOne( | ||
x => x.Address, | ||
a => | ||
{ | ||
a.Property(p => p.Value) | ||
.HasColumnName(nameof(Airport.Address)) | ||
.HasMaxLength(50) | ||
.IsRequired(); | ||
} | ||
); | ||
|
||
builder.OwnsOne( | ||
x => x.Code, | ||
a => | ||
{ | ||
a.Property(p => p.Value) | ||
.HasColumnName(nameof(Airport.Code)) | ||
.HasMaxLength(50) | ||
.IsRequired(); | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.