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); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user