file-scoped namespaces
This commit is contained in:
		| @@ -1,4 +1,3 @@ | ||||
| namespace ApplicationLayer.Services.AuthServices.Common | ||||
| { | ||||
|     public record AuthData(string Email, string Password); | ||||
| } | ||||
| namespace ApplicationLayer.Services.AuthServices.Common; | ||||
|  | ||||
| public record AuthData(string Email, string Password); | ||||
| @@ -2,12 +2,12 @@ | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService; | ||||
|  | ||||
| public class DevelopmentLoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService | ||||
| { | ||||
|     public class DevelopmentLoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService | ||||
|     async Task<string> ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken) | ||||
|     { | ||||
|         async Task<string> ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken) | ||||
|         { | ||||
|             if (email == "admin@mail.ru" && password == "admin") | ||||
|             { | ||||
|                 var admin = new User { Role = Role.Admin }; | ||||
| @@ -23,5 +23,4 @@ namespace ApplicationLayer.Services.AuthServices.LoginService | ||||
|  | ||||
|             return tokenGenerator.CreateToken(user); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| using ApplicationLayer.GeneralExceptions; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService.Exceptions | ||||
| { | ||||
|     public class IncorrectLoginDataException() : ApiException("Incorrect email or password"); | ||||
| } | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService.Exceptions; | ||||
|  | ||||
| public class IncorrectLoginDataException() : ApiException("Incorrect email or password"); | ||||
| @@ -1,10 +1,9 @@ | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService; | ||||
|  | ||||
| /// Handles login requests | ||||
| public interface ILoginService | ||||
| { | ||||
|     /// Handles login requests | ||||
|     public interface ILoginService | ||||
|     { | ||||
|         /// Handle login request | ||||
|         /// <returns>JWT-token</returns> | ||||
|         Task<string> LoginAsync(string email, string password, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|     /// Handle login request | ||||
|     /// <returns>JWT-token</returns> | ||||
|     Task<string> LoginAsync(string email, string password, CancellationToken cancellationToken); | ||||
| } | ||||
| @@ -1,13 +1,13 @@ | ||||
| using ApplicationLayer.Services.AuthServices.LoginService.Exceptions; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService | ||||
| namespace ApplicationLayer.Services.AuthServices.LoginService; | ||||
|  | ||||
| /// <inheritdoc cref="ILoginService"/> | ||||
| public class LoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService | ||||
| { | ||||
|     /// <inheritdoc cref="ILoginService"/> | ||||
|     public class LoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService | ||||
|     async Task<string> ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken) | ||||
|     { | ||||
|         async Task<string> ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = await users.FindByEmailAsync(email, cancellationToken); | ||||
|             if (user is null || user.Password != password) | ||||
|             { | ||||
| @@ -16,5 +16,4 @@ namespace ApplicationLayer.Services.AuthServices.LoginService | ||||
|  | ||||
|             return tokenGenerator.CreateToken(user); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,9 +1,8 @@ | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.NeededServices | ||||
| namespace ApplicationLayer.Services.AuthServices.NeededServices; | ||||
|  | ||||
| public interface ITokenGenerator | ||||
| { | ||||
|     public interface ITokenGenerator | ||||
|     { | ||||
|         string CreateToken(User user); | ||||
|     } | ||||
| } | ||||
|     string CreateToken(User user); | ||||
| } | ||||
| @@ -1,21 +1,20 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.NeededServices | ||||
| { | ||||
|     /// Repository pattern for <see cref="User"/> | ||||
|     public interface IUsersRepository : IGenericRepository<User> | ||||
|     { | ||||
|         /// Find <see cref="User"/> by email | ||||
|         /// <param name="email"><see cref="User"/>'s email</param> | ||||
|         /// <param name="cancellationToken">Cancellation token</param> | ||||
|         /// <returns>User or null if not found</returns> | ||||
|         Task<User?> FindByEmailAsync(string email, CancellationToken cancellationToken); | ||||
| namespace ApplicationLayer.Services.AuthServices.NeededServices; | ||||
|  | ||||
|         /// Returns all accounts with specific role | ||||
|         /// <param name="role">role</param> | ||||
|         /// <param name="cancellationToken">cancellation token</param> | ||||
|         /// <returns>list of accounts</returns> | ||||
|         Task<List<User>> GetAllOfRoleAsync(Role role, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| /// Repository pattern for <see cref="User"/> | ||||
| public interface IUsersRepository : IGenericRepository<User> | ||||
| { | ||||
|     /// Find <see cref="User"/> by email | ||||
|     /// <param name="email"><see cref="User"/>'s email</param> | ||||
|     /// <param name="cancellationToken">Cancellation token</param> | ||||
|     /// <returns>User or null if not found</returns> | ||||
|     Task<User?> FindByEmailAsync(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|     /// Returns all accounts with specific role | ||||
|     /// <param name="role">role</param> | ||||
|     /// <param name="cancellationToken">cancellation token</param> | ||||
|     /// <returns>list of accounts</returns> | ||||
|     Task<List<User>> GetAllOfRoleAsync(Role role, CancellationToken cancellationToken); | ||||
| } | ||||
| @@ -1,14 +1,13 @@ | ||||
| using ApplicationLayer.Services.AuthServices.Requests; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.RegisterService | ||||
| { | ||||
|     /// Handles register request | ||||
|     public interface IRegisterService | ||||
|     { | ||||
|         /// Handle <see cref="RegisterApplicantRequest"/> | ||||
|         Task RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken); | ||||
| namespace ApplicationLayer.Services.AuthServices.RegisterService; | ||||
|  | ||||
|         /// Handles <see cref="RegisterRequest"/> and adds approving authority account | ||||
|         Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| /// Handles register request | ||||
| public interface IRegisterService | ||||
| { | ||||
|     /// Handle <see cref="RegisterApplicantRequest"/> | ||||
|     Task RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken); | ||||
|  | ||||
|     /// Handles <see cref="RegisterRequest"/> and adds approving authority account | ||||
|     Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken); | ||||
| } | ||||
| @@ -6,37 +6,36 @@ using AutoMapper; | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.RegisterService | ||||
| namespace ApplicationLayer.Services.AuthServices.RegisterService; | ||||
|  | ||||
| /// <inheritdoc cref="IRegisterService"/> | ||||
| public class RegisterService( | ||||
|     IUsersRepository users, | ||||
|     IApplicantsRepository applicants, | ||||
|     IUnitOfWork unitOfWork, | ||||
|     IMapper mapper) : IRegisterService | ||||
| { | ||||
|     /// <inheritdoc cref="IRegisterService"/> | ||||
|     public class RegisterService( | ||||
|         IUsersRepository users, | ||||
|         IApplicantsRepository applicants, | ||||
|         IUnitOfWork unitOfWork, | ||||
|         IMapper mapper) : IRegisterService | ||||
|     async Task IRegisterService.RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken) | ||||
|     { | ||||
|         async Task IRegisterService.RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = mapper.Map<User>(request.AuthData); | ||||
|             user.Role = Role.Applicant; | ||||
|         var user = mapper.Map<User>(request.AuthData); | ||||
|         user.Role = Role.Applicant; | ||||
|  | ||||
|             var applicant = mapper.Map<Applicant>(request); | ||||
|             applicant.UserId = user.Id; | ||||
|         var applicant = mapper.Map<Applicant>(request); | ||||
|         applicant.UserId = user.Id; | ||||
|  | ||||
|             await users.AddAsync(user, cancellationToken); | ||||
|             await applicants.AddAsync(applicant, cancellationToken); | ||||
|         await users.AddAsync(user, cancellationToken); | ||||
|         await applicants.AddAsync(applicant, cancellationToken); | ||||
|  | ||||
|             await unitOfWork.SaveAsync(cancellationToken); | ||||
|         } | ||||
|  | ||||
|         async Task IRegisterService.RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = mapper.Map<User>(request.AuthData); | ||||
|             user.Role = Role.ApprovingAuthority; | ||||
|  | ||||
|             await users.AddAsync(user, cancellationToken); | ||||
|  | ||||
|             await unitOfWork.SaveAsync(cancellationToken); | ||||
|         } | ||||
|         await unitOfWork.SaveAsync(cancellationToken); | ||||
|     } | ||||
| } | ||||
|  | ||||
|     async Task IRegisterService.RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var user = mapper.Map<User>(request.AuthData); | ||||
|         user.Role = Role.ApprovingAuthority; | ||||
|  | ||||
|         await users.AddAsync(user, cancellationToken); | ||||
|  | ||||
|         await unitOfWork.SaveAsync(cancellationToken); | ||||
|     } | ||||
| } | ||||
| @@ -2,22 +2,21 @@ | ||||
| using ApplicationLayer.Services.AuthServices.Common; | ||||
| using Domains.ApplicantDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests | ||||
| { | ||||
|     public record RegisterApplicantRequest( | ||||
|         AuthData AuthData, | ||||
|         Name ApplicantName, | ||||
|         Passport Passport, | ||||
|         DateTime BirthDate, | ||||
|         string CityOfBirth, | ||||
|         string CountryOfBirth, | ||||
|         string Citizenship, | ||||
|         string CitizenshipByBirth, | ||||
|         Gender Gender, | ||||
|         MaritalStatus MaritalStatus, | ||||
|         Name FatherName, | ||||
|         Name MotherName, | ||||
|         string JobTitle, | ||||
|         PlaceOfWorkModel PlaceOfWork, | ||||
|         bool IsNonResident) : RegisterRequest(AuthData); | ||||
| } | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests; | ||||
|  | ||||
| public record RegisterApplicantRequest( | ||||
|     AuthData AuthData, | ||||
|     Name ApplicantName, | ||||
|     Passport Passport, | ||||
|     DateTime BirthDate, | ||||
|     string CityOfBirth, | ||||
|     string CountryOfBirth, | ||||
|     string Citizenship, | ||||
|     string CitizenshipByBirth, | ||||
|     Gender Gender, | ||||
|     MaritalStatus MaritalStatus, | ||||
|     Name FatherName, | ||||
|     Name MotherName, | ||||
|     string JobTitle, | ||||
|     PlaceOfWorkModel PlaceOfWork, | ||||
|     bool IsNonResident) : RegisterRequest(AuthData); | ||||
| @@ -1,6 +1,5 @@ | ||||
| using ApplicationLayer.Services.AuthServices.Common; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests | ||||
| { | ||||
|     public record RegisterRequest(AuthData AuthData); | ||||
| } | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests; | ||||
|  | ||||
| public record RegisterRequest(AuthData AuthData); | ||||
| @@ -3,12 +3,12 @@ using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation; | ||||
|  | ||||
| public class AuthDataValidator : AbstractValidator<AuthData> | ||||
| { | ||||
|     public class AuthDataValidator : AbstractValidator<AuthData> | ||||
|     public AuthDataValidator(IUsersRepository users) | ||||
|     { | ||||
|         public AuthDataValidator(IUsersRepository users) | ||||
|         { | ||||
|             RuleFor(d => d.Email) | ||||
|                 .NotEmpty() | ||||
|                 .WithMessage("Email can not be empty") | ||||
| @@ -28,5 +28,4 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
|                 .MaximumLength(ConfigurationConstraints.PasswordLength) | ||||
|                 .WithMessage($"Password length must be less than {ConfigurationConstraints.PasswordLength}"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -2,12 +2,12 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation; | ||||
|  | ||||
| public class NameValidator : AbstractValidator<Name> | ||||
| { | ||||
|     public class NameValidator : AbstractValidator<Name> | ||||
|     public NameValidator() | ||||
|     { | ||||
|         public NameValidator() | ||||
|         { | ||||
|             RuleFor(m => m.FirstName) | ||||
|                 .NotEmpty() | ||||
|                 .WithMessage("First Name can not be empty") | ||||
| @@ -24,5 +24,4 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
|                 .MaximumLength(ConfigurationConstraints.NameLength) | ||||
|                 .WithMessage($"Patronymic length must be less than {ConfigurationConstraints.NameLength}"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -3,12 +3,12 @@ using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation; | ||||
|  | ||||
| public class PassportValidator : AbstractValidator<Passport> | ||||
| { | ||||
|     public class PassportValidator : AbstractValidator<Passport> | ||||
|     public PassportValidator(IDateTimeProvider dateTimeProvider) | ||||
|     { | ||||
|         public PassportValidator(IDateTimeProvider dateTimeProvider) | ||||
|         { | ||||
|             RuleFor(r => r.Issuer) | ||||
|                 .NotEmpty() | ||||
|                 .WithMessage("Passport issuer can not be empty") | ||||
| @@ -33,5 +33,4 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
|                 .LessThanOrEqualTo(dateTimeProvider.Now()) | ||||
|                 .WithMessage("Passport issue date must be in past"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -2,12 +2,12 @@ | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation; | ||||
|  | ||||
| public class PlaceOfWorkModelValidator : AbstractValidator<PlaceOfWorkModel> | ||||
| { | ||||
|     public class PlaceOfWorkModelValidator : AbstractValidator<PlaceOfWorkModel> | ||||
|     public PlaceOfWorkModelValidator() | ||||
|     { | ||||
|         public PlaceOfWorkModelValidator() | ||||
|         { | ||||
|             RuleFor(p => p.Name) | ||||
|                 .NotEmpty() | ||||
|                 .WithMessage("Place of work name can not be empty") | ||||
| @@ -46,5 +46,4 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
|                 .MaximumLength(ConfigurationConstraints.CountryNameLength) | ||||
|                 .WithMessage($"Building of place of work length must be less than {ConfigurationConstraints.BuildingNumberLength}"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -5,17 +5,17 @@ using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
| namespace ApplicationLayer.Services.AuthServices.Requests.Validation; | ||||
|  | ||||
| public class RegisterApplicantRequestValidator : AbstractValidator<RegisterApplicantRequest> | ||||
| { | ||||
|     public class RegisterApplicantRequestValidator : AbstractValidator<RegisterApplicantRequest> | ||||
|     public RegisterApplicantRequestValidator( | ||||
|         IDateTimeProvider dateTimeProvider, | ||||
|         IValidator<Name> nameValidator, | ||||
|         IValidator<AuthData> authDataValidator, | ||||
|         IValidator<Passport> passportValidator, | ||||
|         IValidator<PlaceOfWorkModel> placeOfWorkModelValidator) | ||||
|     { | ||||
|         public RegisterApplicantRequestValidator( | ||||
|             IDateTimeProvider dateTimeProvider, | ||||
|             IValidator<Name> nameValidator, | ||||
|             IValidator<AuthData> authDataValidator, | ||||
|             IValidator<Passport> passportValidator, | ||||
|             IValidator<PlaceOfWorkModel> placeOfWorkModelValidator) | ||||
|         { | ||||
|             RuleFor(r => r.AuthData) | ||||
|                 .SetValidator(authDataValidator); | ||||
|  | ||||
| @@ -74,5 +74,4 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation | ||||
|             RuleFor(r => r.PlaceOfWork) | ||||
|                 .SetValidator(placeOfWorkModelValidator); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user