Registration and actions for approving authorities

This commit is contained in:
2024-08-19 23:12:01 +03:00
parent 0afe775d85
commit 8c58574b5a
19 changed files with 86 additions and 91 deletions

View File

@@ -14,8 +14,4 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0-preview.7.24405.7" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
using ApplicationLayer.Services.AuthServices.LoginService;
using ApplicationLayer.Services.AuthServices.RegisterService;
using ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests;
using ApplicationLayer.Services.Locations.RequestHandlers.ApplicantRequests;
using ApplicationLayer.Services.Locations.RequestHandlers;
using ApplicationLayer.Services.VisaApplications.Handlers;
using Microsoft.Extensions.DependencyInjection;
@@ -15,7 +14,6 @@ public static class DependencyInjection
{
services.AddScoped<IVisaApplicationRequestsHandler, VisaApplicationRequestsHandler>();
services.AddScoped<ILocationRequestsHandler, LocationRequestsHandler>();
services.AddScoped<IEditLocationsRequestsHandler, EditLocationsRequestsHandler>();
services.AddScoped<IRegisterService, RegisterService>();

View File

@@ -3,5 +3,5 @@ using ApplicationLayer.Services.AuthServices.Requests;
namespace ApplicationLayer.Services.AuthServices.RegisterService.Exceptions
{
public class UserAlreadyExistsException(RegisterApplicantRequest request) : AlreadyExistsException($"User with email '{request.Email}' already exists");
public class UserAlreadyExistsException(RegisterRequest request) : AlreadyExistsException($"User with email '{request.Email}' already exists");
}

View File

@@ -2,10 +2,13 @@
namespace ApplicationLayer.Services.AuthServices.RegisterService
{
/// Handles <see cref="RegisterApplicantRequest"/>
/// Handles register request
public interface IRegisterService
{
/// Handle <see cref="RegisterApplicantRequest"/>
Task Register(RegisterApplicantRequest request, CancellationToken cancellationToken);
/// Handles <see cref="RegisterRequest"/> and adds approving authority account
Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken);
}
}

View File

@@ -18,6 +18,7 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService
{
async Task IRegisterService.Register(RegisterApplicantRequest request, CancellationToken cancellationToken)
{
//todo move to validation layer
if (await users.FindByEmailAsync(request.Email, cancellationToken) is not null)
{
throw new UserAlreadyExistsException(request);
@@ -38,9 +39,7 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService
var placeOfWork = new PlaceOfWork
{
Name = request.PlaceOfWork.Name,
Address = placeOfWorkAddress,
PhoneNum = request.PlaceOfWork.PhoneNum
Name = request.PlaceOfWork.Name, Address = placeOfWorkAddress, PhoneNum = request.PlaceOfWork.PhoneNum
};
var applicant = new Applicant
@@ -67,5 +66,21 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService
await unitOfWork.SaveAsync(cancellationToken);
}
async Task IRegisterService.RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken)
{
//todo move to validation layer
if (await users.FindByEmailAsync(request.Email, cancellationToken) is not null)
{
throw new UserAlreadyExistsException(request);
}
//TODO mapper
var user = new User { Email = request.Email, Password = request.Password, Role = Role.ApprovingAuthority };
await users.AddAsync(user, cancellationToken);
await unitOfWork.SaveAsync(cancellationToken);
}
}
}

View File

@@ -18,5 +18,5 @@ namespace ApplicationLayer.Services.AuthServices.Requests
Name MotherName,
string JobTitle,
PlaceOfWorkModel PlaceOfWork,
bool IsNonResident);
bool IsNonResident) : RegisterRequest(Email, Password);
}

View File

@@ -0,0 +1,4 @@
namespace ApplicationLayer.Services.AuthServices.Requests
{
public record RegisterRequest(string Email, string Password);
}

View File

@@ -1,11 +0,0 @@
using ApplicationLayer.Services.Locations.Requests;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests
{
/// Handles edit requests of locations from admins
public interface IEditLocationsRequestsHandler
{
/// Handles add country requests
Task AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken);
}
}

View File

@@ -1,12 +0,0 @@
using Domains.LocationDomain;
namespace ApplicationLayer.Services.Locations.RequestHandlers.ApplicantRequests
{
/// Handles location requests
public interface ILocationRequestsHandler
{
/// Handle get request
/// <returns>List of available countries</returns>
Task<List<Country>> HandleGetRequestAsync(CancellationToken cancellationToken);
}
}

View File

@@ -1,14 +0,0 @@
using ApplicationLayer.Services.Locations.NeededServices;
using Domains.LocationDomain;
namespace ApplicationLayer.Services.Locations.RequestHandlers.ApplicantRequests
{
/// <inheritdoc cref="ILocationRequestsHandler"/>
public class LocationRequestsHandler(ICountriesRepository countries) : ILocationRequestsHandler
{
async Task<List<Country>> ILocationRequestsHandler.HandleGetRequestAsync(CancellationToken cancellationToken)
{
return await countries.GetAllAsync(cancellationToken);
}
}
}

View File

@@ -1,6 +1,6 @@
using ApplicationLayer.GeneralExceptions;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests.Exceptions
namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions
{
public class CountryAlreadyExists(string countryName) : AlreadyExistsException($"{countryName} already exists.");
}

View File

@@ -1,6 +1,6 @@
using ApplicationLayer.GeneralExceptions;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests.Exceptions
namespace ApplicationLayer.Services.Locations.RequestHandlers.Exceptions
{
public class MultipleIdenticalCitiesInCountryException() : ApiException("There are multiple cities with one name in the country.");
}

View File

@@ -0,0 +1,16 @@
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 add country requests
Task AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken);
}
}

View File

@@ -1,15 +1,20 @@
using ApplicationLayer.GeneralNeededServices;
using ApplicationLayer.Services.Locations.NeededServices;
using ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests.Exceptions;
using ApplicationLayer.Services.Locations.RequestHandlers.Exceptions;
using ApplicationLayer.Services.Locations.Requests;
using Domains.LocationDomain;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests
namespace ApplicationLayer.Services.Locations.RequestHandlers
{
/// <inheritdoc cref="IEditLocationsRequestsHandler"/>
public class EditLocationsRequestsHandler(ICountriesRepository countries, IUnitOfWork unitOfWork) : IEditLocationsRequestsHandler
/// <inheritdoc cref="ILocationRequestsHandler"/>
public class LocationRequestsHandler(ICountriesRepository countries, IUnitOfWork unitOfWork) : ILocationRequestsHandler
{
async Task IEditLocationsRequestsHandler.AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken)
async Task<List<Country>> ILocationRequestsHandler.HandleGetRequestAsync(CancellationToken cancellationToken)
{
return await countries.GetAllAsync(cancellationToken);
}
async Task ILocationRequestsHandler.AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken)
{
if (await countries.FindByName(request.CountryName, cancellationToken) is not null)
{
@@ -21,6 +26,7 @@ namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests
throw new MultipleIdenticalCitiesInCountryException();
}
//todo mapper
var country = new Country
{
Name = request.CountryName,