From c1a4acf4149e3158d34eb52e9a4567607c69988e Mon Sep 17 00:00:00 2001 From: prtsie Date: Thu, 15 Aug 2024 14:54:23 +0300 Subject: [PATCH] Changed models, added Application layer models --- .../CreateVisaApplicationRequest.cs | 7 +- .../VisaApplication/Models/AddressModel.cs | 16 ++++ .../Models/PlaceOfWorkModel.cs | 13 +++ .../Domains/ApplicantDomain/Address.cs | 29 +++--- .../Domains/ApplicantDomain/Applicant.cs | 75 ++++++++------- .../Domains/ApplicantDomain/Gender.cs | 17 ++-- .../Domains/ApplicantDomain/MaritalStatus.cs | 19 ++-- .../Domains/ApplicantDomain/Name.cs | 19 ++-- .../Domains/ApplicantDomain/Passport.cs | 29 +++--- .../Domains/ApplicantDomain/PlaceOfWork.cs | 25 +++-- SchengenVisaApi/Domains/IEntity.cs | 13 ++- .../Domains/LocationDomain/City.cs | 23 +++-- .../Domains/LocationDomain/Country.cs | 27 +++--- .../Domains/VisaApplicationDomain/PastVisa.cs | 25 +++-- .../VisaApplicationDomain/PastVisit.cs | 21 ++--- .../PermissionToDestCountry.cs | 23 +++-- .../VisaApplicationDomain/ReentryPermit.cs | 23 +++-- .../RequestedNumberOfEntries.cs | 17 ++-- .../VisaApplicationDomain/VisaApplication.cs | 69 +++++++------- .../VisaApplicationDomain/VisaCategory.cs | 15 ++- .../Configuration/AddressConfiguration.cs | 23 +++-- .../Configuration/ApplicantConfiguration.cs | 33 ++++--- .../Configuration/NameConfiguration.cs | 29 +++--- .../Configuration/PassportConfiguration.cs | 27 +++--- .../Configuration/PlaceOfWorkConfiguration.cs | 25 +++-- .../Repositories/ApplicantsRepository.cs | 29 +++--- .../Repositories/IApplicantsRepository.cs | 9 +- .../Infrastructure/Database/DbContext.cs | 65 +++++++------ .../EntityNotFoundException.cs | 15 ++- .../Database/Generic/GenericRepository.cs | 91 +++++++++---------- .../Database/Generic/IGenericReader.cs | 17 ++-- .../Database/Generic/IGenericRepository.cs | 59 ++++++------ .../Database/Generic/IGenericWriter.cs | 39 ++++---- .../Infrastructure/Database/IUnitOfWork.cs | 15 ++- .../Configuration/CityConfiguration.cs | 17 ++-- .../Configuration/CountryConfiguration.cs | 17 ++-- .../Repositories/Cities/CitiesRepository.cs | 15 ++- .../Repositories/Cities/ICitiesRepository.cs | 7 +- .../Countries/CountriesRepository.cs | 15 ++- .../Countries/ICountriesRepository.cs | 7 +- .../Configuration/PastVisaConfiguration.cs | 17 ++-- .../PermissionToDestCountryConfiguration.cs | 17 ++-- .../ReentryPermitConfiguration.cs | 17 ++-- .../VisaApplicationConfiguration.cs | 25 ++--- .../IVisaApplicationsRepository.cs | 7 +- .../VisaApplicationsRepository.cs | 21 ++--- .../Infrastructure/DependencyInjection.cs | 37 ++++---- .../SchengenVisaApi/DependencyInjection.cs | 47 +++++----- SchengenVisaApi/SchengenVisaApi/Program.cs | 3 +- .../SchengenVisaApi/RequestPipeline.cs | 25 +++-- 50 files changed, 628 insertions(+), 647 deletions(-) create mode 100644 SchengenVisaApi/ApplicationLayer/VisaApplication/Models/AddressModel.cs create mode 100644 SchengenVisaApi/ApplicationLayer/VisaApplication/Models/PlaceOfWorkModel.cs diff --git a/SchengenVisaApi/ApplicationLayer/VisaApplication/CreateVisaApplicationRequest.cs b/SchengenVisaApi/ApplicationLayer/VisaApplication/CreateVisaApplicationRequest.cs index 964f957..e280265 100644 --- a/SchengenVisaApi/ApplicationLayer/VisaApplication/CreateVisaApplicationRequest.cs +++ b/SchengenVisaApi/ApplicationLayer/VisaApplication/CreateVisaApplicationRequest.cs @@ -1,4 +1,5 @@ -using Domains.ApplicantDomain; +using ApplicationLayer.VisaApplication.Models; +using Domains.ApplicantDomain; using Domains.VisaApplicationDomain; namespace ApplicationLayer.VisaApplication; @@ -19,7 +20,7 @@ public record CreateVisaApplicationRequest( bool IsNonResident, ReentryPermit ReentryPermit, string JobTitle, - PlaceOfWork PlaceOfWork, + PlaceOfWorkModel PlaceOfWork, string DestinationCountry, VisaCategory VisaCategory, bool IsForGroup, @@ -28,4 +29,4 @@ public record CreateVisaApplicationRequest( PastVisa[] PastVisas, PermissionToDestCountry? PermissionToDestCountry, PastVisit[] PastVisits - ); +); diff --git a/SchengenVisaApi/ApplicationLayer/VisaApplication/Models/AddressModel.cs b/SchengenVisaApi/ApplicationLayer/VisaApplication/Models/AddressModel.cs new file mode 100644 index 0000000..3b1288a --- /dev/null +++ b/SchengenVisaApi/ApplicationLayer/VisaApplication/Models/AddressModel.cs @@ -0,0 +1,16 @@ +namespace ApplicationLayer.VisaApplication.Models; + +public class AddressModel +{ + /// Country part of address + public string Country { get; set; } = null!; + + /// City part of address + public string City { get; set; } = null!; + + /// Street part of address + public string Street { get; set; } = null!; + + /// Building part of address + public string Building { get; set; } = null!; +} diff --git a/SchengenVisaApi/ApplicationLayer/VisaApplication/Models/PlaceOfWorkModel.cs b/SchengenVisaApi/ApplicationLayer/VisaApplication/Models/PlaceOfWorkModel.cs new file mode 100644 index 0000000..c436e32 --- /dev/null +++ b/SchengenVisaApi/ApplicationLayer/VisaApplication/Models/PlaceOfWorkModel.cs @@ -0,0 +1,13 @@ +namespace ApplicationLayer.VisaApplication.Models; + +public class PlaceOfWorkModel +{ + /// Name of hirer + public string Name { get; set; } = null!; + + /// of hirer + public AddressModel Address { get; set; } = null!; + + /// Phone number of hirer + public string PhoneNum { get; set; } = null!; +} diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Address.cs b/SchengenVisaApi/Domains/ApplicantDomain/Address.cs index d319e32..3455840 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Address.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Address.cs @@ -1,21 +1,20 @@ using Domains.LocationDomain; -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +/// Model of address +/// Owned +public class Address { - /// Model of address - /// Owned - public class Address - { - /// Country part of address - public Country Country { get; set; } = null!; + /// Country part of address + public Country Country { get; set; } = null!; - /// City part of address - public City City { get; set; } = null!; + /// City part of address + public City City { get; set; } = null!; - /// Street part of address - public string Street { get; set; } = null!; + /// Street part of address + public string Street { get; set; } = null!; - /// Building part of address - public string Building { get; set; } = null!; - } -} + /// Building part of address + public string Building { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs b/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs index c173803..77f2bdb 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs @@ -1,57 +1,56 @@ using Domains.LocationDomain; using Domains.VisaApplicationDomain; -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +/// Model of an applicant +public class Applicant : IEntity { - /// Model of an applicant - public class Applicant : IEntity - { - /// Unique identifier of the - public Guid Id { get; set; } + /// Unique identifier of the + public Guid Id { get; set; } - /// Full name of the - public Name Name { get; set; } = null!; + /// Full name of the + public Name Name { get; set; } = null!; - /// Passport of - public Passport Passport { get; set; } = null!; + /// Passport of + public Passport Passport { get; set; } = null!; - /// Date of birth of the - public DateTime BirthDate { get; set; } + /// Date of birth of the + public DateTime BirthDate { get; set; } - /// of birth of the - public Country CountryOfBirth { get; set; } = null!; + /// of birth of the + public Country CountryOfBirth { get; set; } = null!; - /// of birth of the - public City CityOfBirth { get; set; } = null!; + /// of birth of the + public City CityOfBirth { get; set; } = null!; - /// Citizenship of - public string Citizenship { get; set; } = null!; + /// Citizenship of + public string Citizenship { get; set; } = null!; - /// Citizenship by birth of - public string CitizenshipByBirth { get; set; } = null!; + /// Citizenship by birth of + public string CitizenshipByBirth { get; set; } = null!; - /// Gender of - public Gender Gender { get; set; } + /// Gender of + public Gender Gender { get; set; } - /// Marital status of - public MaritalStatus MaritalStatus { get; set; } + /// Marital status of + public MaritalStatus MaritalStatus { get; set; } - /// Full name of the 's father - public Name FatherName { get; set; } = null!; + /// Full name of the 's father + public Name FatherName { get; set; } = null!; - /// Full name of the 's mother - public Name MotherName { get; set; } = null!; + /// Full name of the 's mother + public Name MotherName { get; set; } = null!; - /// Position of - public string JobTitle { get; set; } = null!; + /// Position of + public string JobTitle { get; set; } = null!; - /// Place of 's work - public PlaceOfWork PlaceOfWork { get; set; } = null!; + /// Place of 's work + public PlaceOfWork PlaceOfWork { get; set; } = null!; - /// Is a non-resident - public bool IsNonResident { get; set; } + /// Is a non-resident + public bool IsNonResident { get; set; } - /// List of 's applications - public List VisaApplications { get; set; } = null!; - } -} + /// List of 's applications + public List VisaApplications { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Gender.cs b/SchengenVisaApi/Domains/ApplicantDomain/Gender.cs index 08588dc..f2e2f1d 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Gender.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Gender.cs @@ -1,10 +1,9 @@ -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +public enum Gender { - public enum Gender - { - Unknown, - Male, - Female, - Turkish - } -} + Unknown, + Male, + Female, + Turkish +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ApplicantDomain/MaritalStatus.cs b/SchengenVisaApi/Domains/ApplicantDomain/MaritalStatus.cs index 547edd6..7c57152 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/MaritalStatus.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/MaritalStatus.cs @@ -1,11 +1,10 @@ -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +public enum MaritalStatus { - public enum MaritalStatus - { - Other, - Married, - Unmarried, - Separated, - WidowOrWidower - } -} + Other, + Married, + Unmarried, + Separated, + WidowOrWidower +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Name.cs b/SchengenVisaApi/Domains/ApplicantDomain/Name.cs index 2455318..237297c 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Name.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Name.cs @@ -1,13 +1,12 @@ -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +/// Model of full name +/// Owned +public class Name { - /// Model of full name - /// Owned - public class Name - { - public string FirstName { get; set; } = null!; + public string FirstName { get; set; } = null!; - public string Surname { get; set; } = null!; + public string Surname { get; set; } = null!; - public string? Patronymic { get; set; } - } -} + public string? Patronymic { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Passport.cs b/SchengenVisaApi/Domains/ApplicantDomain/Passport.cs index 6a494b6..6e081c9 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Passport.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Passport.cs @@ -1,19 +1,18 @@ -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +/// Model of passport +/// Owned +public class Passport { - /// Model of passport - /// Owned - public class Passport - { - /// Number of - public string Number { get; set; } = null!; + /// Number of + public string Number { get; set; } = null!; - /// Issuing authority of - public string Issuer { get; set; } = null!; + /// Issuing authority of + public string Issuer { get; set; } = null!; - /// Date of issue - public DateTime IssueDate { get; set; } + /// Date of issue + public DateTime IssueDate { get; set; } - /// Date when the expires - public DateTime ExpirationDate { get; set; } - } -} + /// Date when the expires + public DateTime ExpirationDate { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ApplicantDomain/PlaceOfWork.cs b/SchengenVisaApi/Domains/ApplicantDomain/PlaceOfWork.cs index 4655bf6..2a78c14 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/PlaceOfWork.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/PlaceOfWork.cs @@ -1,17 +1,16 @@ -namespace Domains.ApplicantDomain +namespace Domains.ApplicantDomain; + +public class PlaceOfWork : IEntity { - public class PlaceOfWork : IEntity - { - /// Unique identifier of - public Guid Id { get; private set; } = Guid.NewGuid(); + /// Unique identifier of + public Guid Id { get; private set; } = Guid.NewGuid(); - /// Name of hirer - public string Name { get; set; } = null!; + /// Name of hirer + public string Name { get; set; } = null!; - /// of hirer - public Address Address { get; set; } = null!; + /// of hirer + public Address Address { get; set; } = null!; - /// Phone number of hirer - public string PhoneNum { get; set; } = null!; - } -} + /// Phone number of hirer + public string PhoneNum { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/IEntity.cs b/SchengenVisaApi/Domains/IEntity.cs index 0007e83..cedffef 100644 --- a/SchengenVisaApi/Domains/IEntity.cs +++ b/SchengenVisaApi/Domains/IEntity.cs @@ -1,8 +1,7 @@ -namespace Domains +namespace Domains; + +/// Interface that every entity should inherit from +public interface IEntity { - /// Interface that every entity should inherit from - public interface IEntity - { - public Guid Id { get; } - } -} + public Guid Id { get; } +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/LocationDomain/City.cs b/SchengenVisaApi/Domains/LocationDomain/City.cs index 1aa4830..ebc0e31 100644 --- a/SchengenVisaApi/Domains/LocationDomain/City.cs +++ b/SchengenVisaApi/Domains/LocationDomain/City.cs @@ -1,15 +1,14 @@ -namespace Domains.LocationDomain +namespace Domains.LocationDomain; + +/// Model of a city +public class City : IEntity { - /// Model of a city - public class City : IEntity - { - /// Unique identifier of the - public Guid Id { get; private set; } = Guid.NewGuid(); + /// Unique identifier of the + public Guid Id { get; private set; } = Guid.NewGuid(); - /// Name of the city - public string Name { get; set; } = null!; + /// Name of the city + public string Name { get; set; } = null!; - /// in which the city is located - public Country Country { get; set; } = null!; - } -} + /// in which the city is located + public Country Country { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/LocationDomain/Country.cs b/SchengenVisaApi/Domains/LocationDomain/Country.cs index 06a21a3..db0a495 100644 --- a/SchengenVisaApi/Domains/LocationDomain/Country.cs +++ b/SchengenVisaApi/Domains/LocationDomain/Country.cs @@ -1,18 +1,17 @@ -namespace Domains.LocationDomain +namespace Domains.LocationDomain; + +/// Model of a country +public class Country : IEntity { - /// Model of a country - public class Country : IEntity - { - /// Unique identifier of the - public Guid Id { get; private set; } = Guid.NewGuid(); + /// Unique identifier of the + public Guid Id { get; private set; } = Guid.NewGuid(); - /// Name of the country - public string Name { get; set; } = null!; + /// Name of the country + public string Name { get; set; } = null!; - /// Located in Schengen area - public bool IsSchengen { get; set; } + /// Located in Schengen area + public bool IsSchengen { get; set; } - /// List of that country have - public List Cities { get; set; } = null!; - } -} + /// List of that country have + public List Cities { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisa.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisa.cs index 1db3473..077c905 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisa.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisa.cs @@ -1,20 +1,17 @@ using Domains.ApplicantDomain; -namespace Domains.VisaApplicationDomain +namespace Domains.VisaApplicationDomain; + +/// Visa that already had +/// Owned +public class PastVisa { - /// Visa that already had - public class PastVisa : IEntity - { - /// Unique identifier of - public Guid Id { get; private set; } = Guid.NewGuid(); + /// Date of issue + public DateTime IssueDate { get; set; } - /// Date of issue - public DateTime IssueDate { get; set; } + /// Name of visa + public string Name { get; set; } = null!; - /// Name of visa - public string Name { get; set; } = null!; - - /// Date when visa expires - public DateTime ExpirationDate { get; set; } - } + /// Date when visa expires + public DateTime ExpirationDate { get; set; } } diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs index 10c0e84..b7017ed 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs @@ -1,17 +1,14 @@ using Domains.ApplicantDomain; -namespace Domains.VisaApplicationDomain +namespace Domains.VisaApplicationDomain; + +/// Visit in a Schengen country that already had +/// Owned +public class PastVisit { - /// Visit in a Schengen country that already had - public class PastVisit : IEntity - { - /// Unique identifier of - public Guid Id { get; private set; } = Guid.NewGuid(); + /// First day of + public DateTime StartDate { get; set; } - /// First day of - public DateTime StartDate { get; set; } - - /// Last day of - public DateTime EndDate { get; set; } - } + /// Last day of + public DateTime EndDate { get; set; } } diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/PermissionToDestCountry.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/PermissionToDestCountry.cs index 74e02ec..09027fe 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/PermissionToDestCountry.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/PermissionToDestCountry.cs @@ -1,13 +1,12 @@ -namespace Domains.VisaApplicationDomain -{ - /// Permission to enter the destination country - /// Owned - public class PermissionToDestCountry - { - /// Date when expires - public DateTime ExpirationDate { get; set; } +namespace Domains.VisaApplicationDomain; - /// Issuing authority - public string Issuer { get; set; } = null!; - } -} +/// Permission to enter the destination country +/// Owned +public class PermissionToDestCountry +{ + /// Date when expires + public DateTime ExpirationDate { get; set; } + + /// Issuing authority + public string Issuer { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/ReentryPermit.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/ReentryPermit.cs index 40164eb..2f77fbf 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/ReentryPermit.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/ReentryPermit.cs @@ -1,13 +1,12 @@ -namespace Domains.VisaApplicationDomain -{ - /// Permission to enter a country the issuer wants to come from - /// Owned - public class ReentryPermit - { - /// Number of - public string Number { get; set; } = null!; +namespace Domains.VisaApplicationDomain; - /// Date when expires - public DateTime ExpirationDate { get; set; } - } -} +/// Permission to enter a country the issuer wants to come from +/// Owned +public class ReentryPermit +{ + /// Number of + public string Number { get; set; } = null!; + + /// Date when expires + public DateTime ExpirationDate { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/RequestedNumberOfEntries.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/RequestedNumberOfEntries.cs index 8bcd998..b393585 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/RequestedNumberOfEntries.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/RequestedNumberOfEntries.cs @@ -1,10 +1,9 @@ -namespace Domains.VisaApplicationDomain +namespace Domains.VisaApplicationDomain; + +/// Requested number of entries +public enum RequestedNumberOfEntries { - /// Requested number of entries - public enum RequestedNumberOfEntries - { - Many, - One, - Two - } -} + Many, + One, + Two +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs index f133873..ba7596b 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs @@ -1,51 +1,50 @@ using Domains.ApplicantDomain; using Domains.LocationDomain; -namespace Domains.VisaApplicationDomain +namespace Domains.VisaApplicationDomain; + +/// Model of visit request +public class VisaApplication : IEntity { - /// Model of visit request - public class VisaApplication : IEntity - { - /// Unique identifier of - public Guid Id { get; private set; } = Guid.NewGuid(); + /// Unique identifier of + public Guid Id { get; private set; } = Guid.NewGuid(); - /// Identifier of the - public Guid ApplicantId { get; set; } + /// Identifier of the + public Guid ApplicantId { get; set; } - /// Applicant of - public Applicant Applicant { get; set; } = null!; + /// Applicant of + public Applicant Applicant { get; set; } = null!; - /// - /// always null if is not a non-resident - public ReentryPermit? ReentryPermit { get; set; } + /// + /// always null if is not a non-resident + public ReentryPermit? ReentryPermit { get; set; } - /// that wants to visit - public Country DestinationCountry { get; set; } = null!; + /// that wants to visit + public Country DestinationCountry { get; set; } = null!; - /// - /// List of that applicant had before - /// - public List PastVisas { get; set; } = null!; + /// + /// List of that applicant had before + /// + public List PastVisas { get; set; } = null!; - /// Permission to enter the destination country of - /// always null if is Schengen - public PermissionToDestCountry? PermissionToDestCountry { get; set; } + /// Permission to enter the destination country of + /// always null if is Schengen + public PermissionToDestCountry? PermissionToDestCountry { get; set; } - public List PastVisits { get; set; } = null!; + public List PastVisits { get; set; } = null!; - /// - public VisaCategory VisaCategory { get; set; } + /// + public VisaCategory VisaCategory { get; set; } - /// Is for group - public bool ForGroup { get; set; } + /// Is for group + public bool ForGroup { get; set; } - /// - public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } + /// + public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } - /// When application was created - public DateTime RequestDate { get; set; } + /// When application was created + public DateTime RequestDate { get; set; } - /// Valid days requested - public int ValidDaysRequested { get; set; } - } -} + /// Valid days requested + public int ValidDaysRequested { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/VisaCategory.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/VisaCategory.cs index 841044c..c3690f6 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/VisaCategory.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/VisaCategory.cs @@ -1,9 +1,8 @@ -namespace Domains.VisaApplicationDomain +namespace Domains.VisaApplicationDomain; + +/// Category of visa +public enum VisaCategory { - /// Category of visa - public enum VisaCategory - { - Transit, - ShortDated - } -} + Transit, + ShortDated +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/AddressConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/AddressConfiguration.cs index 868e7dc..5db0dc6 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/AddressConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/AddressConfiguration.cs @@ -2,18 +2,17 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Applicants.Configuration +namespace Infrastructure.Database.Applicants.Configuration; + +public class AddressConfiguration : IEntityTypeConfiguration
{ - public class AddressConfiguration : IEntityTypeConfiguration
+ public void Configure(EntityTypeBuilder
entity) { - public void Configure(EntityTypeBuilder
entity) - { - entity.Property(p => p.Street) - .IsUnicode(false) - .HasMaxLength(100); - entity.Property(p => p.Building) - .IsUnicode(false) - .HasMaxLength(10); - } + entity.Property(p => p.Street) + .IsUnicode(false) + .HasMaxLength(100); + entity.Property(p => p.Building) + .IsUnicode(false) + .HasMaxLength(10); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs index 025c6f3..cc3bca4 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs @@ -2,26 +2,25 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Applicants.Configuration +namespace Infrastructure.Database.Applicants.Configuration; + +public class ApplicantConfiguration : IEntityTypeConfiguration { - public class ApplicantConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.ToTable("Applicants"); + entity.ToTable("Applicants"); - entity.OwnsOne(p => p.Name); - entity.OwnsOne(p => p.FatherName); - entity.OwnsOne(p => p.MotherName); - entity.OwnsOne(p => p.Passport); + entity.OwnsOne(p => p.Name); + entity.OwnsOne(p => p.FatherName); + entity.OwnsOne(p => p.MotherName); + entity.OwnsOne(p => p.Passport); - entity.Property(p => p.Citizenship) - .IsUnicode(false) - .HasMaxLength(30); + entity.Property(p => p.Citizenship) + .IsUnicode(false) + .HasMaxLength(30); - entity.Property(p => p.CitizenshipByBirth) - .IsUnicode(false) - .HasMaxLength(30); - } + entity.Property(p => p.CitizenshipByBirth) + .IsUnicode(false) + .HasMaxLength(30); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs index e194101..e13842a 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs @@ -2,23 +2,22 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Applicants.Configuration +namespace Infrastructure.Database.Applicants.Configuration; + +public class NameConfiguration : IEntityTypeConfiguration { - public class NameConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.FirstName) - .IsUnicode(false) - .HasMaxLength(50); + entity.Property(p => p.FirstName) + .IsUnicode(false) + .HasMaxLength(50); - entity.Property(p => p.Surname) - .IsUnicode(false) - .HasMaxLength(50); + entity.Property(p => p.Surname) + .IsUnicode(false) + .HasMaxLength(50); - entity.Property(p => p.Patronymic) - .IsUnicode(false) - .HasMaxLength(50); - } + entity.Property(p => p.Patronymic) + .IsUnicode(false) + .HasMaxLength(50); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs index e9a1a6e..18ef216 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs @@ -2,19 +2,18 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Applicants.Configuration -{ - public class PassportConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.Number) - .IsUnicode(false) - .HasMaxLength(20); +namespace Infrastructure.Database.Applicants.Configuration; - entity.Property(p => p.Issuer) - .IsUnicode(false) - .HasMaxLength(200); - } +public class PassportConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder entity) + { + entity.Property(p => p.Number) + .IsUnicode(false) + .HasMaxLength(20); + + entity.Property(p => p.Issuer) + .IsUnicode(false) + .HasMaxLength(200); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs index 6203a4c..9336d04 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs @@ -2,21 +2,20 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Applicants.Configuration +namespace Infrastructure.Database.Applicants.Configuration; + +public class PlaceOfWorkConfiguration : IEntityTypeConfiguration { - public class PlaceOfWorkConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.OwnsOne(p => p.Address); + entity.OwnsOne(p => p.Address); - entity.Property(p => p.Name) - .IsUnicode(false) - .HasMaxLength(200); + entity.Property(p => p.Name) + .IsUnicode(false) + .HasMaxLength(200); - entity.Property(p => p.PhoneNum) - .IsUnicode(false) - .HasMaxLength(20); - } + entity.Property(p => p.PhoneNum) + .IsUnicode(false) + .HasMaxLength(20); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs index 473a43b..b19ad1a 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs @@ -2,21 +2,20 @@ using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database.Applicants.Repositories +namespace Infrastructure.Database.Applicants.Repositories; + +/// Repository pattern for +/// +/// +/// +public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) + : GenericRepository(reader, writer, unitOfWork), IApplicantsRepository { - /// Repository pattern for - /// - /// - /// - public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) - : GenericRepository(reader, writer, unitOfWork), IApplicantsRepository + protected override IQueryable LoadDomain() { - protected override IQueryable LoadDomain() - { - return base.LoadDomain() - .Include(a => a.CountryOfBirth) - .Include(a => a.CityOfBirth) - .Include(a => a.PlaceOfWork); - } + return base.LoadDomain() + .Include(a => a.CountryOfBirth) + .Include(a => a.CityOfBirth) + .Include(a => a.PlaceOfWork); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/IApplicantsRepository.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/IApplicantsRepository.cs index d26b29a..62561d1 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/IApplicantsRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/IApplicantsRepository.cs @@ -1,8 +1,7 @@ using Domains.ApplicantDomain; using Infrastructure.Database.Generic; -namespace Infrastructure.Database.Applicants.Repositories -{ - /// Repository pattern for - public interface IApplicantsRepository : IGenericRepository { } -} +namespace Infrastructure.Database.Applicants.Repositories; + +/// Repository pattern for +public interface IApplicantsRepository : IGenericRepository { } \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/DbContext.cs b/SchengenVisaApi/Infrastructure/Database/DbContext.cs index 7d3a975..2d21103 100644 --- a/SchengenVisaApi/Infrastructure/Database/DbContext.cs +++ b/SchengenVisaApi/Infrastructure/Database/DbContext.cs @@ -2,39 +2,38 @@ using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database +namespace Infrastructure.Database; + +public class DbContext(DbContextOptions opts) + : Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork { - public class DbContext(DbContextOptions opts) - : Microsoft.EntityFrameworkCore.DbContext(opts), IGenericWriter, IGenericReader, IUnitOfWork + protected override void OnModelCreating(ModelBuilder modelBuilder) { - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); - } - - async Task IGenericWriter.AddAsync(T entity, CancellationToken cancellationToken) - { - await AddAsync(entity, cancellationToken); - } - - void IGenericWriter.Update(T entity) - { - Update(entity); - } - - void IGenericWriter.Remove(T entity) - { - Remove(entity); - } - - IQueryable IGenericReader.GetAll() - { - return Set(); - } - - async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken) - { - await SaveChangesAsync(cancellationToken); - } + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); } -} + + async Task IGenericWriter.AddAsync(T entity, CancellationToken cancellationToken) + { + await AddAsync(entity, cancellationToken); + } + + void IGenericWriter.Update(T entity) + { + Update(entity); + } + + void IGenericWriter.Remove(T entity) + { + Remove(entity); + } + + IQueryable IGenericReader.GetAll() + { + return Set(); + } + + async Task IUnitOfWork.SaveAsync(CancellationToken cancellationToken) + { + await SaveChangesAsync(cancellationToken); + } +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/GeneralExceptions/EntityNotFoundException.cs b/SchengenVisaApi/Infrastructure/Database/GeneralExceptions/EntityNotFoundException.cs index d98221d..2d6801c 100644 --- a/SchengenVisaApi/Infrastructure/Database/GeneralExceptions/EntityNotFoundException.cs +++ b/SchengenVisaApi/Infrastructure/Database/GeneralExceptions/EntityNotFoundException.cs @@ -1,10 +1,9 @@ using Domains; -namespace Infrastructure.Database.GeneralExceptions -{ - /// Exception to throw when entity with specific id not found - /// Identifier of entity - /// Not found entity type - public class EntityNotFoundException(Guid id) : Exception($"Entity {typeof(T).Name} with id '{id}' not found") - where T : class, IEntity; -} +namespace Infrastructure.Database.GeneralExceptions; + +/// Exception to throw when entity with specific id not found +/// Identifier of entity +/// Not found entity type +public class EntityNotFoundException(Guid id) : Exception($"Entity {typeof(T).Name} with id '{id}' not found") + where T : class, IEntity; \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Generic/GenericRepository.cs b/SchengenVisaApi/Infrastructure/Database/Generic/GenericRepository.cs index c8c2391..9bc6475 100644 --- a/SchengenVisaApi/Infrastructure/Database/Generic/GenericRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Generic/GenericRepository.cs @@ -2,52 +2,51 @@ using Infrastructure.Database.GeneralExceptions; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database.Generic +namespace Infrastructure.Database.Generic; + +/// Generic repository pattern +/// +/// +/// Type of entity +/// Should be inherited to create typed repositories +public abstract class GenericRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : IGenericRepository + where T : class, IEntity { - /// Generic repository pattern - /// - /// - /// Type of entity - /// Should be inherited to create typed repositories - public abstract class GenericRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : IGenericRepository - where T : class, IEntity + /// + public async Task> GetAllAsync(CancellationToken cancellationToken) + => await LoadDomain().ToListAsync(cancellationToken); + + /// + public async Task GetOneAsync(Guid id, CancellationToken cancellationToken) { - /// - public async Task> GetAllAsync(CancellationToken cancellationToken) - => await LoadDomain().ToListAsync(cancellationToken); - - /// - public async Task GetOneAsync(Guid id, CancellationToken cancellationToken) - { - var result = await LoadDomain().SingleOrDefaultAsync(a => a.Id == id, cancellationToken); - return result ?? throw new EntityNotFoundException(id); - } - - /// - public async Task AddAsync(T entity, CancellationToken cancellationToken) - => await writer.AddAsync(entity, cancellationToken); - - /// - public async Task UpdateAsync(T entity, CancellationToken cancellationToken) - { - await GetOneAsync(entity.Id, cancellationToken); - writer.Update(entity); - } - - /// - public void Remove(T entity) - { - writer.Remove(entity); - } - - /// - public async Task SaveAsync(CancellationToken cancellationToken) - => await unitOfWork.SaveAsync(cancellationToken); - - /// Should be overriden to load navigation properties of entity - protected virtual IQueryable LoadDomain() - { - return reader.GetAll(); - } + var result = await LoadDomain().SingleOrDefaultAsync(a => a.Id == id, cancellationToken); + return result ?? throw new EntityNotFoundException(id); } -} + + /// + public async Task AddAsync(T entity, CancellationToken cancellationToken) + => await writer.AddAsync(entity, cancellationToken); + + /// + public async Task UpdateAsync(T entity, CancellationToken cancellationToken) + { + await GetOneAsync(entity.Id, cancellationToken); + writer.Update(entity); + } + + /// + public void Remove(T entity) + { + writer.Remove(entity); + } + + /// + public async Task SaveAsync(CancellationToken cancellationToken) + => await unitOfWork.SaveAsync(cancellationToken); + + /// Should be overriden to load navigation properties of entity + protected virtual IQueryable LoadDomain() + { + return reader.GetAll(); + } +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Generic/IGenericReader.cs b/SchengenVisaApi/Infrastructure/Database/Generic/IGenericReader.cs index 679f42c..2923a57 100644 --- a/SchengenVisaApi/Infrastructure/Database/Generic/IGenericReader.cs +++ b/SchengenVisaApi/Infrastructure/Database/Generic/IGenericReader.cs @@ -1,12 +1,11 @@ using Domains; -namespace Infrastructure.Database.Generic +namespace Infrastructure.Database.Generic; + +/// Reads from data storage +public interface IGenericReader { - /// Reads from data storage - public interface IGenericReader - { - /// Get all entities of type T stored in storage - /// Entity type to seek in storage - IQueryable GetAll() where T : class, IEntity; - } -} + /// Get all entities of type T stored in storage + /// Entity type to seek in storage + IQueryable GetAll() where T : class, IEntity; +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Generic/IGenericRepository.cs b/SchengenVisaApi/Infrastructure/Database/Generic/IGenericRepository.cs index 5478600..3b49c2e 100644 --- a/SchengenVisaApi/Infrastructure/Database/Generic/IGenericRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Generic/IGenericRepository.cs @@ -1,37 +1,36 @@ using Domains; -namespace Infrastructure.Database.Generic +namespace Infrastructure.Database.Generic; + +/// +/// Generic repository pattern +/// +/// Entity type +public interface IGenericRepository where T : class, IEntity { + /// Get all entities from data storage + Task> GetAllAsync(CancellationToken cancellationToken); + + /// Get one entity with specific id + /// Identifier of entity + Task GetOneAsync(Guid id, CancellationToken cancellationToken); + + /// Add entity to storage + /// Entity to add + Task AddAsync(T entity, CancellationToken cancellationToken); + /// - /// Generic repository pattern + /// Update entity in storage /// - /// Entity type - public interface IGenericRepository where T : class, IEntity - { - /// Get all entities from data storage - Task> GetAllAsync(CancellationToken cancellationToken); + /// Entity to update + Task UpdateAsync(T entity, CancellationToken cancellationToken); - /// Get one entity with specific id - /// Identifier of entity - Task GetOneAsync(Guid id, CancellationToken cancellationToken); + /// + /// Remove entity from storage + /// + /// Entity to remove + void Remove(T entity); - /// Add entity to storage - /// Entity to add - Task AddAsync(T entity, CancellationToken cancellationToken); - - /// - /// Update entity in storage - /// - /// Entity to update - Task UpdateAsync(T entity, CancellationToken cancellationToken); - - /// - /// Remove entity from storage - /// - /// Entity to remove - void Remove(T entity); - - /// Save changes in storage - Task SaveAsync(CancellationToken cancellationToken); - } -} + /// Save changes in storage + Task SaveAsync(CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Generic/IGenericWriter.cs b/SchengenVisaApi/Infrastructure/Database/Generic/IGenericWriter.cs index ab2b075..77db3c2 100644 --- a/SchengenVisaApi/Infrastructure/Database/Generic/IGenericWriter.cs +++ b/SchengenVisaApi/Infrastructure/Database/Generic/IGenericWriter.cs @@ -1,25 +1,24 @@ using Domains; -namespace Infrastructure.Database.Generic +namespace Infrastructure.Database.Generic; + +/// Writes data to data storage +/// should be used to save changes +public interface IGenericWriter { - /// Writes data to data storage - /// should be used to save changes - public interface IGenericWriter - { - /// Add entity to data storage - /// Entity to add - /// Cancellation Token - /// Entity type - Task AddAsync(T entity, CancellationToken cancellationToken) where T : class, IEntity; + /// Add entity to data storage + /// Entity to add + /// Cancellation Token + /// Entity type + Task AddAsync(T entity, CancellationToken cancellationToken) where T : class, IEntity; - /// Update entity in data storage - /// Entity to update - /// Entity type - void Update(T entity) where T : class, IEntity; + /// Update entity in data storage + /// Entity to update + /// Entity type + void Update(T entity) where T : class, IEntity; - /// Remove entity from data storage - /// Entity to remove - /// Entity type - void Remove(T entity) where T : class, IEntity; - } -} + /// Remove entity from data storage + /// Entity to remove + /// Entity type + void Remove(T entity) where T : class, IEntity; +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/IUnitOfWork.cs b/SchengenVisaApi/Infrastructure/Database/IUnitOfWork.cs index 653ddbc..821c4f1 100644 --- a/SchengenVisaApi/Infrastructure/Database/IUnitOfWork.cs +++ b/SchengenVisaApi/Infrastructure/Database/IUnitOfWork.cs @@ -1,9 +1,8 @@ -namespace Infrastructure.Database +namespace Infrastructure.Database; + +public interface IUnitOfWork { - public interface IUnitOfWork - { - /// Saves changes in data storage - /// Cancellation Token - Task SaveAsync(CancellationToken cancellationToken); - } -} + /// Saves changes in data storage + /// Cancellation Token + Task SaveAsync(CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs index d43ea6a..a9b3c4b 100644 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs @@ -2,15 +2,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Locations.Configuration +namespace Infrastructure.Database.Locations.Configuration; + +public class CityConfiguration : IEntityTypeConfiguration { - public class CityConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.Name) - .IsUnicode(false) - .HasMaxLength(70); - } + entity.Property(p => p.Name) + .IsUnicode(false) + .HasMaxLength(70); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CountryConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CountryConfiguration.cs index 1e909f9..5f0459e 100644 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CountryConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CountryConfiguration.cs @@ -2,15 +2,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Locations.Configuration +namespace Infrastructure.Database.Locations.Configuration; + +public class CountryConfiguration : IEntityTypeConfiguration { - public class CountryConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.Name) - .IsUnicode(false) - .HasMaxLength(70); - } + entity.Property(p => p.Name) + .IsUnicode(false) + .HasMaxLength(70); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs index b417188..cb42d8a 100644 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs @@ -2,14 +2,13 @@ using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database.Locations.Repositories.Cities +namespace Infrastructure.Database.Locations.Repositories.Cities; + +public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) + : GenericRepository(reader, writer, unitOfWork), ICitiesRepository { - public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) - : GenericRepository(reader, writer, unitOfWork), ICitiesRepository + protected override IQueryable LoadDomain() { - protected override IQueryable LoadDomain() - { - return base.LoadDomain().Include(c => c.Country); - } + return base.LoadDomain().Include(c => c.Country); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/ICitiesRepository.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/ICitiesRepository.cs index 5f5cf9b..8a5e042 100644 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/ICitiesRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/ICitiesRepository.cs @@ -1,7 +1,6 @@ using Domains.LocationDomain; using Infrastructure.Database.Generic; -namespace Infrastructure.Database.Locations.Repositories.Cities -{ - public interface ICitiesRepository : IGenericRepository { } -} +namespace Infrastructure.Database.Locations.Repositories.Cities; + +public interface ICitiesRepository : IGenericRepository { } \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs index 8d431b9..3616e3d 100644 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs @@ -2,14 +2,13 @@ using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database.Locations.Repositories.Countries +namespace Infrastructure.Database.Locations.Repositories.Countries; + +public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) + : GenericRepository(reader, writer, unitOfWork), ICountriesRepository { - public sealed class CountriesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) - : GenericRepository(reader, writer, unitOfWork), ICountriesRepository + protected override IQueryable LoadDomain() { - protected override IQueryable LoadDomain() - { - return base.LoadDomain().Include(c => c.Cities); - } + return base.LoadDomain().Include(c => c.Cities); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/ICountriesRepository.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/ICountriesRepository.cs index 0361a9b..dc94dd3 100644 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/ICountriesRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/ICountriesRepository.cs @@ -1,7 +1,6 @@ using Domains.LocationDomain; using Infrastructure.Database.Generic; -namespace Infrastructure.Database.Locations.Repositories.Countries -{ - public interface ICountriesRepository : IGenericRepository { } -} +namespace Infrastructure.Database.Locations.Repositories.Countries; + +public interface ICountriesRepository : IGenericRepository { } \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs index 2041a81..41cfb70 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs @@ -2,15 +2,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.VisaApplications.Configuration +namespace Infrastructure.Database.VisaApplications.Configuration; + +public class PastVisaConfiguration : IEntityTypeConfiguration { - public class PastVisaConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.Name) - .IsUnicode(false) - .HasMaxLength(70); - } + entity.Property(p => p.Name) + .IsUnicode(false) + .HasMaxLength(70); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs index a8a3c44..9f02124 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs @@ -2,15 +2,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.VisaApplications.Configuration +namespace Infrastructure.Database.VisaApplications.Configuration; + +public class PermissionToDestCountryConfiguration : IEntityTypeConfiguration { - public class PermissionToDestCountryConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.Issuer) - .IsUnicode(false) - .HasMaxLength(200); - } + entity.Property(p => p.Issuer) + .IsUnicode(false) + .HasMaxLength(200); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs index 7e6755c..8e834b5 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs @@ -2,15 +2,14 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.VisaApplications.Configuration +namespace Infrastructure.Database.VisaApplications.Configuration; + +public class ReentryPermitConfiguration : IEntityTypeConfiguration { - public class ReentryPermitConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.Property(p => p.Number) - .IsUnicode(false) - .HasMaxLength(25); - } + entity.Property(p => p.Number) + .IsUnicode(false) + .HasMaxLength(25); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs index fee6000..16d23d2 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs @@ -2,21 +2,22 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.VisaApplications.Configuration +namespace Infrastructure.Database.VisaApplications.Configuration; + +public class VisaApplicationConfiguration : IEntityTypeConfiguration { - public class VisaApplicationConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { - entity.ToTable("VisaApplications"); + entity.ToTable("VisaApplications"); - entity.HasOne(va => va.Applicant) - .WithMany(a => a.VisaApplications) - .HasForeignKey(va => va.ApplicantId) - .IsRequired(); + entity.HasOne(va => va.Applicant) + .WithMany(a => a.VisaApplications) + .HasForeignKey(va => va.ApplicantId) + .IsRequired(); - entity.OwnsOne(p => p.ReentryPermit); - entity.OwnsOne(p => p.PermissionToDestCountry); - } + entity.OwnsOne(p => p.ReentryPermit); + entity.OwnsOne(p => p.PermissionToDestCountry); + entity.OwnsMany(p => p.PastVisits).ToTable("PastVisits"); + entity.OwnsMany(p => p.PastVisas).ToTable("PastVisas"); } } diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/IVisaApplicationsRepository.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/IVisaApplicationsRepository.cs index 14e4965..e9ce3dd 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/IVisaApplicationsRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/IVisaApplicationsRepository.cs @@ -1,7 +1,6 @@ using Domains.VisaApplicationDomain; using Infrastructure.Database.Generic; -namespace Infrastructure.Database.VisaApplications.Repositories -{ - public interface IVisaApplicationsRepository : IGenericRepository { } -} +namespace Infrastructure.Database.VisaApplications.Repositories; + +public interface IVisaApplicationsRepository : IGenericRepository { } \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs index d18d1f4..33ef5b2 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs @@ -2,17 +2,16 @@ using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database.VisaApplications.Repositories +namespace Infrastructure.Database.VisaApplications.Repositories; + +public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) + : GenericRepository(reader, writer, unitOfWork), IVisaApplicationsRepository { - public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) - : GenericRepository(reader, writer, unitOfWork), IVisaApplicationsRepository + protected override IQueryable LoadDomain() { - protected override IQueryable LoadDomain() - { - return base.LoadDomain() - .Include(a => a.DestinationCountry) - .Include(a => a.PastVisas) - .Include(a => a.PastVisits); - } + return base.LoadDomain() + .Include(a => a.DestinationCountry) + .Include(a => a.PastVisas) + .Include(a => a.PastVisits); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/DependencyInjection.cs b/SchengenVisaApi/Infrastructure/DependencyInjection.cs index 156abe4..f976ffe 100644 --- a/SchengenVisaApi/Infrastructure/DependencyInjection.cs +++ b/SchengenVisaApi/Infrastructure/DependencyInjection.cs @@ -8,28 +8,27 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using DbContext = Infrastructure.Database.DbContext; -namespace Infrastructure +namespace Infrastructure; + +/// Provides methods to add services to DI-container +public static class DependencyInjection { - /// Provides methods to add services to DI-container - public static class DependencyInjection + /// Add services needed for Infrastructure layer + public static IServiceCollection AddInfrastructure(this IServiceCollection services) { - /// Add services needed for Infrastructure layer - public static IServiceCollection AddInfrastructure(this IServiceCollection services) - { - //TODO строка подключения - services.AddDbContext(opts => - opts.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=visadb;Integrated Security=True;")); + //TODO строка подключения + services.AddDbContext(opts => + opts.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=visadb;Integrated Security=True;")); - services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); - services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); - services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); + services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); + services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); + services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); - return services; - } + return services; } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/DependencyInjection.cs b/SchengenVisaApi/SchengenVisaApi/DependencyInjection.cs index 9b3dffc..7851b66 100644 --- a/SchengenVisaApi/SchengenVisaApi/DependencyInjection.cs +++ b/SchengenVisaApi/SchengenVisaApi/DependencyInjection.cs @@ -1,31 +1,30 @@ using System.Reflection; using Infrastructure; -namespace SchengenVisaApi +namespace SchengenVisaApi; + +/// Provides methods to add services to DI-container +public static class DependencyInjection { - /// Provides methods to add services to DI-container - public static class DependencyInjection + /// Add needed services + public static IServiceCollection RegisterServices(this IServiceCollection services) { - /// Add needed services - public static IServiceCollection RegisterServices(this IServiceCollection services) - { - services - .AddInfrastructure() - .AddPresentation(); + services + .AddInfrastructure() + .AddPresentation(); - return services; - } - - /// Add services needed for Presentation layer - private static void AddPresentation(this IServiceCollection services) - { - services.AddControllers(); - services.AddEndpointsApiExplorer(); - services.AddSwaggerGen(options => - { - var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; - options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); - }); - } + return services; } -} + + /// Add services needed for Presentation layer + private static void AddPresentation(this IServiceCollection services) + { + services.AddControllers(); + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(options => + { + var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); + }); + } +} \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/Program.cs b/SchengenVisaApi/SchengenVisaApi/Program.cs index 929f927..f800273 100644 --- a/SchengenVisaApi/SchengenVisaApi/Program.cs +++ b/SchengenVisaApi/SchengenVisaApi/Program.cs @@ -1,5 +1,4 @@ namespace SchengenVisaApi; - #pragma warning disable CS1591 public class Program { @@ -14,4 +13,4 @@ public class Program app.Run(); } } -#pragma warning restore CS1591 +#pragma warning restore CS1591 \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/RequestPipeline.cs b/SchengenVisaApi/SchengenVisaApi/RequestPipeline.cs index 24f4a34..cca11d1 100644 --- a/SchengenVisaApi/SchengenVisaApi/RequestPipeline.cs +++ b/SchengenVisaApi/SchengenVisaApi/RequestPipeline.cs @@ -1,19 +1,18 @@ -namespace SchengenVisaApi +namespace SchengenVisaApi; + +/// Provides methods for configuring middleware +public static class PipelineRequest { - /// Provides methods for configuring middleware - public static class PipelineRequest + /// Configure middleware + public static WebApplication ConfigurePipelineRequest(this WebApplication app) { - /// Configure middleware - public static WebApplication ConfigurePipelineRequest(this WebApplication app) - { - app.UseSwagger() - .UseSwaggerUI(); + app.UseSwagger() + .UseSwaggerUI(); - app.UseHttpsRedirection(); + app.UseHttpsRedirection(); - app.MapControllers(); + app.MapControllers(); - return app; - } + return app; } -} +} \ No newline at end of file