Added validation and fixed errors
This commit is contained in:
		| @@ -3,5 +3,5 @@ using ApplicationLayer.Services.AuthServices.Requests; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.RegisterService.Exceptions | ||||
| { | ||||
|     public class UserAlreadyExistsException(RegisterRequest request) : AlreadyExistsException($"User with email '{request.Email}' already exists"); | ||||
|     public class UserAlreadyExistsException(RegisterRequest request) : AlreadyExistsException($"User with email '{request.AuthData.Email}' already exists"); | ||||
| } | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.Applicants.NeededServices; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using ApplicationLayer.Services.AuthServices.RegisterService.Exceptions; | ||||
| using ApplicationLayer.Services.AuthServices.Requests; | ||||
| using AutoMapper; | ||||
| using Domains.ApplicantDomain; | ||||
| @@ -18,33 +17,11 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService | ||||
|     { | ||||
|         async Task IRegisterService.RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             //todo move to validation layer | ||||
|             if (await users.FindByEmailAsync(request.Email, cancellationToken) is not null) | ||||
|             { | ||||
|                 throw new UserAlreadyExistsException(request); | ||||
|             } | ||||
|  | ||||
|             var user = mapper.Map<User>(request); | ||||
|             var user = mapper.Map<User>(request.AuthData); | ||||
|             user.Role = Role.Applicant; | ||||
|  | ||||
|             var applicant = new Applicant | ||||
|             { | ||||
|                 Citizenship = request.Citizenship, | ||||
|                 CitizenshipByBirth = request.CitizenshipByBirth, | ||||
|                 Gender = request.Gender, | ||||
|                 Name = request.ApplicantName, | ||||
|                 Passport = request.Passport, | ||||
|                 BirthDate = request.BirthDate, | ||||
|                 FatherName = request.FatherName, | ||||
|                 JobTitle = request.JobTitle, | ||||
|                 MaritalStatus = request.MaritalStatus, | ||||
|                 MotherName = request.MotherName, | ||||
|                 UserId = user.Id, | ||||
|                 CityOfBirth = request.CityOfBirth, | ||||
|                 CountryOfBirth = request.CountryOfBirth, | ||||
|                 IsNonResident = request.IsNonResident, | ||||
|                 PlaceOfWork = request.PlaceOfWork | ||||
|             }; | ||||
|             var applicant = mapper.Map<Applicant>(request); | ||||
|             applicant.UserId = user.Id; | ||||
|  | ||||
|             await users.AddAsync(user, cancellationToken); | ||||
|             await applicants.AddAsync(applicant, cancellationToken); | ||||
| @@ -54,13 +31,7 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService | ||||
|  | ||||
|         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); | ||||
|             } | ||||
|  | ||||
|             var user = mapper.Map<User>(request); | ||||
|             var user = mapper.Map<User>(request.AuthData); | ||||
|             user.Role = Role.ApprovingAuthority; | ||||
|  | ||||
|             await users.AddAsync(user, cancellationToken); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user