Removed location entities, fixed configurations and controllers' comments

This commit is contained in:
2024-08-21 18:39:22 +03:00
parent f857ba90f8
commit 3e21a0a164
47 changed files with 111 additions and 506 deletions

View File

@@ -1,6 +1,5 @@
using Domains;
using Domains.ApplicantDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Applicants.Configuration;
@@ -9,15 +8,20 @@ public static class AddressConfiguration<T> where T : class, IEntity
{
public static void Configure(OwnedNavigationBuilder<T, Address> entity)
{
entity.HasOne(a => a.Country).WithMany().OnDelete(DeleteBehavior.Restrict);
entity.HasOne(a => a.City).WithMany().OnDelete(DeleteBehavior.Restrict);
entity.Property(p => p.Street)
entity.Property(a => a.Country)
.IsUnicode(false)
.HasMaxLength(100);
.HasMaxLength(ConfigurationConstraints.CountryNameLength);
entity.Property(p => p.Building)
entity.Property(a => a.City)
.IsUnicode(false)
.HasMaxLength(10);
.HasMaxLength(ConfigurationConstraints.CityNameLength);
entity.Property(a => a.Street)
.IsUnicode(false)
.HasMaxLength(ConfigurationConstraints.StreetNameLength);
entity.Property(a => a.Building)
.IsUnicode(false)
.HasMaxLength(ConfigurationConstraints.BuildingNumberLength);
}
}

View File

@@ -9,21 +9,27 @@ public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant>
{
public void Configure(EntityTypeBuilder<Applicant> entity)
{
entity.OwnsOne(p => p.Name, NameConfiguration<Applicant>.Configure);
entity.OwnsOne(p => p.FatherName, NameConfiguration<Applicant>.Configure);
entity.OwnsOne(p => p.MotherName, NameConfiguration<Applicant>.Configure);
entity.OwnsOne(p => p.Passport, PassportConfiguration<Applicant>.Configure);
entity.OwnsOne(a => a.Name, NameConfiguration<Applicant>.Configure);
entity.OwnsOne(a => a.FatherName, NameConfiguration<Applicant>.Configure);
entity.OwnsOne(a => a.MotherName, NameConfiguration<Applicant>.Configure);
entity.OwnsOne(a => a.Passport, PassportConfiguration<Applicant>.Configure);
entity.HasOne(a => a.CityOfBirth).WithMany().OnDelete(DeleteBehavior.Restrict);
entity.HasOne(a => a.CountryOfBirth).WithMany().OnDelete(DeleteBehavior.Restrict);
entity.HasOne<User>().WithOne().HasForeignKey<Applicant>(a => a.UserId);
entity.Property(p => p.Citizenship)
entity.Property(a => a.Citizenship)
.IsUnicode(false)
.HasMaxLength(30);
.HasMaxLength(ConfigurationConstraints.CitizenshipLength);
entity.Property(p => p.CitizenshipByBirth)
entity.Property(a => a.CitizenshipByBirth)
.IsUnicode(false)
.HasMaxLength(30);
.HasMaxLength(ConfigurationConstraints.CitizenshipLength);
entity.Property(a => a.CountryOfBirth)
.IsUnicode(false)
.HasMaxLength(ConfigurationConstraints.CountryNameLength);
entity.Property(a => a.CityOfBirth)
.IsUnicode(false)
.HasMaxLength(ConfigurationConstraints.CityNameLength);
}
}

View File

@@ -10,14 +10,14 @@ public static class NameConfiguration<T> where T : class, IEntity
{
entity.Property(p => p.FirstName)
.IsUnicode(false)
.HasMaxLength(50);
.HasMaxLength(ConfigurationConstraints.NameLength);
entity.Property(p => p.Surname)
.IsUnicode(false)
.HasMaxLength(50);
.HasMaxLength(ConfigurationConstraints.NameLength);
entity.Property(p => p.Patronymic)
.IsUnicode(false)
.HasMaxLength(50);
.HasMaxLength(ConfigurationConstraints.NameLength);
}
}

View File

@@ -10,10 +10,10 @@ public static class PassportConfiguration<T> where T : class, IEntity
{
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(20);
.HasMaxLength(ConfigurationConstraints.PassportNumberLength);
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
.HasMaxLength(ConfigurationConstraints.IssuerNameLength);
}
}

View File

@@ -12,10 +12,10 @@ public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork>
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(200);
.HasMaxLength(ConfigurationConstraints.PlaceOfWorkNameLength);
entity.Property(p => p.PhoneNum)
.IsUnicode(false)
.HasMaxLength(20);
.HasMaxLength(ConfigurationConstraints.PhoneNumberLength);
}
}

View File

@@ -15,8 +15,6 @@ public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter w
protected override IQueryable<Applicant> LoadDomain()
{
return base.LoadDomain()
.Include(a => a.CountryOfBirth)
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}

View File

@@ -0,0 +1,20 @@
namespace Infrastructure.Database
{
public static class ConfigurationConstraints
{
public const int CityNameLength = 70;
public const int CountryNameLength = 70;
public const int CitizenshipLength = 30;
public const int ReentryPermitNumberLength = 25;
public const int IssuerNameLength = 200;
public const int VisaNameLength = 70;
public const int StreetNameLength = 100;
public const int PlaceOfWorkNameLength = 200;
public const int NameLength = 50;
public const int BuildingNumberLength = 10;
public const int PassportNumberLength = 20;
public const int PhoneNumberLength = 15;
public const int EmailLength = 254;
public const int PasswordLength = 50;
}
}

View File

@@ -1,15 +0,0 @@
using Domains.LocationDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Locations.Configuration;
public class CityConfiguration : IEntityTypeConfiguration<City>
{
public void Configure(EntityTypeBuilder<City> entity)
{
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
}
}

View File

@@ -1,17 +0,0 @@
using Domains.LocationDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.Locations.Configuration;
public class CountryConfiguration : IEntityTypeConfiguration<Country>
{
public void Configure(EntityTypeBuilder<Country> entity)
{
entity.Property(c => c.Name)
.IsUnicode(false)
.HasMaxLength(70);
entity.HasIndex(c => c.Name).IsUnique();
}
}

View File

@@ -1,18 +0,0 @@
using ApplicationLayer.Services.Locations.NeededServices;
using Domains.LocationDomain;
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Locations.Repositories.Cities;
public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer)
: GenericRepository<City>(reader, writer), ICitiesRepository
{
protected override IQueryable<City> LoadDomain()
{
return base.LoadDomain().Include(c => c.Country);
}
Task<City?> ICitiesRepository.GetByNameAsync(Guid countryId, string cityName, CancellationToken cancellationToken)
=> LoadDomain().SingleOrDefaultAsync(c => c.Country.Id == countryId && c.Name == cityName, cancellationToken);
}

View File

@@ -1,27 +0,0 @@
using ApplicationLayer.Services.Locations.NeededServices;
using Domains.LocationDomain;
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Locations.Repositories.Countries;
public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer)
: GenericRepository<Country>(reader, writer), ICountriesRepository
{
protected override IQueryable<Country> LoadDomain()
{
return base.LoadDomain().Include(c => c.Cities);
}
async Task<Country?> ICountriesRepository.FindByNameAsync(string countryName, CancellationToken cancellationToken)
{
var result = await LoadDomain().SingleOrDefaultAsync(c => c.Name == countryName, cancellationToken);
return result;
}
async Task<Country?> ICountriesRepository.FindByIdAsync(Guid id, CancellationToken cancellationToken)
{
var result = await LoadDomain().SingleOrDefaultAsync(c => c.Id == id, cancellationToken);
return result;
}
}

View File

@@ -10,13 +10,13 @@ namespace Infrastructure.Database.Users.Configuration
{
entity.Property(u => u.Email)
.IsUnicode(false)
.HasMaxLength(254);
.HasMaxLength(ConfigurationConstraints.EmailLength);
entity.HasIndex(u => u.Email).IsUnique();
entity.Property(u => u.Password)
.IsUnicode(false)
.HasMaxLength(50);
.HasMaxLength(ConfigurationConstraints.PasswordLength);
}
}
}

View File

@@ -10,6 +10,6 @@ public static class PastVisaConfiguration<T> where T : class, IEntity
{
entity.Property(p => p.Name)
.IsUnicode(false)
.HasMaxLength(70);
.HasMaxLength(ConfigurationConstraints.VisaNameLength);
}
}

View File

@@ -1,6 +1,5 @@
using Domains;
using Domains.VisaApplicationDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Infrastructure.Database.VisaApplications.Configuration
@@ -9,7 +8,9 @@ namespace Infrastructure.Database.VisaApplications.Configuration
{
public static void Configure(OwnedNavigationBuilder<T, PastVisit> entity)
{
entity.HasOne(p => p.DestinationCountry).WithMany().OnDelete(DeleteBehavior.Restrict);
entity.Property(pv => pv.DestinationCountry)
.IsUnicode(false)
.HasMaxLength(ConfigurationConstraints.CountryNameLength);
}
}
}

View File

@@ -10,6 +10,6 @@ public static class PermissionToDestCountryConfiguration<T> where T : class, IEn
{
entity.Property(p => p.Issuer)
.IsUnicode(false)
.HasMaxLength(200);
.HasMaxLength(ConfigurationConstraints.IssuerNameLength);
}
}

View File

@@ -10,6 +10,6 @@ public static class ReentryPermitConfiguration<T> where T : class, IEntity
{
entity.Property(p => p.Number)
.IsUnicode(false)
.HasMaxLength(25);
.HasMaxLength(ConfigurationConstraints.ReentryPermitNumberLength);
}
}

View File

@@ -1,4 +1,5 @@
using Domains.VisaApplicationDomain;
using Domains.ApplicantDomain;
using Domains.VisaApplicationDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
@@ -11,11 +12,13 @@ public class VisaApplicationConfiguration : IEntityTypeConfiguration<VisaApplica
entity.OwnsOne(va => va.ReentryPermit, ReentryPermitConfiguration<VisaApplication>.Configure);
entity.OwnsOne(va => va.PermissionToDestCountry, PermissionToDestCountryConfiguration<VisaApplication>.Configure);
entity.OwnsMany(va => va.PastVisits, PastVisitConfiguration<VisaApplication>.Configure);
entity.OwnsMany(va => va.PastVisas);
entity.OwnsMany(va => va.PastVisas, PastVisaConfiguration<VisaApplication>.Configure);
entity.HasOne(va => va.DestinationCountry).WithMany().OnDelete(DeleteBehavior.Restrict);
entity.Property(va => va.DestinationCountry)
.IsUnicode(false)
.HasMaxLength(ConfigurationConstraints.CountryNameLength);
entity.HasOne(va => va.Applicant)
entity.HasOne<Applicant>()
.WithMany()
.HasForeignKey(va => va.ApplicantId)
.IsRequired();

View File

@@ -10,7 +10,6 @@ public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWr
{
protected override IQueryable<VisaApplication> LoadDomain()
=> base.LoadDomain()
.Include(va => va.DestinationCountry)
.Include(va => va.PastVisas)
.Include(va => va.PastVisits);