Refactored and fixed errors
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using ApplicationLayer.Common;
|
||||
using ApplicationLayer.GeneralNeededServices;
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace ApplicationLayer.Applicants;
|
||||
namespace ApplicationLayer.Applicants.NeededServices;
|
||||
|
||||
/// Repository pattern for <see cref="Applicant"/>
|
||||
public interface IApplicantsRepository : IGenericRepository<Applicant> { }
|
||||
public interface IApplicantsRepository : IGenericRepository<Applicant> { }
|
||||
@@ -10,4 +10,8 @@
|
||||
<ProjectReference Include="..\Domains\Domains.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0-preview.7.24405.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
16
SchengenVisaApi/ApplicationLayer/DependencyInjection.cs
Normal file
16
SchengenVisaApi/ApplicationLayer/DependencyInjection.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using ApplicationLayer.VisaApplications.Handlers;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ApplicationLayer;
|
||||
|
||||
/// Provides methods to add services to DI-container
|
||||
public static class DependencyInjection
|
||||
{
|
||||
/// Add services for Application layer
|
||||
public static IServiceCollection AddApplicationLayer(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IVisaApplicationsRequestHandler, VisaApplicationRequestsHandler>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Domains;
|
||||
|
||||
namespace ApplicationLayer.Common;
|
||||
namespace ApplicationLayer.GeneralNeededServices;
|
||||
|
||||
/// <summary>
|
||||
/// Generic repository pattern
|
||||
@@ -15,7 +15,7 @@ public interface IGenericRepository<T> where T : class, IEntity
|
||||
/// Get one entity with specific id
|
||||
/// <param name="id">Identifier of entity</param>
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
Task<T> GetOneAsync(Guid id, CancellationToken cancellationToken);
|
||||
Task<T> GetByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// Add entity to storage
|
||||
/// <param name="entity">Entity to add</param>
|
||||
@@ -1,14 +0,0 @@
|
||||
using ApplicationLayer.Common;
|
||||
using Domains.LocationDomain;
|
||||
|
||||
namespace ApplicationLayer.Locations;
|
||||
|
||||
public interface ICitiesRepository : IGenericRepository<City>
|
||||
{
|
||||
/// Find the city by its name and its country name
|
||||
/// <param name="name">City's name</param>
|
||||
/// <param name="countryName">City's country name</param>
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
/// <returns>City with specific name and country</returns>
|
||||
Task<City> GetByNameAsync(string name, string countryName, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using ApplicationLayer.GeneralNeededServices;
|
||||
using Domains.LocationDomain;
|
||||
|
||||
namespace ApplicationLayer.Locations.NeededServices;
|
||||
|
||||
public interface ICitiesRepository : IGenericRepository<City> { }
|
||||
@@ -1,6 +1,6 @@
|
||||
using ApplicationLayer.Common;
|
||||
using ApplicationLayer.GeneralNeededServices;
|
||||
using Domains.LocationDomain;
|
||||
|
||||
namespace ApplicationLayer.Locations;
|
||||
namespace ApplicationLayer.Locations.NeededServices;
|
||||
|
||||
public interface ICountriesRepository : IGenericRepository<Country> { }
|
||||
@@ -0,0 +1,11 @@
|
||||
using ApplicationLayer.VisaApplications.Requests;
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.VisaApplications.Handlers;
|
||||
|
||||
public interface IVisaApplicationsRequestHandler
|
||||
{
|
||||
Task<List<VisaApplication>> Get(CancellationToken cancellationToken);
|
||||
|
||||
void HandleCreateRequest(VisaApplicationCreateRequest request, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -1,14 +1,78 @@
|
||||
using ApplicationLayer.Applicants;
|
||||
using ApplicationLayer.Locations.NeededServices;
|
||||
using ApplicationLayer.VisaApplications.Models;
|
||||
using ApplicationLayer.VisaApplications.NeededServices;
|
||||
using ApplicationLayer.VisaApplications.Requests;
|
||||
using Domains.ApplicantDomain;
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.VisaApplications.Handlers
|
||||
namespace ApplicationLayer.VisaApplications.Handlers;
|
||||
|
||||
/// Handles visa requests
|
||||
public class VisaApplicationRequestsHandler(
|
||||
IVisaApplicationsRepository applications,
|
||||
ICitiesRepository cities,
|
||||
ICountriesRepository countries) : IVisaApplicationsRequestHandler
|
||||
{
|
||||
/// Handles visa requests
|
||||
public class VisaApplicationRequestsHandler(IApplicantsRepository)
|
||||
{
|
||||
public void HandleCreateRequest(CreateVisaApplicationRequest request)
|
||||
{
|
||||
public async Task<List<VisaApplication>> Get(CancellationToken cancellationToken) => await applications.GetAllAsync(cancellationToken);
|
||||
|
||||
}
|
||||
public async void HandleCreateRequest(VisaApplicationCreateRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
//TODO mapper
|
||||
var cityOfBirth = await cities.GetByIdAsync(request.BirthCityId, cancellationToken);
|
||||
var cityOfWork = await cities.GetByIdAsync(request.PlaceOfWork.Address.CityId, cancellationToken);
|
||||
|
||||
var addressOfWork = new Address
|
||||
{
|
||||
City = cityOfWork,
|
||||
Country = cityOfWork.Country,
|
||||
Building = request.PlaceOfWork.Address.Building,
|
||||
Street = request.PlaceOfWork.Address.Street
|
||||
};
|
||||
|
||||
var applicant = new Applicant
|
||||
{
|
||||
MaritalStatus = request.MaritalStatus,
|
||||
Name = request.FullName,
|
||||
Passport = request.Passport,
|
||||
Gender = request.Gender,
|
||||
Citizenship = request.CitizenShip,
|
||||
BirthDate = request.BirthDate,
|
||||
FatherName = request.FatherName,
|
||||
JobTitle = request.JobTitle,
|
||||
MotherName = request.MotherName,
|
||||
CitizenshipByBirth = request.CitizenshipByBirth,
|
||||
CityOfBirth = cityOfBirth,
|
||||
CountryOfBirth = cityOfBirth.Country,
|
||||
IsNonResident = request.IsNonResident,
|
||||
PlaceOfWork = new PlaceOfWork { Address = addressOfWork, Name = request.PlaceOfWork.Name, PhoneNum = request.PlaceOfWork.PhoneNum }
|
||||
};
|
||||
|
||||
var pastVisits = request.PastVisits.Select(m => ConvertPastVisitModelToPastVisit(m, cancellationToken).Result).ToList();
|
||||
var visaApplication = new VisaApplication
|
||||
{
|
||||
Applicant = applicant,
|
||||
RequestedNumberOfEntries = request.RequestedNumberOfEntries,
|
||||
ValidDaysRequested = request.ValidDaysRequested,
|
||||
ReentryPermit = request.ReentryPermit,
|
||||
VisaCategory = request.VisaCategory,
|
||||
PermissionToDestCountry = request.PermissionToDestCountry,
|
||||
DestinationCountry = await countries.GetByIdAsync(request.DestinationCountryId, cancellationToken),
|
||||
PastVisas = request.PastVisas.ToList(),
|
||||
PastVisits = pastVisits,
|
||||
ForGroup = request.IsForGroup,
|
||||
RequestDate = DateTime.Today
|
||||
};
|
||||
|
||||
await applications.AddAsync(visaApplication, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<PastVisit> ConvertPastVisitModelToPastVisit(PastVisitModel model, CancellationToken cancellationToken)
|
||||
{
|
||||
return new PastVisit
|
||||
{
|
||||
DestinationCountry = await countries.GetByIdAsync(model.DestinationCountryId, cancellationToken),
|
||||
StartDate = model.StartDate,
|
||||
EndDate = model.EndDate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
using ApplicationLayer.Common;
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.VisaApplications;
|
||||
|
||||
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }
|
||||
@@ -2,11 +2,8 @@
|
||||
|
||||
public class AddressModel
|
||||
{
|
||||
/// Country part of address
|
||||
public string Country { get; set; } = null!;
|
||||
|
||||
/// City part of address
|
||||
public string City { get; set; } = null!;
|
||||
public Guid CityId { get; set; }
|
||||
|
||||
/// Street part of address
|
||||
public string Street { get; set; } = null!;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace ApplicationLayer.VisaApplications.Models
|
||||
{
|
||||
public class PastVisitModel
|
||||
{
|
||||
/// First day of <see cref="PastVisitModel"/>
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
/// Last day of <see cref="PastVisitModel"/>
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
/// Identifier of destination country of <see cref="PastVisitModel"/>
|
||||
public Guid DestinationCountryId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using ApplicationLayer.GeneralNeededServices;
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.VisaApplications.NeededServices;
|
||||
|
||||
public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> { }
|
||||
@@ -5,12 +5,11 @@ using Domains.VisaApplicationDomain;
|
||||
namespace ApplicationLayer.VisaApplications.Requests;
|
||||
|
||||
/// Model of visa request from user
|
||||
public record CreateVisaApplicationRequest(
|
||||
public record VisaApplicationCreateRequest(
|
||||
Name FullName,
|
||||
Passport Passport,
|
||||
DateTime BirthDate,
|
||||
string BirthCity,
|
||||
string BirthCountry,
|
||||
Guid BirthCityId,
|
||||
string CitizenShip,
|
||||
string CitizenshipByBirth,
|
||||
Gender Gender,
|
||||
@@ -21,12 +20,12 @@ public record CreateVisaApplicationRequest(
|
||||
ReentryPermit ReentryPermit,
|
||||
string JobTitle,
|
||||
PlaceOfWorkModel PlaceOfWork,
|
||||
string DestinationCountry,
|
||||
Guid DestinationCountryId,
|
||||
VisaCategory VisaCategory,
|
||||
bool IsForGroup,
|
||||
RequestedNumberOfEntries RequestedNumberOfEntries,
|
||||
int ValidDaysRequested,
|
||||
PastVisa[] PastVisas,
|
||||
PermissionToDestCountry? PermissionToDestCountry,
|
||||
PastVisit[] PastVisits
|
||||
PastVisitModel[] PastVisits
|
||||
);
|
||||
Reference in New Issue
Block a user