From 3e21a0a164be0cbd8a173093668a581217592296 Mon Sep 17 00:00:00 2001 From: prtsie Date: Wed, 21 Aug 2024 18:39:22 +0300 Subject: [PATCH] Removed location entities, fixed configurations and controllers' comments --- .../ApplicationLayer/DependencyInjection.cs | 2 - .../RegisterService/RegisterService.cs | 23 +---- .../Requests/RegisterApplicantRequest.cs | 8 +- .../NeededServices/ICitiesRepository.cs | 10 -- .../NeededServices/ICountriesRepository.cs | 13 --- .../CityCanNotBeDeletedException.cs | 7 -- .../Exceptions/CountryAlreadyExists.cs | 6 -- .../Exceptions/CountryNotFoundException.cs | 7 -- ...ltipleIdenticalCitiesInCountryException.cs | 6 -- .../ILocationRequestsHandler.cs | 19 ---- .../LocationRequestsHandler.cs | 91 ------------------- .../Locations/Requests/AddCountryRequest.cs | 4 - .../Requests/UpdateCountryRequest.cs | 4 - .../VisaApplicationRequestsHandler.cs | 24 +---- .../VisaApplications/Models/PastVisitModel.cs | 17 ---- .../Models/PastVisitModelForRequest.cs | 17 ---- .../VisaApplicationModelForApplicant.cs | 2 +- .../Requests/VisaApplicationCreateRequest.cs | 7 +- .../Domains/ApplicantDomain/Address.cs | 10 +- .../Domains/ApplicantDomain/Applicant.cs | 12 +-- .../Domains/LocationDomain/City.cs | 17 ---- .../Domains/LocationDomain/Country.cs | 17 ---- .../VisaApplicationDomain/PastVisit.cs | 3 +- .../VisaApplicationDomain/VisaApplication.cs | 10 +- .../Configuration/AddressConfiguration.cs | 20 ++-- .../Configuration/ApplicantConfiguration.cs | 26 ++++-- .../Configuration/NameConfiguration.cs | 6 +- .../Configuration/PassportConfiguration.cs | 4 +- .../Configuration/PlaceOfWorkConfiguration.cs | 4 +- .../Repositories/ApplicantsRepository.cs | 2 - .../Database/ConfigurationConstraints.cs | 20 ++++ .../Configuration/CityConfiguration.cs | 15 --- .../Configuration/CountryConfiguration.cs | 17 ---- .../Repositories/Cities/CitiesRepository.cs | 18 ---- .../Countries/CountriesRepository.cs | 27 ------ .../Users/Configuration/UserConfiguration.cs | 4 +- .../Configuration/PastVisaConfiguration.cs | 2 +- .../Configuration/PastVisitConfiguration.cs | 5 +- .../PermissionToDestCountryConfiguration.cs | 2 +- .../ReentryPermitConfiguration.cs | 2 +- .../VisaApplicationConfiguration.cs | 11 ++- .../VisaApplicationsRepository.cs | 1 - .../Infrastructure/DependencyInjection.cs | 5 - .../Controllers/LocationsController.cs | 53 ----------- .../Controllers/UsersController.cs | 11 +-- .../Controllers/VisaApplicationController.cs | 15 ++- .../GlobalExceptionsFilter.cs | 11 --- 47 files changed, 111 insertions(+), 506 deletions(-) delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICitiesRepository.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICountriesRepository.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CityCanNotBeDeletedException.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryAlreadyExists.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryNotFoundException.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/MultipleIdenticalCitiesInCountryException.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/ILocationRequestsHandler.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/LocationRequestsHandler.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/AddCountryRequest.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/UpdateCountryRequest.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModel.cs delete mode 100644 SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModelForRequest.cs delete mode 100644 SchengenVisaApi/Domains/LocationDomain/City.cs delete mode 100644 SchengenVisaApi/Domains/LocationDomain/Country.cs create mode 100644 SchengenVisaApi/Infrastructure/Database/ConfigurationConstraints.cs delete mode 100644 SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs delete mode 100644 SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CountryConfiguration.cs delete mode 100644 SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs delete mode 100644 SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs delete mode 100644 SchengenVisaApi/SchengenVisaApi/Controllers/LocationsController.cs diff --git a/SchengenVisaApi/ApplicationLayer/DependencyInjection.cs b/SchengenVisaApi/ApplicationLayer/DependencyInjection.cs index 30e32ee..63b38d8 100644 --- a/SchengenVisaApi/ApplicationLayer/DependencyInjection.cs +++ b/SchengenVisaApi/ApplicationLayer/DependencyInjection.cs @@ -1,6 +1,5 @@ using ApplicationLayer.Services.AuthServices.LoginService; using ApplicationLayer.Services.AuthServices.RegisterService; -using ApplicationLayer.Services.Locations.RequestHandlers; using ApplicationLayer.Services.VisaApplications.Handlers; using Microsoft.Extensions.DependencyInjection; @@ -13,7 +12,6 @@ public static class DependencyInjection public static IServiceCollection AddApplicationLayer(this IServiceCollection services, bool isDevelopment = false) { services.AddScoped(); - services.AddScoped(); services.AddScoped(); diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs index 0f5c534..68cedc8 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs @@ -3,7 +3,6 @@ using ApplicationLayer.Services.Applicants.NeededServices; using ApplicationLayer.Services.AuthServices.NeededServices; using ApplicationLayer.Services.AuthServices.RegisterService.Exceptions; using ApplicationLayer.Services.AuthServices.Requests; -using ApplicationLayer.Services.Locations.NeededServices; using Domains.ApplicantDomain; using Domains.Users; @@ -13,7 +12,6 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService public class RegisterService( IUsersRepository users, IApplicantsRepository applicants, - ICitiesRepository cities, IUnitOfWork unitOfWork) : IRegisterService { async Task IRegisterService.Register(RegisterApplicantRequest request, CancellationToken cancellationToken) @@ -27,21 +25,6 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService //TODO mapper var user = new User { Email = request.Email, Password = request.Password, Role = Role.Applicant }; - var applicantCity = await cities.GetByIdAsync(request.CityOfBirthId, cancellationToken); - var placeOfWorkCity = await cities.GetByIdAsync(request.PlaceOfWork.Address.CityId, cancellationToken); - var placeOfWorkAddress = new Address - { - Country = placeOfWorkCity.Country, - City = placeOfWorkCity, - Building = request.PlaceOfWork.Address.Building, - Street = request.PlaceOfWork.Address.Street - }; - - var placeOfWork = new PlaceOfWork - { - Name = request.PlaceOfWork.Name, Address = placeOfWorkAddress, PhoneNum = request.PlaceOfWork.PhoneNum - }; - var applicant = new Applicant { Citizenship = request.Citizenship, @@ -55,10 +38,10 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService MaritalStatus = request.MaritalStatus, MotherName = request.MotherName, UserId = user.Id, - CityOfBirth = applicantCity, - CountryOfBirth = applicantCity.Country, + CityOfBirth = request.CityOfBirth, + CountryOfBirth = request.CountryOfBirth, IsNonResident = request.IsNonResident, - PlaceOfWork = placeOfWork + PlaceOfWork = request.PlaceOfWork }; await users.AddAsync(user, cancellationToken); diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs index 22dbe4d..e9b5d9a 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs @@ -1,5 +1,4 @@ -using ApplicationLayer.Services.Applicants.Models; -using Domains.ApplicantDomain; +using Domains.ApplicantDomain; namespace ApplicationLayer.Services.AuthServices.Requests { @@ -9,7 +8,8 @@ namespace ApplicationLayer.Services.AuthServices.Requests Name ApplicantName, Passport Passport, DateTime BirthDate, - Guid CityOfBirthId, + string CityOfBirth, + string CountryOfBirth, string Citizenship, string CitizenshipByBirth, Gender Gender, @@ -17,6 +17,6 @@ namespace ApplicationLayer.Services.AuthServices.Requests Name FatherName, Name MotherName, string JobTitle, - PlaceOfWorkModel PlaceOfWork, + PlaceOfWork PlaceOfWork, bool IsNonResident) : RegisterRequest(Email, Password); } diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICitiesRepository.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICitiesRepository.cs deleted file mode 100644 index ef332d4..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICitiesRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using ApplicationLayer.InfrastructureServicesInterfaces; -using Domains.LocationDomain; - -namespace ApplicationLayer.Services.Locations.NeededServices; - -public interface ICitiesRepository : IGenericRepository -{ - /// Get by name and country identifier - Task GetByNameAsync(Guid requestId, string existingCity, CancellationToken cancellationToken); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICountriesRepository.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICountriesRepository.cs deleted file mode 100644 index c3bd0ea..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/NeededServices/ICountriesRepository.cs +++ /dev/null @@ -1,13 +0,0 @@ -using ApplicationLayer.InfrastructureServicesInterfaces; -using Domains.LocationDomain; - -namespace ApplicationLayer.Services.Locations.NeededServices; - -public interface ICountriesRepository : IGenericRepository -{ - /// Gets country by name - Task FindByNameAsync(string countryName, CancellationToken cancellationToken); - - /// Gets country by identifier - Task FindByIdAsync(Guid id, CancellationToken cancellationToken); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CityCanNotBeDeletedException.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CityCanNotBeDeletedException.cs deleted file mode 100644 index 47a294b..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CityCanNotBeDeletedException.cs +++ /dev/null @@ -1,7 +0,0 @@ -using ApplicationLayer.Services.GeneralExceptions; - -namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions -{ - public class CityCanNotBeDeletedException(string cityName) - : EntityUsedInDatabaseException($"{cityName} can not be deleted because some applicants live or work in it"); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryAlreadyExists.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryAlreadyExists.cs deleted file mode 100644 index 68a9ad4..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryAlreadyExists.cs +++ /dev/null @@ -1,6 +0,0 @@ -using ApplicationLayer.GeneralExceptions; - -namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions -{ - public class CountryAlreadyExists(string countryName) : AlreadyExistsException($"{countryName} already exists."); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryNotFoundException.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryNotFoundException.cs deleted file mode 100644 index aae4508..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/CountryNotFoundException.cs +++ /dev/null @@ -1,7 +0,0 @@ -using ApplicationLayer.Services.GeneralExceptions; -using Domains.LocationDomain; - -namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions -{ - public class CountryNotFoundException(string countryName) : EntityNotFoundException($"Country {countryName} is not supported."); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/MultipleIdenticalCitiesInCountryException.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/MultipleIdenticalCitiesInCountryException.cs deleted file mode 100644 index 4a901da..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/Exceptions/MultipleIdenticalCitiesInCountryException.cs +++ /dev/null @@ -1,6 +0,0 @@ -using ApplicationLayer.GeneralExceptions; - -namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions -{ - public class MultipleIdenticalCitiesInCountryException() : ApiException("There are multiple cities with one name in the country."); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/ILocationRequestsHandler.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/ILocationRequestsHandler.cs deleted file mode 100644 index eab5625..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/ILocationRequestsHandler.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ApplicationLayer.Services.Locations.Requests; -using Domains.LocationDomain; - -namespace ApplicationLayer.Services.Locations.RequestHandlers -{ - /// Handles location requests - public interface ILocationRequestsHandler - { - /// Handle get request - /// List of available countries - Task> HandleGetRequestAsync(CancellationToken cancellationToken); - - /// Handles - Task AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken); - - /// Handles - Task UpdateCountryAsync(UpdateCountryRequest request, CancellationToken cancellationToken); - } -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/LocationRequestsHandler.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/LocationRequestsHandler.cs deleted file mode 100644 index be07a39..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/RequestHandlers/LocationRequestsHandler.cs +++ /dev/null @@ -1,91 +0,0 @@ -using ApplicationLayer.InfrastructureServicesInterfaces; -using ApplicationLayer.Services.Applicants.NeededServices; -using ApplicationLayer.Services.Locations.NeededServices; -using ApplicationLayer.Services.Locations.RequestHandlers.Exceptions; -using ApplicationLayer.Services.Locations.Requests; -using Domains.LocationDomain; - -namespace ApplicationLayer.Services.Locations.RequestHandlers -{ - /// - public class LocationRequestsHandler( - ICountriesRepository countries, - ICitiesRepository cities, - IApplicantsRepository applicants, - IUnitOfWork unitOfWork) : ILocationRequestsHandler - { - async Task> ILocationRequestsHandler.HandleGetRequestAsync(CancellationToken cancellationToken) - { - return await countries.GetAllAsync(cancellationToken); - } - - async Task ILocationRequestsHandler.AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken) - { - if (await countries.FindByNameAsync(request.CountryName, cancellationToken) is not null) - { - throw new CountryAlreadyExists(request.CountryName); - } - - if (request.Cities.Distinct().Count() < request.Cities.Length) - { - throw new MultipleIdenticalCitiesInCountryException(); - } - - //todo mapper - var country = new Country - { - Name = request.CountryName, - IsSchengen = request.IsSchengen, - Cities = request.Cities.Select(cityName => new City { Name = cityName }).ToList() - }; - - await countries.AddAsync(country, cancellationToken); - - await unitOfWork.SaveAsync(cancellationToken); - } - - async Task ILocationRequestsHandler.UpdateCountryAsync(UpdateCountryRequest request, CancellationToken cancellationToken) - { - if (await countries.FindByNameAsync(request.CountryName, cancellationToken) is not null) - { - throw new CountryAlreadyExists(request.CountryName); - } - - var country = await countries.FindByIdAsync(request.Id, cancellationToken); - if (country is null) - { - throw new CountryNotFoundException(request.CountryName); - } - - var existingCities = country.Cities; - var citiesToAdd = request.Cities.Except(existingCities.Select(c => c.Name)).ToList(); - var citiesToRemove = existingCities.Where(c => !request.Cities.Contains(c.Name)); - var applicantsList = await applicants.GetAllAsync(cancellationToken); - - //todo mapper - foreach (var city in citiesToRemove) - { - if (applicantsList.All(a => a.CityOfBirth.Id != city.Id && a.PlaceOfWork.Address.City.Id != city.Id)) - { - cities.Remove(city); - } - else - { - throw new CityCanNotBeDeletedException(city.Name); - } - } - - foreach (var city in citiesToAdd) - { - await cities.AddAsync(new City { Name = city, Country = country }, cancellationToken); - } - - country.Name = request.CountryName; - country.IsSchengen = request.IsSchengen; - - await countries.UpdateAsync(country, cancellationToken); - - await unitOfWork.SaveAsync(cancellationToken); - } - } -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/AddCountryRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/AddCountryRequest.cs deleted file mode 100644 index cf6cb45..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/AddCountryRequest.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace ApplicationLayer.Services.Locations.Requests -{ - public record AddCountryRequest(string CountryName, bool IsSchengen, string[] Cities); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/UpdateCountryRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/UpdateCountryRequest.cs deleted file mode 100644 index 8aa5dcc..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/Locations/Requests/UpdateCountryRequest.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace ApplicationLayer.Services.Locations.Requests -{ - public record UpdateCountryRequest(Guid Id, string CountryName, bool IsSchengen, string[] Cities); -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Handlers/VisaApplicationRequestsHandler.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Handlers/VisaApplicationRequestsHandler.cs index 77fb187..5638207 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Handlers/VisaApplicationRequestsHandler.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Handlers/VisaApplicationRequestsHandler.cs @@ -1,6 +1,5 @@ using ApplicationLayer.InfrastructureServicesInterfaces; using ApplicationLayer.Services.Applicants.NeededServices; -using ApplicationLayer.Services.Locations.NeededServices; using ApplicationLayer.Services.VisaApplications.Models; using ApplicationLayer.Services.VisaApplications.NeededServices; using ApplicationLayer.Services.VisaApplications.Requests; @@ -12,7 +11,6 @@ namespace ApplicationLayer.Services.VisaApplications.Handlers; public class VisaApplicationRequestsHandler( IVisaApplicationsRepository applications, IApplicantsRepository applicants, - ICountriesRepository countries, IUnitOfWork unitOfWork) : IVisaApplicationRequestsHandler { public async Task> Get(CancellationToken cancellationToken) => await applications.GetAllAsync(cancellationToken); @@ -24,7 +22,7 @@ public class VisaApplicationRequestsHandler( var visaApplications = await applications.GetOfApplicantAsync(applicantId, cancellationToken); return visaApplications.Select(va => new VisaApplicationModelForApplicant { - DestinationCountry = va.DestinationCountry.Name, + DestinationCountry = va.DestinationCountry, ValidDaysRequested = va.ValidDaysRequested, ReentryPermit = va.ReentryPermit, VisaCategory = va.VisaCategory, @@ -33,8 +31,7 @@ public class VisaApplicationRequestsHandler( ForGroup = va.ForGroup, PastVisas = va.PastVisas, RequestDate = va.RequestDate, - PastVisits = va.PastVisits.Select(pv => - new PastVisitModel { DestinationCountry = pv.DestinationCountry.Name, StartDate = pv.StartDate, EndDate = pv.EndDate }).ToList() + PastVisits = va.PastVisits }).ToList(); } @@ -44,18 +41,17 @@ public class VisaApplicationRequestsHandler( var applicant = await applicants.FindByUserIdAsync(userId, cancellationToken); - var pastVisits = request.PastVisits.Select(m => ConvertPastVisitModelToPastVisit(m, cancellationToken).Result).ToList(); var visaApplication = new VisaApplication { - Applicant = applicant, + ApplicantId = applicant.Id, RequestedNumberOfEntries = request.RequestedNumberOfEntries, ValidDaysRequested = request.ValidDaysRequested, ReentryPermit = request.ReentryPermit, VisaCategory = request.VisaCategory, PermissionToDestCountry = request.PermissionToDestCountry, - DestinationCountry = await countries.GetByIdAsync(request.DestinationCountryId, cancellationToken), + DestinationCountry = request.DestinationCountry, PastVisas = request.PastVisas.ToList(), - PastVisits = pastVisits, + PastVisits = request.PastVisits.ToList(), ForGroup = request.IsForGroup, RequestDate = DateTime.Today }; @@ -64,14 +60,4 @@ public class VisaApplicationRequestsHandler( await unitOfWork.SaveAsync(cancellationToken); } - - private async Task ConvertPastVisitModelToPastVisit(PastVisitModelForRequest modelForRequest, CancellationToken cancellationToken) - { - return new PastVisit - { - DestinationCountry = await countries.GetByIdAsync(modelForRequest.DestinationCountryId, cancellationToken), - StartDate = modelForRequest.StartDate, - EndDate = modelForRequest.EndDate - }; - } } diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModel.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModel.cs deleted file mode 100644 index c492e57..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Domains.VisaApplicationDomain; - -namespace ApplicationLayer.Services.VisaApplications.Models -{ - /// Model of with only name of the destination country - public class PastVisitModel - { - /// - public DateTime StartDate { get; set; } - - /// - public DateTime EndDate { get; set; } - - /// - public string DestinationCountry { get; set; } = null!; - } -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModelForRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModelForRequest.cs deleted file mode 100644 index 81b3c8f..0000000 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/PastVisitModelForRequest.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Domains.VisaApplicationDomain; - -namespace ApplicationLayer.Services.VisaApplications.Models -{ - /// Model of with only identifier of country - public class PastVisitModelForRequest - { - /// First day of - public DateTime StartDate { get; set; } - - /// Last day of - public DateTime EndDate { get; set; } - - /// Identifier of destination country of - public Guid DestinationCountryId { get; set; } - } -} diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs index c347147..5703882 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs @@ -18,7 +18,7 @@ namespace ApplicationLayer.Services.VisaApplications.Models /// public PermissionToDestCountry? PermissionToDestCountry { get; set; } - public List PastVisits { get; set; } = null!; + public List PastVisits { get; set; } = null!; /// public VisaCategory VisaCategory { get; set; } diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/VisaApplicationCreateRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/VisaApplicationCreateRequest.cs index d14f53e..58f8c1d 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/VisaApplicationCreateRequest.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/VisaApplicationCreateRequest.cs @@ -1,17 +1,16 @@ -using ApplicationLayer.Services.VisaApplications.Models; -using Domains.VisaApplicationDomain; +using Domains.VisaApplicationDomain; namespace ApplicationLayer.Services.VisaApplications.Requests; /// Model of visa request from user public record VisaApplicationCreateRequest( ReentryPermit ReentryPermit, - Guid DestinationCountryId, + string DestinationCountry, VisaCategory VisaCategory, bool IsForGroup, RequestedNumberOfEntries RequestedNumberOfEntries, int ValidDaysRequested, PastVisa[] PastVisas, PermissionToDestCountry? PermissionToDestCountry, - PastVisitModelForRequest[] PastVisits + PastVisit[] PastVisits ); diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Address.cs b/SchengenVisaApi/Domains/ApplicantDomain/Address.cs index 3455840..394bc92 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Address.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Address.cs @@ -1,20 +1,18 @@ -using Domains.LocationDomain; - -namespace Domains.ApplicantDomain; +namespace Domains.ApplicantDomain; /// Model of address /// Owned public class Address { /// Country part of address - public Country Country { get; set; } = null!; + public string Country { get; set; } = null!; /// City part of address - public City City { get; set; } = null!; + 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!; -} \ No newline at end of file +} diff --git a/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs b/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs index 91404c2..fba6984 100644 --- a/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs +++ b/SchengenVisaApi/Domains/ApplicantDomain/Applicant.cs @@ -1,6 +1,4 @@ -using Domains.LocationDomain; - -namespace Domains.ApplicantDomain; +namespace Domains.ApplicantDomain; /// Model of an applicant public class Applicant : IEntity @@ -19,11 +17,11 @@ public class Applicant : IEntity /// Date of birth of the public DateTime BirthDate { get; set; } - /// of birth of the - public Country CountryOfBirth { get; set; } = null!; + /// Country of birth of the + public string CountryOfBirth { get; set; } = null!; - /// of birth of the - public City CityOfBirth { get; set; } = null!; + /// City of birth of the + public string CityOfBirth { get; set; } = null!; /// Citizenship of public string Citizenship { get; set; } = null!; diff --git a/SchengenVisaApi/Domains/LocationDomain/City.cs b/SchengenVisaApi/Domains/LocationDomain/City.cs deleted file mode 100644 index 1a646f6..0000000 --- a/SchengenVisaApi/Domains/LocationDomain/City.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text.Json.Serialization; - -namespace Domains.LocationDomain; - -/// Model of a city -public class City : IEntity -{ - /// Unique identifier of the - public Guid Id { get; private set; } = Guid.NewGuid(); - - /// Name of the city - public string Name { get; set; } = null!; - - /// in which the city is located - [JsonIgnore] - public Country Country { get; set; } = null!; -} diff --git a/SchengenVisaApi/Domains/LocationDomain/Country.cs b/SchengenVisaApi/Domains/LocationDomain/Country.cs deleted file mode 100644 index db0a495..0000000 --- a/SchengenVisaApi/Domains/LocationDomain/Country.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Domains.LocationDomain; - -/// Model of a country -public class Country : IEntity -{ - /// Unique identifier of the - public Guid Id { get; private set; } = Guid.NewGuid(); - - /// Name of the country - public string Name { get; set; } = null!; - - /// Located in Schengen area - public bool IsSchengen { get; set; } - - /// List of that country have - public List Cities { get; set; } = null!; -} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs index cdc285e..67b7dab 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/PastVisit.cs @@ -1,5 +1,4 @@ using Domains.ApplicantDomain; -using Domains.LocationDomain; namespace Domains.VisaApplicationDomain; @@ -14,5 +13,5 @@ public class PastVisit public DateTime EndDate { get; set; } /// Destination country of - public Country DestinationCountry { get; set; } = null!; + public string DestinationCountry { get; set; } = null!; } diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs index ba7596b..3fbde18 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/VisaApplication.cs @@ -1,5 +1,4 @@ using Domains.ApplicantDomain; -using Domains.LocationDomain; namespace Domains.VisaApplicationDomain; @@ -12,15 +11,12 @@ public class VisaApplication : IEntity /// Identifier of the public Guid ApplicantId { get; set; } - /// Applicant of - public Applicant Applicant { get; set; } = null!; - /// /// always null if is not a non-resident public ReentryPermit? ReentryPermit { get; set; } - /// that wants to visit - public Country DestinationCountry { get; set; } = null!; + /// Country that wants to visit + public string DestinationCountry { get; set; } = null!; /// /// List of that applicant had before @@ -47,4 +43,4 @@ public class VisaApplication : IEntity /// Valid days requested public int ValidDaysRequested { get; set; } -} \ 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 f250e3d..f212c86 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/AddressConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/AddressConfiguration.cs @@ -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 where T : class, IEntity { public static void Configure(OwnedNavigationBuilder 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); } } diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs index 2c2ed76..dd8469f 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/ApplicantConfiguration.cs @@ -9,21 +9,27 @@ public class ApplicantConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { - entity.OwnsOne(p => p.Name, NameConfiguration.Configure); - entity.OwnsOne(p => p.FatherName, NameConfiguration.Configure); - entity.OwnsOne(p => p.MotherName, NameConfiguration.Configure); - entity.OwnsOne(p => p.Passport, PassportConfiguration.Configure); + entity.OwnsOne(a => a.Name, NameConfiguration.Configure); + entity.OwnsOne(a => a.FatherName, NameConfiguration.Configure); + entity.OwnsOne(a => a.MotherName, NameConfiguration.Configure); + entity.OwnsOne(a => a.Passport, PassportConfiguration.Configure); - entity.HasOne(a => a.CityOfBirth).WithMany().OnDelete(DeleteBehavior.Restrict); - entity.HasOne(a => a.CountryOfBirth).WithMany().OnDelete(DeleteBehavior.Restrict); entity.HasOne().WithOne().HasForeignKey(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); } } diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs index 2dd6923..8d683cc 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/NameConfiguration.cs @@ -10,14 +10,14 @@ public static class NameConfiguration 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); } } diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs index faa35f1..9a445ff 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PassportConfiguration.cs @@ -10,10 +10,10 @@ public static class PassportConfiguration 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); } } diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs index f339d9b..e4eda3f 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Configuration/PlaceOfWorkConfiguration.cs @@ -12,10 +12,10 @@ public class PlaceOfWorkConfiguration : IEntityTypeConfiguration entity.Property(p => p.Name) .IsUnicode(false) - .HasMaxLength(200); + .HasMaxLength(ConfigurationConstraints.PlaceOfWorkNameLength); entity.Property(p => p.PhoneNum) .IsUnicode(false) - .HasMaxLength(20); + .HasMaxLength(ConfigurationConstraints.PhoneNumberLength); } } diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs index 750d13b..a5a9ef5 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/ApplicantsRepository.cs @@ -15,8 +15,6 @@ public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter w protected override IQueryable LoadDomain() { return base.LoadDomain() - .Include(a => a.CountryOfBirth) - .Include(a => a.CityOfBirth) .Include(a => a.PlaceOfWork); } diff --git a/SchengenVisaApi/Infrastructure/Database/ConfigurationConstraints.cs b/SchengenVisaApi/Infrastructure/Database/ConfigurationConstraints.cs new file mode 100644 index 0000000..5f5816b --- /dev/null +++ b/SchengenVisaApi/Infrastructure/Database/ConfigurationConstraints.cs @@ -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; + } +} diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs deleted file mode 100644 index a9b3c4b..0000000 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CityConfiguration.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Domains.LocationDomain; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace Infrastructure.Database.Locations.Configuration; - -public class CityConfiguration : IEntityTypeConfiguration -{ - public void Configure(EntityTypeBuilder entity) - { - 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 deleted file mode 100644 index 6ef5bf2..0000000 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Configuration/CountryConfiguration.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Domains.LocationDomain; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace Infrastructure.Database.Locations.Configuration; - -public class CountryConfiguration : IEntityTypeConfiguration -{ - public void Configure(EntityTypeBuilder entity) - { - entity.Property(c => c.Name) - .IsUnicode(false) - .HasMaxLength(70); - - entity.HasIndex(c => c.Name).IsUnique(); - } -} diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs deleted file mode 100644 index 13104b2..0000000 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Cities/CitiesRepository.cs +++ /dev/null @@ -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(reader, writer), ICitiesRepository -{ - protected override IQueryable LoadDomain() - { - return base.LoadDomain().Include(c => c.Country); - } - - Task ICitiesRepository.GetByNameAsync(Guid countryId, string cityName, CancellationToken cancellationToken) - => LoadDomain().SingleOrDefaultAsync(c => c.Country.Id == countryId && c.Name == cityName, cancellationToken); -} diff --git a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs b/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs deleted file mode 100644 index 2ef1ddb..0000000 --- a/SchengenVisaApi/Infrastructure/Database/Locations/Repositories/Countries/CountriesRepository.cs +++ /dev/null @@ -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(reader, writer), ICountriesRepository -{ - protected override IQueryable LoadDomain() - { - return base.LoadDomain().Include(c => c.Cities); - } - - async Task ICountriesRepository.FindByNameAsync(string countryName, CancellationToken cancellationToken) - { - var result = await LoadDomain().SingleOrDefaultAsync(c => c.Name == countryName, cancellationToken); - return result; - } - - async Task ICountriesRepository.FindByIdAsync(Guid id, CancellationToken cancellationToken) - { - var result = await LoadDomain().SingleOrDefaultAsync(c => c.Id == id, cancellationToken); - return result; - } -} diff --git a/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs index 84e47c7..727ae64 100644 --- a/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs @@ -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); } } } diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs index 4741ddc..9ec5263 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisaConfiguration.cs @@ -10,6 +10,6 @@ public static class PastVisaConfiguration where T : class, IEntity { entity.Property(p => p.Name) .IsUnicode(false) - .HasMaxLength(70); + .HasMaxLength(ConfigurationConstraints.VisaNameLength); } } diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs index 9956633..0f8f574 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs @@ -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 entity) { - entity.HasOne(p => p.DestinationCountry).WithMany().OnDelete(DeleteBehavior.Restrict); + entity.Property(pv => pv.DestinationCountry) + .IsUnicode(false) + .HasMaxLength(ConfigurationConstraints.CountryNameLength); } } } diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs index 11df404..793d286 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PermissionToDestCountryConfiguration.cs @@ -10,6 +10,6 @@ public static class PermissionToDestCountryConfiguration where T : class, IEn { entity.Property(p => p.Issuer) .IsUnicode(false) - .HasMaxLength(200); + .HasMaxLength(ConfigurationConstraints.IssuerNameLength); } } diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs index 7bc1ba6..fa972be 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/ReentryPermitConfiguration.cs @@ -10,6 +10,6 @@ public static class ReentryPermitConfiguration where T : class, IEntity { entity.Property(p => p.Number) .IsUnicode(false) - .HasMaxLength(25); + .HasMaxLength(ConfigurationConstraints.ReentryPermitNumberLength); } } diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs index f85b5c8..39a69d6 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/VisaApplicationConfiguration.cs @@ -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 va.ReentryPermit, ReentryPermitConfiguration.Configure); entity.OwnsOne(va => va.PermissionToDestCountry, PermissionToDestCountryConfiguration.Configure); entity.OwnsMany(va => va.PastVisits, PastVisitConfiguration.Configure); - entity.OwnsMany(va => va.PastVisas); + entity.OwnsMany(va => va.PastVisas, PastVisaConfiguration.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() .WithMany() .HasForeignKey(va => va.ApplicantId) .IsRequired(); diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs index 4878c99..cd20971 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/VisaApplicationsRepository.cs @@ -10,7 +10,6 @@ public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWr { protected override IQueryable LoadDomain() => base.LoadDomain() - .Include(va => va.DestinationCountry) .Include(va => va.PastVisas) .Include(va => va.PastVisits); diff --git a/SchengenVisaApi/Infrastructure/DependencyInjection.cs b/SchengenVisaApi/Infrastructure/DependencyInjection.cs index 06daa13..a05b816 100644 --- a/SchengenVisaApi/Infrastructure/DependencyInjection.cs +++ b/SchengenVisaApi/Infrastructure/DependencyInjection.cs @@ -1,13 +1,10 @@ using ApplicationLayer.InfrastructureServicesInterfaces; using ApplicationLayer.Services.Applicants.NeededServices; using ApplicationLayer.Services.AuthServices.NeededServices; -using ApplicationLayer.Services.Locations.NeededServices; using ApplicationLayer.Services.VisaApplications.NeededServices; using Infrastructure.Common; using Infrastructure.Database.Applicants.Repositories; using Infrastructure.Database.Generic; -using Infrastructure.Database.Locations.Repositories.Cities; -using Infrastructure.Database.Locations.Repositories.Countries; using Infrastructure.Database.Users.Repositories; using Infrastructure.Database.VisaApplications.Repositories; using Microsoft.EntityFrameworkCore; @@ -36,8 +33,6 @@ public static class DependencyInjection services.AddScoped(); services.AddScoped(); - services.AddScoped(); - services.AddScoped(); services.AddScoped(); services.AddSingleton(); diff --git a/SchengenVisaApi/SchengenVisaApi/Controllers/LocationsController.cs b/SchengenVisaApi/SchengenVisaApi/Controllers/LocationsController.cs deleted file mode 100644 index 01d499f..0000000 --- a/SchengenVisaApi/SchengenVisaApi/Controllers/LocationsController.cs +++ /dev/null @@ -1,53 +0,0 @@ -using ApplicationLayer.Services.Locations.RequestHandlers; -using ApplicationLayer.Services.Locations.Requests; -using Domains.LocationDomain; -using Domains.Users; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using SchengenVisaApi.Common; - -namespace SchengenVisaApi.Controllers -{ - /// Controller for - [ApiController] - [Route("locations")] - public class LocationsController(ILocationRequestsHandler requestsHandler) : ControllerBase - { - /// Return countries with cities from DB - [HttpGet] - [ProducesResponseType>(StatusCodes.Status200OK)] - public async Task GetAvailableLocations(CancellationToken cancellationToken) - { - return Ok(await requestsHandler.HandleGetRequestAsync(cancellationToken)); - } - - /// Adds country with cities to DB - /// Accessible only for - [HttpPost] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [Route("country")] - [Authorize(policy: PolicyConstants.AdminPolicy)] - public async Task AddCountry(AddCountryRequest request, CancellationToken cancellationToken) - { - await requestsHandler.AddCountryAsync(request, cancellationToken); - return Ok(); - } - - /// Updates country with cities in DB - [HttpPut] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [Route("country")] - [Authorize(policy: PolicyConstants.AdminPolicy)] - public async Task UpdateCountry(UpdateCountryRequest request, CancellationToken cancellationToken) - { - await requestsHandler.UpdateCountryAsync(request, cancellationToken); - return Ok(); - } - } -} diff --git a/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs b/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs index 68fdb7a..9c59b6d 100644 --- a/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs +++ b/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs @@ -1,19 +1,18 @@ using ApplicationLayer.Services.AuthServices.LoginService; using ApplicationLayer.Services.AuthServices.RegisterService; using ApplicationLayer.Services.AuthServices.Requests; -using Domains.Users; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SchengenVisaApi.Common; namespace SchengenVisaApi.Controllers { - /// Controller for + /// Controller for user-auth and registration [ApiController] [Route("auth")] public class UsersController(IRegisterService registerService, ILoginService loginService) : ControllerBase { - /// Adds applicant with user account to DB + /// Adds applicant with user account to DB [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status409Conflict)] @@ -24,8 +23,8 @@ namespace SchengenVisaApi.Controllers return Ok(); } - /// Adds approving authority with user account to DB - /// Accessible only for + /// Adds approving authority with user account to DB + /// Accessible only for admins [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status409Conflict)] @@ -39,7 +38,7 @@ namespace SchengenVisaApi.Controllers return Ok(); } - /// Returns JWT-token for authentication + /// Returns JWT-token for authentication [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/SchengenVisaApi/SchengenVisaApi/Controllers/VisaApplicationController.cs b/SchengenVisaApi/SchengenVisaApi/Controllers/VisaApplicationController.cs index ec8c627..d284511 100644 --- a/SchengenVisaApi/SchengenVisaApi/Controllers/VisaApplicationController.cs +++ b/SchengenVisaApi/SchengenVisaApi/Controllers/VisaApplicationController.cs @@ -2,7 +2,6 @@ using System.Security.Claims; using ApplicationLayer.Services.VisaApplications.Handlers; using ApplicationLayer.Services.VisaApplications.Models; using ApplicationLayer.Services.VisaApplications.Requests; -using Domains.Users; using Domains.VisaApplicationDomain; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -10,14 +9,14 @@ using SchengenVisaApi.Common; namespace SchengenVisaApi.Controllers; -/// Controller for +/// Controller for [ApiController] [Route("[controller]")] public class VisaApplicationController(IVisaApplicationRequestsHandler visaApplicationRequestsHandler) : ControllerBase { //todo should return only pending applications - /// Returns all from DB - /// Accessible only for + /// Returns all applications from DB + /// Accessible only for approving authorities [HttpGet] [ProducesResponseType>(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -29,8 +28,8 @@ public class VisaApplicationController(IVisaApplicationRequestsHandler visaAppli return Ok(result); } - /// Returns all of one applicant - /// Returns applications for authorized applicant + /// Returns all applications of one applicant + /// Returns applications of authorized applicant [HttpGet] [ProducesResponseType>(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] @@ -45,8 +44,8 @@ public class VisaApplicationController(IVisaApplicationRequestsHandler visaAppli return Ok(result); } - /// Adds new to DB - /// Adds application for authorized applicant + /// Adds new application to DB + /// Adds application for authorized applicant [HttpPost] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs b/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs index 09b11d0..3bd38a6 100644 --- a/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs +++ b/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs @@ -1,7 +1,6 @@ using ApplicationLayer.GeneralExceptions; using ApplicationLayer.Services.AuthServices.LoginService.Exceptions; using ApplicationLayer.Services.GeneralExceptions; -using ApplicationLayer.Services.Locations.RequestHandlers.Exceptions; using Domains; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; @@ -37,16 +36,6 @@ namespace SchengenVisaApi.ExceptionFilters problemDetails.Title = "Already exists"; problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.8"; break; - case MultipleIdenticalCitiesInCountryException: - problemDetails.Status = StatusCodes.Status400BadRequest; - problemDetails.Title = "Can not add cities with one name to one country"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"; - break; - case EntityUsedInDatabaseException: - problemDetails.Status = StatusCodes.Status409Conflict; - problemDetails.Title = "entity is used by someone"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.8"; - break; default: problemDetails.Status = StatusCodes.Status400BadRequest; problemDetails.Title = "Bad request";