Removed location entities, fixed configurations and controllers' comments
This commit is contained in:
@@ -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<IVisaApplicationRequestsHandler, VisaApplicationRequestsHandler>();
|
||||
services.AddScoped<ILocationRequestsHandler, LocationRequestsHandler>();
|
||||
|
||||
services.AddScoped<IRegisterService, RegisterService>();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using Domains.LocationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.Locations.NeededServices;
|
||||
|
||||
public interface ICitiesRepository : IGenericRepository<City>
|
||||
{
|
||||
/// Get <see cref="City"/> by name and country identifier
|
||||
Task<City?> GetByNameAsync(Guid requestId, string existingCity, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using Domains.LocationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.Locations.NeededServices;
|
||||
|
||||
public interface ICountriesRepository : IGenericRepository<Country>
|
||||
{
|
||||
/// Gets country by name
|
||||
Task<Country?> FindByNameAsync(string countryName, CancellationToken cancellationToken);
|
||||
|
||||
/// Gets country by identifier
|
||||
Task<Country?> FindByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
using ApplicationLayer.GeneralExceptions;
|
||||
|
||||
namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions
|
||||
{
|
||||
public class CountryAlreadyExists(string countryName) : AlreadyExistsException($"{countryName} already exists.");
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
using ApplicationLayer.Services.GeneralExceptions;
|
||||
using Domains.LocationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions
|
||||
{
|
||||
public class CountryNotFoundException(string countryName) : EntityNotFoundException<Country>($"Country {countryName} is not supported.");
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
@@ -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
|
||||
/// <returns>List of available countries</returns>
|
||||
Task<List<Country>> HandleGetRequestAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// Handles <see cref="AddCountryRequest"/>
|
||||
Task AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken);
|
||||
|
||||
/// Handles <see cref="UpdateCountryRequest"/>
|
||||
Task UpdateCountryAsync(UpdateCountryRequest request, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <inheritdoc cref="ILocationRequestsHandler"/>
|
||||
public class LocationRequestsHandler(
|
||||
ICountriesRepository countries,
|
||||
ICitiesRepository cities,
|
||||
IApplicantsRepository applicants,
|
||||
IUnitOfWork unitOfWork) : ILocationRequestsHandler
|
||||
{
|
||||
async Task<List<Country>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace ApplicationLayer.Services.Locations.Requests
|
||||
{
|
||||
public record AddCountryRequest(string CountryName, bool IsSchengen, string[] Cities);
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace ApplicationLayer.Services.Locations.Requests
|
||||
{
|
||||
public record UpdateCountryRequest(Guid Id, string CountryName, bool IsSchengen, string[] Cities);
|
||||
}
|
||||
@@ -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<List<VisaApplication>> 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<PastVisit> ConvertPastVisitModelToPastVisit(PastVisitModelForRequest modelForRequest, CancellationToken cancellationToken)
|
||||
{
|
||||
return new PastVisit
|
||||
{
|
||||
DestinationCountry = await countries.GetByIdAsync(modelForRequest.DestinationCountryId, cancellationToken),
|
||||
StartDate = modelForRequest.StartDate,
|
||||
EndDate = modelForRequest.EndDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
{
|
||||
/// Model of <see cref="PastVisit"/> with only name of the destination country
|
||||
public class PastVisitModel
|
||||
{
|
||||
/// <inheritdoc cref="PastVisit.StartDate"/>
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
/// <inheritdoc cref="PastVisit.EndDate"/>
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
/// <inheritdoc cref="PastVisit.DestinationCountry"/>
|
||||
public string DestinationCountry { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
{
|
||||
/// Model of <see cref="PastVisit"/> with only identifier of country
|
||||
public class PastVisitModelForRequest
|
||||
{
|
||||
/// First day of <see cref="PastVisitModelForRequest"/>
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
/// Last day of <see cref="PastVisitModelForRequest"/>
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
/// Identifier of destination country of <see cref="PastVisitModelForRequest"/>
|
||||
public Guid DestinationCountryId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
/// <inheritdoc cref="VisaApplication.PermissionToDestCountry"/>
|
||||
public PermissionToDestCountry? PermissionToDestCountry { get; set; }
|
||||
|
||||
public List<PastVisitModel> PastVisits { get; set; } = null!;
|
||||
public List<PastVisit> PastVisits { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="VisaApplication.VisaCategory"/>
|
||||
public VisaCategory VisaCategory { get; set; }
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user