Registration and actions for approving authorities
This commit is contained in:
		| @@ -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"); | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -18,5 +18,5 @@ namespace ApplicationLayer.Services.AuthServices.Requests | ||||
|         Name MotherName, | ||||
|         string JobTitle, | ||||
|         PlaceOfWorkModel PlaceOfWork, | ||||
|         bool IsNonResident); | ||||
|         bool IsNonResident) : RegisterRequest(Email, Password); | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,4 @@ | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests | ||||
| { | ||||
|     public record RegisterRequest(string Email, string Password); | ||||
| } | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
| @@ -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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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."); | ||||
| } | ||||
| @@ -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."); | ||||
| } | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
| @@ -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, | ||||
		Reference in New Issue
	
	Block a user