diff --git a/SchengenVisaApi/ApplicationLayer/GeneralExceptions/AlreadyExistsException.cs b/SchengenVisaApi/ApplicationLayer/GeneralExceptions/AlreadyExistsException.cs index 51daa4e..42731b2 100644 --- a/SchengenVisaApi/ApplicationLayer/GeneralExceptions/AlreadyExistsException.cs +++ b/SchengenVisaApi/ApplicationLayer/GeneralExceptions/AlreadyExistsException.cs @@ -1,4 +1,3 @@ -namespace ApplicationLayer.GeneralExceptions -{ - public class AlreadyExistsException(string message) : ApiException(message); -} +namespace ApplicationLayer.GeneralExceptions; + +public class AlreadyExistsException(string message) : ApiException(message); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/GeneralExceptions/ApiException.cs b/SchengenVisaApi/ApplicationLayer/GeneralExceptions/ApiException.cs index 8f7ed6a..732a21d 100644 --- a/SchengenVisaApi/ApplicationLayer/GeneralExceptions/ApiException.cs +++ b/SchengenVisaApi/ApplicationLayer/GeneralExceptions/ApiException.cs @@ -1,4 +1,3 @@ -namespace ApplicationLayer.GeneralExceptions -{ - public class ApiException(string message) : Exception(message); -} +namespace ApplicationLayer.GeneralExceptions; + +public class ApiException(string message) : Exception(message); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IDateTimeProvider.cs b/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IDateTimeProvider.cs index 8960bea..de0f09d 100644 --- a/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IDateTimeProvider.cs +++ b/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IDateTimeProvider.cs @@ -1,8 +1,7 @@ -namespace ApplicationLayer.InfrastructureServicesInterfaces +namespace ApplicationLayer.InfrastructureServicesInterfaces; + +public interface IDateTimeProvider { - public interface IDateTimeProvider - { - /// Returns current date and time - DateTime Now(); - } -} + /// Returns current date and time + DateTime Now(); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IUserIdProvider.cs b/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IUserIdProvider.cs index b7e1101..4f706af 100644 --- a/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IUserIdProvider.cs +++ b/SchengenVisaApi/ApplicationLayer/InfrastructureServicesInterfaces/IUserIdProvider.cs @@ -1,8 +1,7 @@ -namespace ApplicationLayer.InfrastructureServicesInterfaces +namespace ApplicationLayer.InfrastructureServicesInterfaces; + +public interface IUserIdProvider { - public interface IUserIdProvider - { - /// Returns identifier of authenticated user who sent the request - Guid GetUserId(); - } -} + /// Returns identifier of authenticated user who sent the request + Guid GetUserId(); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs b/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs index 1898c3a..1530e2e 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs @@ -1,50 +1,49 @@ using Domains.ApplicantDomain; -namespace ApplicationLayer.Services.Applicants.Models +namespace ApplicationLayer.Services.Applicants.Models; + +/// Model of +public class ApplicantModel { - /// Model of - public class ApplicantModel - { - /// - public Name Name { get; set; } = null!; + /// + public Name Name { get; set; } = null!; - /// - public Passport Passport { get; set; } = null!; + /// + public Passport Passport { get; set; } = null!; - /// - public DateTime BirthDate { get; set; } + /// + public DateTime BirthDate { get; set; } - /// - public string CountryOfBirth { get; set; } = null!; + /// + public string CountryOfBirth { get; set; } = null!; - /// - public string CityOfBirth { get; set; } = null!; + /// + public string CityOfBirth { get; set; } = null!; - /// - public string Citizenship { get; set; } = null!; + /// + public string Citizenship { get; set; } = null!; - /// - public string CitizenshipByBirth { get; set; } = null!; + /// + public string CitizenshipByBirth { get; set; } = null!; - /// - public Gender Gender { get; set; } + /// + public Gender Gender { get; set; } - /// - public MaritalStatus MaritalStatus { get; set; } + /// + public MaritalStatus MaritalStatus { get; set; } - /// - public Name FatherName { get; set; } = null!; + /// + public Name FatherName { get; set; } = null!; - /// - public Name MotherName { get; set; } = null!; + /// + public Name MotherName { get; set; } = null!; - /// - public string JobTitle { get; set; } = null!; + /// + public string JobTitle { get; set; } = null!; - /// - public PlaceOfWork PlaceOfWork { get; set; } = null!; + /// + public PlaceOfWork PlaceOfWork { get; set; } = null!; - /// - public bool IsNonResident { get; set; } - } -} + /// + public bool IsNonResident { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/PlaceOfWorkModel.cs b/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/PlaceOfWorkModel.cs index 35ae398..f7df5fb 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/PlaceOfWorkModel.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/PlaceOfWorkModel.cs @@ -1,16 +1,15 @@ using Domains.ApplicantDomain; -namespace ApplicationLayer.Services.Applicants.Models +namespace ApplicationLayer.Services.Applicants.Models; + +public class PlaceOfWorkModel { - public class PlaceOfWorkModel - { - /// Name of hirer - public string Name { get; set; } = null!; + /// Name of hirer + public string Name { get; set; } = null!; - /// Address of hirer - public Address Address { get; set; } = null!; + /// Address of hirer + public Address Address { get; set; } = null!; - /// Phone number of hirer - public string PhoneNum { get; set; } = null!; - } -} + /// Phone number of hirer + public string PhoneNum { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Common/AuthData.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Common/AuthData.cs index a6cec9c..0eebb89 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Common/AuthData.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Common/AuthData.cs @@ -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); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/DevelopmentLoginService.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/DevelopmentLoginService.cs index 2e9d245..0434a6f 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/DevelopmentLoginService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/DevelopmentLoginService.cs @@ -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 ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken) { - async Task 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); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/Exceptions/IncorrectLoginDataException.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/Exceptions/IncorrectLoginDataException.cs index 65a49aa..0d989cd 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/Exceptions/IncorrectLoginDataException.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/Exceptions/IncorrectLoginDataException.cs @@ -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"); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/ILoginService.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/ILoginService.cs index 71599c9..bb4e2a3 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/ILoginService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/ILoginService.cs @@ -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 - /// JWT-token - Task LoginAsync(string email, string password, CancellationToken cancellationToken); - } -} + /// Handle login request + /// JWT-token + Task LoginAsync(string email, string password, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/LoginService.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/LoginService.cs index 8697956..33e44cf 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/LoginService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/LoginService/LoginService.cs @@ -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; + +/// +public class LoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService { - /// - public class LoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService + async Task ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken) { - async Task 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); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/ITokenGenerator.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/ITokenGenerator.cs index a91b9c7..5601a04 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/ITokenGenerator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/ITokenGenerator.cs @@ -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); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/IUsersRepository.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/IUsersRepository.cs index a77ff96..214d08c 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/IUsersRepository.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/NeededServices/IUsersRepository.cs @@ -1,21 +1,20 @@ using ApplicationLayer.InfrastructureServicesInterfaces; using Domains.Users; -namespace ApplicationLayer.Services.AuthServices.NeededServices -{ - /// Repository pattern for - public interface IUsersRepository : IGenericRepository - { - /// Find by email - /// 's email - /// Cancellation token - /// User or null if not found - Task FindByEmailAsync(string email, CancellationToken cancellationToken); +namespace ApplicationLayer.Services.AuthServices.NeededServices; - /// Returns all accounts with specific role - /// role - /// cancellation token - /// list of accounts - Task> GetAllOfRoleAsync(Role role, CancellationToken cancellationToken); - } -} +/// Repository pattern for +public interface IUsersRepository : IGenericRepository +{ + /// Find by email + /// 's email + /// Cancellation token + /// User or null if not found + Task FindByEmailAsync(string email, CancellationToken cancellationToken); + + /// Returns all accounts with specific role + /// role + /// cancellation token + /// list of accounts + Task> GetAllOfRoleAsync(Role role, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/IRegisterService.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/IRegisterService.cs index 52d69e4..1092a25 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/IRegisterService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/IRegisterService.cs @@ -1,14 +1,13 @@ using ApplicationLayer.Services.AuthServices.Requests; -namespace ApplicationLayer.Services.AuthServices.RegisterService -{ - /// Handles register request - public interface IRegisterService - { - /// Handle - Task RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken); +namespace ApplicationLayer.Services.AuthServices.RegisterService; - /// Handles and adds approving authority account - Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken); - } -} +/// Handles register request +public interface IRegisterService +{ + /// Handle + Task RegisterApplicant(RegisterApplicantRequest request, CancellationToken cancellationToken); + + /// Handles and adds approving authority account + Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs index 86be1f9..57bb4ed 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/RegisterService/RegisterService.cs @@ -6,37 +6,36 @@ using AutoMapper; using Domains.ApplicantDomain; using Domains.Users; -namespace ApplicationLayer.Services.AuthServices.RegisterService +namespace ApplicationLayer.Services.AuthServices.RegisterService; + +/// +public class RegisterService( + IUsersRepository users, + IApplicantsRepository applicants, + IUnitOfWork unitOfWork, + IMapper mapper) : 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(request.AuthData); - user.Role = Role.Applicant; + var user = mapper.Map(request.AuthData); + user.Role = Role.Applicant; - var applicant = mapper.Map(request); - applicant.UserId = user.Id; + var applicant = mapper.Map(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(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(request.AuthData); + user.Role = Role.ApprovingAuthority; + + await users.AddAsync(user, cancellationToken); + + await unitOfWork.SaveAsync(cancellationToken); + } +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs index 57171f5..a82435b 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterApplicantRequest.cs @@ -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); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterRequest.cs index 82422ce..aaa3bd3 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterRequest.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/RegisterRequest.cs @@ -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); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/AuthDataValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/AuthDataValidator.cs index d988e21..a6f43fa 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/AuthDataValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/AuthDataValidator.cs @@ -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 { - public class AuthDataValidator : AbstractValidator + 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}"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/NameValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/NameValidator.cs index 38547df..5393f61 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/NameValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/NameValidator.cs @@ -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 { - public class NameValidator : AbstractValidator + 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}"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PassportValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PassportValidator.cs index 60b96c1..26a535f 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PassportValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PassportValidator.cs @@ -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 { - public class PassportValidator : AbstractValidator + 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"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PlaceOfWorkModelValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PlaceOfWorkModelValidator.cs index ec01684..dc965d3 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PlaceOfWorkModelValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/PlaceOfWorkModelValidator.cs @@ -2,12 +2,12 @@ using Domains; using FluentValidation; -namespace ApplicationLayer.Services.AuthServices.Requests.Validation +namespace ApplicationLayer.Services.AuthServices.Requests.Validation; + +public class PlaceOfWorkModelValidator : AbstractValidator { - public class PlaceOfWorkModelValidator : AbstractValidator + 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}"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/RegisterApplicantRequestValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/RegisterApplicantRequestValidator.cs index da869d9..4004820 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/RegisterApplicantRequestValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/AuthServices/Requests/Validation/RegisterApplicantRequestValidator.cs @@ -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 { - public class RegisterApplicantRequestValidator : AbstractValidator + public RegisterApplicantRequestValidator( + IDateTimeProvider dateTimeProvider, + IValidator nameValidator, + IValidator authDataValidator, + IValidator passportValidator, + IValidator placeOfWorkModelValidator) { - public RegisterApplicantRequestValidator( - IDateTimeProvider dateTimeProvider, - IValidator nameValidator, - IValidator authDataValidator, - IValidator passportValidator, - IValidator placeOfWorkModelValidator) - { RuleFor(r => r.AuthData) .SetValidator(authDataValidator); @@ -74,5 +74,4 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation RuleFor(r => r.PlaceOfWork) .SetValidator(placeOfWorkModelValidator); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs b/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs index 95a4648..9ca7d8a 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs @@ -1,23 +1,22 @@ using ApplicationLayer.Services.Users.Requests; using Domains.Users; -namespace ApplicationLayer.Services.Users +namespace ApplicationLayer.Services.Users; + +/// user accounts service +public interface IUsersService { - /// user accounts service - public interface IUsersService - { - /// Returns all user accounts with role of approving authority - /// Cancellation token - Task> GetAuthoritiesAccountsAsync(CancellationToken cancellationToken); + /// Returns all user accounts with role of approving authority + /// Cancellation token + Task> GetAuthoritiesAccountsAsync(CancellationToken cancellationToken); - /// Changes authentication data for an account - /// Request object with identifier of user and new authentication data - /// Cancellation token - Task ChangeAccountAuthDataAsync(ChangeUserAuthDataRequest request, CancellationToken cancellationToken); + /// Changes authentication data for an account + /// Request object with identifier of user and new authentication data + /// Cancellation token + Task ChangeAccountAuthDataAsync(ChangeUserAuthDataRequest request, CancellationToken cancellationToken); - /// Removes user account - /// Identifier of account - /// Cancellation token - Task RemoveUserAccount(Guid userId, CancellationToken cancellationToken); - } -} + /// Removes user account + /// Identifier of account + /// Cancellation token + Task RemoveUserAccount(Guid userId, CancellationToken cancellationToken); +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/Users/Requests/ChangeUserAuthDataRequest.cs b/SchengenVisaApi/ApplicationLayer/Services/Users/Requests/ChangeUserAuthDataRequest.cs index 06b10e7..42619b4 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Users/Requests/ChangeUserAuthDataRequest.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Users/Requests/ChangeUserAuthDataRequest.cs @@ -1,6 +1,5 @@ using ApplicationLayer.Services.AuthServices.Common; -namespace ApplicationLayer.Services.Users.Requests -{ - public record ChangeUserAuthDataRequest(Guid UserId, AuthData NewAuthData); -} +namespace ApplicationLayer.Services.Users.Requests; + +public record ChangeUserAuthDataRequest(Guid UserId, AuthData NewAuthData); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs b/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs index d088bac..1228bcc 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs @@ -3,17 +3,17 @@ using ApplicationLayer.Services.AuthServices.NeededServices; using ApplicationLayer.Services.Users.Requests; using Domains.Users; -namespace ApplicationLayer.Services.Users +namespace ApplicationLayer.Services.Users; + +public class UsersService(IUsersRepository users, IUnitOfWork unitOfWork) : IUsersService { - public class UsersService(IUsersRepository users, IUnitOfWork unitOfWork) : IUsersService + async Task> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken) { - async Task> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken) - { return await users.GetAllOfRoleAsync(Role.ApprovingAuthority, cancellationToken); } - async Task IUsersService.ChangeAccountAuthDataAsync(ChangeUserAuthDataRequest request, CancellationToken cancellationToken) - { + async Task IUsersService.ChangeAccountAuthDataAsync(ChangeUserAuthDataRequest request, CancellationToken cancellationToken) + { var user = await users.GetByIdAsync(request.UserId, cancellationToken); user.Email = request.NewAuthData.Email; @@ -23,12 +23,11 @@ namespace ApplicationLayer.Services.Users await unitOfWork.SaveAsync(cancellationToken); } - async Task IUsersService.RemoveUserAccount(Guid userId, CancellationToken cancellationToken) - { + async Task IUsersService.RemoveUserAccount(Guid userId, CancellationToken cancellationToken) + { var user = await users.GetByIdAsync(userId, cancellationToken); users.Remove(user); await unitOfWork.SaveAsync(cancellationToken); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Exceptions/ApplicationAlreadyProcessedException.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Exceptions/ApplicationAlreadyProcessedException.cs index 47da53e..fab7a22 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Exceptions/ApplicationAlreadyProcessedException.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Exceptions/ApplicationAlreadyProcessedException.cs @@ -1,6 +1,5 @@ using ApplicationLayer.GeneralExceptions; -namespace ApplicationLayer.Services.VisaApplications.Exceptions -{ - public class ApplicationAlreadyProcessedException() : ApiException("This application already processed or closed by applicant."); -} +namespace ApplicationLayer.Services.VisaApplications.Exceptions; + +public class ApplicationAlreadyProcessedException() : ApiException("This application already processed or closed by applicant."); \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/AuthorityRequestStatuses.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/AuthorityRequestStatuses.cs index 93f2a93..d90d6ee 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/AuthorityRequestStatuses.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/AuthorityRequestStatuses.cs @@ -1,8 +1,7 @@ -namespace ApplicationLayer.Services.VisaApplications.Models +namespace ApplicationLayer.Services.VisaApplications.Models; + +public enum AuthorityRequestStatuses { - public enum AuthorityRequestStatuses - { - Approved, - Rejected - } -} + Approved, + Rejected +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs index c9b53b9..c47e7ff 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForApplicant.cs @@ -1,44 +1,43 @@ using Domains.VisaApplicationDomain; -namespace ApplicationLayer.Services.VisaApplications.Models +namespace ApplicationLayer.Services.VisaApplications.Models; + +/// Model of +public class VisaApplicationModelForApplicant { - /// Model of - public class VisaApplicationModelForApplicant - { - /// - public Guid Id { get; set; } + /// + public Guid Id { get; set; } - /// - public ApplicationStatus Status { get; set; } + /// + public ApplicationStatus Status { get; set; } - /// - public ReentryPermit? ReentryPermit { get; set; } + /// + public ReentryPermit? ReentryPermit { get; set; } - /// - public string DestinationCountry { get; set; } = null!; + /// + public string DestinationCountry { get; set; } = null!; - /// - public List PastVisas { get; set; } = null!; + /// + public List PastVisas { get; set; } = null!; - /// - public PermissionToDestCountry? PermissionToDestCountry { get; set; } + /// + public PermissionToDestCountry? PermissionToDestCountry { get; set; } - /// - public List PastVisits { get; set; } = null!; + /// + public List PastVisits { get; set; } = null!; - /// - public VisaCategory VisaCategory { get; set; } + /// + public VisaCategory VisaCategory { get; set; } - /// - public bool ForGroup { get; set; } + /// + public bool ForGroup { get; set; } - /// - public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } + /// + public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } - /// - public DateTime RequestDate { get; set; } + /// + public DateTime RequestDate { get; set; } - /// - public int ValidDaysRequested { get; set; } - } -} + /// + public int ValidDaysRequested { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForAuthority.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForAuthority.cs index 6cfed9e..2cbe42f 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForAuthority.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Models/VisaApplicationModelForAuthority.cs @@ -1,47 +1,46 @@ using ApplicationLayer.Services.Applicants.Models; using Domains.VisaApplicationDomain; -namespace ApplicationLayer.Services.VisaApplications.Models +namespace ApplicationLayer.Services.VisaApplications.Models; + +/// Model of with applicant property +public class VisaApplicationModelForAuthority { - /// Model of with applicant property - public class VisaApplicationModelForAuthority - { - /// - public Guid Id { get; set; } + /// + public Guid Id { get; set; } - /// Applicant of application - public ApplicantModel Applicant { get; set; } = null!; + /// Applicant of application + public ApplicantModel Applicant { get; set; } = null!; - /// - public ApplicationStatus Status { get; set; } + /// + public ApplicationStatus Status { get; set; } - /// - public ReentryPermit? ReentryPermit { get; set; } + /// + public ReentryPermit? ReentryPermit { get; set; } - /// - public string DestinationCountry { get; set; } = null!; + /// + public string DestinationCountry { get; set; } = null!; - /// - public List PastVisas { get; set; } = null!; + /// + public List PastVisas { get; set; } = null!; - /// - public PermissionToDestCountry? PermissionToDestCountry { get; set; } + /// + public PermissionToDestCountry? PermissionToDestCountry { get; set; } - public List PastVisits { get; set; } = null!; + public List PastVisits { get; set; } = null!; - /// - public VisaCategory VisaCategory { get; set; } + /// + public VisaCategory VisaCategory { get; set; } - /// - public bool ForGroup { get; set; } + /// + public bool ForGroup { get; set; } - /// - public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } + /// + public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } - /// - public DateTime RequestDate { get; set; } + /// + public DateTime RequestDate { get; set; } - /// - public int ValidDaysRequested { get; set; } - } -} + /// + public int ValidDaysRequested { get; set; } +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisaValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisaValidator.cs index c8fb60a..c0d9f80 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisaValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisaValidator.cs @@ -2,12 +2,12 @@ using Domains.VisaApplicationDomain; using FluentValidation; -namespace ApplicationLayer.Services.VisaApplications.Requests.Validation +namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; + +public class PastVisaValidator : AbstractValidator { - public class PastVisaValidator : AbstractValidator + public PastVisaValidator(IDateTimeProvider dateTimeProvider) { - public PastVisaValidator(IDateTimeProvider dateTimeProvider) - { RuleFor(v => v.ExpirationDate) .NotEmpty() .WithMessage("Expiration date of past visa can not be empty") @@ -24,5 +24,4 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation .NotEmpty() .WithMessage("Name of past visa can not be empty"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisitValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisitValidator.cs index 9e46a30..6799028 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisitValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PastVisitValidator.cs @@ -3,12 +3,12 @@ using Domains; using Domains.VisaApplicationDomain; using FluentValidation; -namespace ApplicationLayer.Services.VisaApplications.Requests.Validation +namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; + +public class PastVisitValidator : AbstractValidator { - public class PastVisitValidator : AbstractValidator + public PastVisitValidator(IDateTimeProvider dateTimeProvider) { - public PastVisitValidator(IDateTimeProvider dateTimeProvider) - { RuleFor(v => v.StartDate) .NotEmpty() .WithMessage("Start date of past visit can not be empty") @@ -27,5 +27,4 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation .MaximumLength(ConfigurationConstraints.CountryNameLength) .WithMessage($"Destination Country of past visit length must be less than {ConfigurationConstraints.CountryNameLength}"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PermissionToDestCountryValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PermissionToDestCountryValidator.cs index 1116730..5404cc6 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PermissionToDestCountryValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/PermissionToDestCountryValidator.cs @@ -3,12 +3,12 @@ using Domains; using Domains.VisaApplicationDomain; using FluentValidation; -namespace ApplicationLayer.Services.VisaApplications.Requests.Validation +namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; + +public class PermissionToDestCountryValidator : AbstractValidator { - public class PermissionToDestCountryValidator : AbstractValidator + public PermissionToDestCountryValidator(IDateTimeProvider dateTimeProvider) { - public PermissionToDestCountryValidator(IDateTimeProvider dateTimeProvider) - { RuleFor(p => p!.ExpirationDate) .NotEmpty() .WithMessage("Expiration date of permission to destination Country can not be empty") @@ -21,5 +21,4 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation .MaximumLength(ConfigurationConstraints.IssuerNameLength) .WithMessage($"Issuer of permission to destination Country length must be less than {ConfigurationConstraints.IssuerNameLength}"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/ReentryPermitValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/ReentryPermitValidator.cs index ff59c98..1b1cde1 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/ReentryPermitValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/ReentryPermitValidator.cs @@ -3,12 +3,12 @@ using Domains; using Domains.VisaApplicationDomain; using FluentValidation; -namespace ApplicationLayer.Services.VisaApplications.Requests.Validation +namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; + +public class ReentryPermitValidator : AbstractValidator { - public class ReentryPermitValidator : AbstractValidator + public ReentryPermitValidator(IDateTimeProvider dateTimeProvider) { - public ReentryPermitValidator(IDateTimeProvider dateTimeProvider) - { RuleFor(p => p!.Number) .NotEmpty() .WithMessage("Re-entry permit number can not be empty") @@ -21,5 +21,4 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation .GreaterThan(dateTimeProvider.Now()) .WithMessage("Re-entry permit must not be expired"); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/VisaApplicationCreateRequestValidator.cs b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/VisaApplicationCreateRequestValidator.cs index 60be0f4..843b420 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/VisaApplicationCreateRequestValidator.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/VisaApplications/Requests/Validation/VisaApplicationCreateRequestValidator.cs @@ -4,51 +4,50 @@ using Domains; using Domains.VisaApplicationDomain; using FluentValidation; -namespace ApplicationLayer.Services.VisaApplications.Requests.Validation +namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; + +public class VisaApplicationCreateRequestValidator : AbstractValidator { - public class VisaApplicationCreateRequestValidator : AbstractValidator + public VisaApplicationCreateRequestValidator( + IValidator reentryPermitValidator, + IValidator pastVisaValidator, + IValidator permissionToDestCountryValidator, + IValidator pastVisitValidator, + IApplicantsRepository applicants, + IUserIdProvider userIdProvider) { - public VisaApplicationCreateRequestValidator( - IValidator reentryPermitValidator, - IValidator pastVisaValidator, - IValidator permissionToDestCountryValidator, - IValidator pastVisitValidator, - IApplicantsRepository applicants, - IUserIdProvider userIdProvider) - { - RuleFor(r => r.ReentryPermit) - .NotEmpty() - .WithMessage("Non-residents must provide re-entry permission") - .SetValidator(reentryPermitValidator) - .WhenAsync(async (r, ct) => - await applicants.IsApplicantNonResidentByUserId(userIdProvider.GetUserId(), ct)); + RuleFor(r => r.ReentryPermit) + .NotEmpty() + .WithMessage("Non-residents must provide re-entry permission") + .SetValidator(reentryPermitValidator) + .WhenAsync(async (r, ct) => + await applicants.IsApplicantNonResidentByUserId(userIdProvider.GetUserId(), ct)); - RuleFor(r => r.DestinationCountry) - .NotEmpty() - .WithMessage("Destination country can not be empty"); + RuleFor(r => r.DestinationCountry) + .NotEmpty() + .WithMessage("Destination country can not be empty"); - RuleFor(r => r.VisaCategory) - .IsInEnum(); + RuleFor(r => r.VisaCategory) + .IsInEnum(); - RuleFor(r => r.RequestedNumberOfEntries) - .IsInEnum(); + RuleFor(r => r.RequestedNumberOfEntries) + .IsInEnum(); - RuleFor(r => r.ValidDaysRequested) - .GreaterThan(0) - .WithMessage($"Valid days requested should be positive number and less than {ConfigurationConstraints.MaxValidDays}") - .LessThanOrEqualTo(ConfigurationConstraints.MaxValidDays) - .WithMessage($"Valid days requested must be less than or equal to {ConfigurationConstraints.MaxValidDays}"); + RuleFor(r => r.ValidDaysRequested) + .GreaterThan(0) + .WithMessage($"Valid days requested should be positive number and less than {ConfigurationConstraints.MaxValidDays}") + .LessThanOrEqualTo(ConfigurationConstraints.MaxValidDays) + .WithMessage($"Valid days requested must be less than or equal to {ConfigurationConstraints.MaxValidDays}"); - RuleForEach(r => r.PastVisas) - .SetValidator(pastVisaValidator); + RuleForEach(r => r.PastVisas) + .SetValidator(pastVisaValidator); - When(r => r.VisaCategory == VisaCategory.Transit, - () => - RuleFor(r => r.PermissionToDestCountry) - .SetValidator(permissionToDestCountryValidator)); + When(r => r.VisaCategory == VisaCategory.Transit, + () => + RuleFor(r => r.PermissionToDestCountry) + .SetValidator(permissionToDestCountryValidator)); - RuleForEach(r => r.PastVisits) - .SetValidator(pastVisitValidator); - } + RuleForEach(r => r.PastVisits) + .SetValidator(pastVisitValidator); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/ConfigurationConstraints.cs b/SchengenVisaApi/Domains/ConfigurationConstraints.cs index 7ce2f72..2ffe908 100644 --- a/SchengenVisaApi/Domains/ConfigurationConstraints.cs +++ b/SchengenVisaApi/Domains/ConfigurationConstraints.cs @@ -1,24 +1,23 @@ -namespace Domains +namespace Domains; + +public static class ConfigurationConstraints { - public static class ConfigurationConstraints - { - public const int CityNameLength = 70; - public const int CountryNameLength = 70; - public const int CitizenshipLength = 30; - public const int ReentryPermitNumberLength = 25; - public const int IssuerNameLength = 200; - public const int VisaNameLength = 70; - public const int StreetNameLength = 100; - public const int PlaceOfWorkNameLength = 200; - public const int NameLength = 50; - public const int BuildingNumberLength = 10; - public const int PassportNumberLength = 20; - public const int PhoneNumberLength = 13; - public const int PhoneNumberMinLength = 11; - public const int EmailLength = 254; - public const int PasswordLength = 50; - public const int ApplicantMinAge = 14; - public const int JobTitleLength = 50; - public const int MaxValidDays = 90; - } -} + public const int CityNameLength = 70; + public const int CountryNameLength = 70; + public const int CitizenshipLength = 30; + public const int ReentryPermitNumberLength = 25; + public const int IssuerNameLength = 200; + public const int VisaNameLength = 70; + public const int StreetNameLength = 100; + public const int PlaceOfWorkNameLength = 200; + public const int NameLength = 50; + public const int BuildingNumberLength = 10; + public const int PassportNumberLength = 20; + public const int PhoneNumberLength = 13; + public const int PhoneNumberMinLength = 11; + public const int EmailLength = 254; + public const int PasswordLength = 50; + public const int ApplicantMinAge = 14; + public const int JobTitleLength = 50; + public const int MaxValidDays = 90; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/Users/Role.cs b/SchengenVisaApi/Domains/Users/Role.cs index 38b9376..8c367e0 100644 --- a/SchengenVisaApi/Domains/Users/Role.cs +++ b/SchengenVisaApi/Domains/Users/Role.cs @@ -1,13 +1,12 @@ -namespace Domains.Users +namespace Domains.Users; + +/// Role of +public enum Role { - /// Role of - public enum Role - { - /// Requests visa applications - Applicant, - /// Approves or declines applications - ApprovingAuthority, - /// Manages approving authorities - Admin - } -} + /// Requests visa applications + Applicant, + /// Approves or declines applications + ApprovingAuthority, + /// Manages approving authorities + Admin +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/Users/User.cs b/SchengenVisaApi/Domains/Users/User.cs index 017a5b0..5457044 100644 --- a/SchengenVisaApi/Domains/Users/User.cs +++ b/SchengenVisaApi/Domains/Users/User.cs @@ -1,14 +1,13 @@ -namespace Domains.Users +namespace Domains.Users; + +public class User : IEntity { - public class User : IEntity - { - /// Unique Identifier of - public Guid Id { get; private set; } = Guid.NewGuid(); + /// Unique Identifier of + public Guid Id { get; private set; } = Guid.NewGuid(); - public Role Role { get; set; } + public Role Role { get; set; } - public string Email { get; set; } = null!; + public string Email { get; set; } = null!; - public string Password { get; set; } = null!; - } -} + public string Password { get; set; } = null!; +} \ No newline at end of file diff --git a/SchengenVisaApi/Domains/VisaApplicationDomain/ApplicationStatus.cs b/SchengenVisaApi/Domains/VisaApplicationDomain/ApplicationStatus.cs index a3978a2..b010066 100644 --- a/SchengenVisaApi/Domains/VisaApplicationDomain/ApplicationStatus.cs +++ b/SchengenVisaApi/Domains/VisaApplicationDomain/ApplicationStatus.cs @@ -1,12 +1,11 @@ -namespace Domains.VisaApplicationDomain +namespace Domains.VisaApplicationDomain; + +public enum ApplicationStatus { - public enum ApplicationStatus - { - /// Waits for approve - Pending, - Approved, - Rejected, - /// Closed by applicant - Closed - } -} + /// Waits for approve + Pending, + Approved, + Rejected, + /// Closed by applicant + Closed +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Auth/ServiceCollectionsExtensions.cs b/SchengenVisaApi/Infrastructure/Auth/ServiceCollectionsExtensions.cs index 84e523d..a823b86 100644 --- a/SchengenVisaApi/Infrastructure/Auth/ServiceCollectionsExtensions.cs +++ b/SchengenVisaApi/Infrastructure/Auth/ServiceCollectionsExtensions.cs @@ -3,12 +3,12 @@ using ApplicationLayer.InfrastructureServicesInterfaces; using ApplicationLayer.Services.AuthServices.NeededServices; using Microsoft.Extensions.DependencyInjection; -namespace Infrastructure.Auth +namespace Infrastructure.Auth; + +public static class ServiceCollectionsExtensions { - public static class ServiceCollectionsExtensions + public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options) { - public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options) - { services.AddSingleton(); services.AddSingleton(provider => { @@ -20,5 +20,4 @@ namespace Infrastructure.Auth return services; } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Auth/TokenGenerator.cs b/SchengenVisaApi/Infrastructure/Auth/TokenGenerator.cs index cea5994..e6d2e1d 100644 --- a/SchengenVisaApi/Infrastructure/Auth/TokenGenerator.cs +++ b/SchengenVisaApi/Infrastructure/Auth/TokenGenerator.cs @@ -4,27 +4,26 @@ using ApplicationLayer.InfrastructureServicesInterfaces; using ApplicationLayer.Services.AuthServices.NeededServices; using Domains.Users; -namespace Infrastructure.Auth +namespace Infrastructure.Auth; + +public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) + : ITokenGenerator { - public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) - : ITokenGenerator + public string CreateToken(User user) { - public string CreateToken(User user) + var claims = new List { - var claims = new List - { - new(ClaimTypes.Role, user.Role.ToString()), - new(ClaimTypes.NameIdentifier, user.Id.ToString()) - }; + new(ClaimTypes.Role, user.Role.ToString()), + new(ClaimTypes.NameIdentifier, user.Id.ToString()) + }; - var token = new JwtSecurityToken( - issuer: options.Issuer, - audience: options.Audience, - expires: dateTimeProvider.Now().Add(options.ValidTime), - signingCredentials: options.Credentials, - claims: claims); + var token = new JwtSecurityToken( + issuer: options.Issuer, + audience: options.Audience, + expires: dateTimeProvider.Now().Add(options.ValidTime), + signingCredentials: options.Credentials, + claims: claims); - return tokenHandler.WriteToken(token); - } + return tokenHandler.WriteToken(token); } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Auth/TokenGeneratorOptions.cs b/SchengenVisaApi/Infrastructure/Auth/TokenGeneratorOptions.cs index b12b8b2..1a1b9c6 100644 --- a/SchengenVisaApi/Infrastructure/Auth/TokenGeneratorOptions.cs +++ b/SchengenVisaApi/Infrastructure/Auth/TokenGeneratorOptions.cs @@ -1,6 +1,5 @@ using Microsoft.IdentityModel.Tokens; -namespace Infrastructure.Auth -{ - public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials); -} +namespace Infrastructure.Auth; + +public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials); \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs index 5344f7a..7075996 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs @@ -3,12 +3,12 @@ using ApplicationLayer.Services.AuthServices.Requests; using AutoMapper; using Domains.ApplicantDomain; -namespace Infrastructure.Automapper.Profiles +namespace Infrastructure.Automapper.Profiles; + +public class ApplicantProfile : Profile { - public class ApplicantProfile : Profile + public ApplicantProfile() { - public ApplicantProfile() - { CreateMap(MemberList.Destination); CreateMap(MemberList.Destination) @@ -16,5 +16,4 @@ namespace Infrastructure.Automapper.Profiles .ForMember(a => a.Name, opts => opts.MapFrom(r => r.ApplicantName)); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs index 56a27a0..ea276dd 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs @@ -2,15 +2,14 @@ using AutoMapper; using Domains.ApplicantDomain; -namespace Infrastructure.Automapper.Profiles +namespace Infrastructure.Automapper.Profiles; + +public class PlaceOfWorkProfile : Profile { - public class PlaceOfWorkProfile : Profile + public PlaceOfWorkProfile() { - public PlaceOfWorkProfile() - { CreateMap(MemberList.Destination) .ForMember(p => p.Id, opts => opts.UseDestinationValue()); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs index ce21f66..0b12a78 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs @@ -2,15 +2,14 @@ using AutoMapper; using Domains.Users; -namespace Infrastructure.Automapper.Profiles +namespace Infrastructure.Automapper.Profiles; + +public class UserProfile : Profile { - public class UserProfile : Profile + public UserProfile() { - public UserProfile() - { CreateMap(MemberList.Destination) .ForMember(u => u.Role, opts => opts.Ignore()); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs index d274a03..81f5367 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs @@ -3,12 +3,12 @@ using ApplicationLayer.Services.VisaApplications.Requests; using AutoMapper; using Domains.VisaApplicationDomain; -namespace Infrastructure.Automapper.Profiles +namespace Infrastructure.Automapper.Profiles; + +public class VisaApplicationProfile : Profile { - public class VisaApplicationProfile : Profile + public VisaApplicationProfile() { - public VisaApplicationProfile() - { CreateMap(MemberList.Destination); CreateMap(MemberList.Destination) @@ -21,5 +21,4 @@ namespace Infrastructure.Automapper.Profiles .ForMember(va => va.ApplicantId, opts => opts.Ignore()); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Common/DateTimeProvider.cs b/SchengenVisaApi/Infrastructure/Common/DateTimeProvider.cs index 2db90fb..ad52077 100644 --- a/SchengenVisaApi/Infrastructure/Common/DateTimeProvider.cs +++ b/SchengenVisaApi/Infrastructure/Common/DateTimeProvider.cs @@ -1,10 +1,9 @@ using ApplicationLayer.InfrastructureServicesInterfaces; -namespace Infrastructure.Common +namespace Infrastructure.Common; + +/// Implements +public class DateTimeProvider : IDateTimeProvider { - /// Implements - public class DateTimeProvider : IDateTimeProvider - { - DateTime IDateTimeProvider.Now() => DateTime.Now; - } -} + DateTime IDateTimeProvider.Now() => DateTime.Now; +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs b/SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs index 06e581f..8c7c180 100644 --- a/SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs +++ b/SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs @@ -2,12 +2,12 @@ using ApplicationLayer.InfrastructureServicesInterfaces; using Microsoft.AspNetCore.Http; -namespace Infrastructure.Common +namespace Infrastructure.Common; + +public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider { - public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider + Guid IUserIdProvider.GetUserId() { - Guid IUserIdProvider.GetUserId() - { var claim = contextAccessor.HttpContext!.User.Claims.SingleOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier); if (claim is null) { @@ -15,5 +15,4 @@ namespace Infrastructure.Common } return Guid.Parse(claim.Value); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/Exceptions/ApplicantNotFoundByUserIdException.cs b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/Exceptions/ApplicantNotFoundByUserIdException.cs index 79fc6d3..52cb8f3 100644 --- a/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/Exceptions/ApplicantNotFoundByUserIdException.cs +++ b/SchengenVisaApi/Infrastructure/Database/Applicants/Repositories/Exceptions/ApplicantNotFoundByUserIdException.cs @@ -1,6 +1,5 @@ using ApplicationLayer.Services.GeneralExceptions; -namespace Infrastructure.Database.Applicants.Repositories.Exceptions -{ - public class ApplicantNotFoundByUserIdException() : EntityNotFoundException("Applicant not found."); -} +namespace Infrastructure.Database.Applicants.Repositories.Exceptions; + +public class ApplicantNotFoundByUserIdException() : EntityNotFoundException("Applicant not found."); diff --git a/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs index d61c81b..3af1db2 100644 --- a/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/Users/Configuration/UserConfiguration.cs @@ -3,12 +3,12 @@ using Domains.Users; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.Users.Configuration +namespace Infrastructure.Database.Users.Configuration; + +public class UserConfiguration : IEntityTypeConfiguration { - public class UserConfiguration : IEntityTypeConfiguration + public void Configure(EntityTypeBuilder entity) { - public void Configure(EntityTypeBuilder entity) - { entity.Property(u => u.Email) .IsUnicode(false) .HasMaxLength(ConfigurationConstraints.EmailLength); @@ -19,5 +19,4 @@ namespace Infrastructure.Database.Users.Configuration .IsUnicode(false) .HasMaxLength(ConfigurationConstraints.PasswordLength); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/Users/Repositories/UsersRepository.cs b/SchengenVisaApi/Infrastructure/Database/Users/Repositories/UsersRepository.cs index 8c75cd9..de77b0a 100644 --- a/SchengenVisaApi/Infrastructure/Database/Users/Repositories/UsersRepository.cs +++ b/SchengenVisaApi/Infrastructure/Database/Users/Repositories/UsersRepository.cs @@ -3,20 +3,19 @@ using Domains.Users; using Infrastructure.Database.Generic; using Microsoft.EntityFrameworkCore; -namespace Infrastructure.Database.Users.Repositories +namespace Infrastructure.Database.Users.Repositories; + +/// +public class UsersRepository(IGenericReader reader, IGenericWriter writer) + : GenericRepository(reader, writer), IUsersRepository { - /// - public class UsersRepository(IGenericReader reader, IGenericWriter writer) - : GenericRepository(reader, writer), IUsersRepository + async Task IUsersRepository.FindByEmailAsync(string email, CancellationToken cancellationToken) { - async Task IUsersRepository.FindByEmailAsync(string email, CancellationToken cancellationToken) - { return await LoadDomain().SingleOrDefaultAsync(u => u.Email == email, cancellationToken); } - async Task> IUsersRepository.GetAllOfRoleAsync(Role role, CancellationToken cancellationToken) - { + async Task> IUsersRepository.GetAllOfRoleAsync(Role role, CancellationToken cancellationToken) + { return await LoadDomain().Where(u => u.Role == role).ToListAsync(cancellationToken); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs index 0f8f574..adc40d9 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Configuration/PastVisitConfiguration.cs @@ -2,15 +2,14 @@ using Domains.VisaApplicationDomain; using Microsoft.EntityFrameworkCore.Metadata.Builders; -namespace Infrastructure.Database.VisaApplications.Configuration +namespace Infrastructure.Database.VisaApplications.Configuration; + +public static class PastVisitConfiguration where T : class, IEntity { - public static class PastVisitConfiguration where T : class, IEntity + public static void Configure(OwnedNavigationBuilder entity) { - public static void Configure(OwnedNavigationBuilder entity) - { entity.Property(pv => pv.DestinationCountry) .IsUnicode(false) .HasMaxLength(ConfigurationConstraints.CountryNameLength); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/Exceptions/ApplicationNotFoundByApplicantAndApplicationIdException.cs b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/Exceptions/ApplicationNotFoundByApplicantAndApplicationIdException.cs index b8d1241..d148c8f 100644 --- a/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/Exceptions/ApplicationNotFoundByApplicantAndApplicationIdException.cs +++ b/SchengenVisaApi/Infrastructure/Database/VisaApplications/Repositories/Exceptions/ApplicationNotFoundByApplicantAndApplicationIdException.cs @@ -1,7 +1,6 @@ using ApplicationLayer.Services.GeneralExceptions; -namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions -{ - public class ApplicationNotFoundByApplicantAndApplicationIdException(Guid applicationId) - : EntityNotFoundException($"Application with id {applicationId} not found for authenticated user"); -} +namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions; + +public class ApplicationNotFoundByApplicantAndApplicationIdException(Guid applicationId) + : EntityNotFoundException($"Application with id {applicationId} not found for authenticated user"); \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/Common/ConfigureSwaggerOptions.cs b/SchengenVisaApi/SchengenVisaApi/Common/ConfigureSwaggerOptions.cs index fbfefec..4c7da47 100644 --- a/SchengenVisaApi/SchengenVisaApi/Common/ConfigureSwaggerOptions.cs +++ b/SchengenVisaApi/SchengenVisaApi/Common/ConfigureSwaggerOptions.cs @@ -2,13 +2,13 @@ using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; -namespace SchengenVisaApi.Common +namespace SchengenVisaApi.Common; + +/// Adds auth for swagger +public class ConfigureSwaggerOptions : IConfigureOptions { - /// Adds auth for swagger - public class ConfigureSwaggerOptions : IConfigureOptions + void IConfigureOptions.Configure(SwaggerGenOptions options) { - void IConfigureOptions.Configure(SwaggerGenOptions options) - { options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, @@ -34,5 +34,4 @@ namespace SchengenVisaApi.Common } }); } - } -} +} \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/Common/PolicyConstants.cs b/SchengenVisaApi/SchengenVisaApi/Common/PolicyConstants.cs index 111b5bc..ec8023b 100644 --- a/SchengenVisaApi/SchengenVisaApi/Common/PolicyConstants.cs +++ b/SchengenVisaApi/SchengenVisaApi/Common/PolicyConstants.cs @@ -1,12 +1,9 @@ -namespace SchengenVisaApi.Common -{ +namespace SchengenVisaApi.Common; #pragma warning disable CS1591 - public static class PolicyConstants - { - public const string AdminPolicy = "AdminPolicy"; - public const string ApplicantPolicy = "ApplicantPolicy"; - public const string ApprovingAuthorityPolicy = "ApprovingAuthorityPolicy"; - } -#pragma warning enable CS1591 - +public static class PolicyConstants +{ + public const string AdminPolicy = "AdminPolicy"; + public const string ApplicantPolicy = "ApplicantPolicy"; + public const string ApprovingAuthorityPolicy = "ApprovingAuthorityPolicy"; } +#pragma warning enable CS1591 \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs b/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs index 45093fa..98d8baf 100644 --- a/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs +++ b/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs @@ -10,106 +10,105 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SchengenVisaApi.Common; -namespace SchengenVisaApi.Controllers +namespace SchengenVisaApi.Controllers; + +/// Controller for user-auth and registration +[ApiController] +[Route("users")] +public class UsersController( + IRegisterService registerService, + ILoginService loginService, + IUsersService usersService, + IValidator registerApplicantRequestValidator, + IValidator authDataValidator) : ControllerBase { - /// Controller for user-auth and registration - [ApiController] - [Route("users")] - public class UsersController( - IRegisterService registerService, - ILoginService loginService, - IUsersService usersService, - IValidator registerApplicantRequestValidator, - IValidator authDataValidator) : ControllerBase + /// Adds applicant with user account to DB + [HttpPost] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Route("register")] + public async Task Register(RegisterApplicantRequest request, CancellationToken cancellationToken) { - /// Adds applicant with user account to DB - [HttpPost] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status409Conflict)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [Route("register")] - public async Task Register(RegisterApplicantRequest request, CancellationToken cancellationToken) - { - await registerApplicantRequestValidator.ValidateAndThrowAsync(request, cancellationToken); + await registerApplicantRequestValidator.ValidateAndThrowAsync(request, cancellationToken); - await registerService.RegisterApplicant(request, cancellationToken); - return Ok(); - } - - /// Adds approving authority with user account to DB - /// Accessible only for admins - [HttpPost] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status409Conflict)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [Route("authorities")] - [Authorize(policy: PolicyConstants.AdminPolicy)] - public async Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken) - { - await authDataValidator.ValidateAndThrowAsync(request.AuthData, cancellationToken); - - await registerService.RegisterAuthority(request, cancellationToken); - return Ok(); - } - - /// Returns JWT-token for authentication - [HttpGet] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [Route("login")] - public async Task Login(string email, string password, CancellationToken cancellationToken) - { - var result = await loginService.LoginAsync(email, password, cancellationToken); - return Ok(result); - } - - /// Returns list of authority accounts - /// Accessible only for admins - [HttpGet] - [ProducesResponseType>(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [Route("authorities")] - [Authorize(policy: PolicyConstants.AdminPolicy)] - public async Task GetAuthorityAccounts(CancellationToken cancellationToken) - { - var result = await usersService.GetAuthoritiesAccountsAsync(cancellationToken); - return Ok(result); - } - - /// Changes authority's account authentication data - /// Accessible only for admins - [HttpPut] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [Route("authorities/{authorityAccountId:guid}")] - [Authorize(policy: PolicyConstants.AdminPolicy)] - public async Task ChangeAuthorityAuthData(Guid authorityAccountId, AuthData authData, CancellationToken cancellationToken) - { - await authDataValidator.ValidateAndThrowAsync(authData, cancellationToken); - - await usersService.ChangeAccountAuthDataAsync(new ChangeUserAuthDataRequest(authorityAccountId, authData), cancellationToken); - return Ok(); - } - - /// Removes authority's account authentication data - /// Accessible only for admins - [HttpDelete] - [ProducesResponseType(StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status401Unauthorized)] - [Route("authorities/{authorityAccountId:guid}")] - [Authorize(policy: PolicyConstants.AdminPolicy)] - public async Task RemoveAuthorityAccount(Guid authorityAccountId, CancellationToken cancellationToken) - { - await usersService.RemoveUserAccount(authorityAccountId, cancellationToken); - return Ok(); - } + await registerService.RegisterApplicant(request, cancellationToken); + return Ok(); } -} + + /// Adds approving authority with user account to DB + /// Accessible only for admins + [HttpPost] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status409Conflict)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Route("authorities")] + [Authorize(policy: PolicyConstants.AdminPolicy)] + public async Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken) + { + await authDataValidator.ValidateAndThrowAsync(request.AuthData, cancellationToken); + + await registerService.RegisterAuthority(request, cancellationToken); + return Ok(); + } + + /// Returns JWT-token for authentication + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [Route("login")] + public async Task Login(string email, string password, CancellationToken cancellationToken) + { + var result = await loginService.LoginAsync(email, password, cancellationToken); + return Ok(result); + } + + /// Returns list of authority accounts + /// Accessible only for admins + [HttpGet] + [ProducesResponseType>(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [Route("authorities")] + [Authorize(policy: PolicyConstants.AdminPolicy)] + public async Task GetAuthorityAccounts(CancellationToken cancellationToken) + { + var result = await usersService.GetAuthoritiesAccountsAsync(cancellationToken); + return Ok(result); + } + + /// Changes authority's account authentication data + /// Accessible only for admins + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [Route("authorities/{authorityAccountId:guid}")] + [Authorize(policy: PolicyConstants.AdminPolicy)] + public async Task ChangeAuthorityAuthData(Guid authorityAccountId, AuthData authData, CancellationToken cancellationToken) + { + await authDataValidator.ValidateAndThrowAsync(authData, cancellationToken); + + await usersService.ChangeAccountAuthDataAsync(new ChangeUserAuthDataRequest(authorityAccountId, authData), cancellationToken); + return Ok(); + } + + /// Removes authority's account authentication data + /// Accessible only for admins + [HttpDelete] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [Route("authorities/{authorityAccountId:guid}")] + [Authorize(policy: PolicyConstants.AdminPolicy)] + public async Task RemoveAuthorityAccount(Guid authorityAccountId, CancellationToken cancellationToken) + { + await usersService.RemoveUserAccount(authorityAccountId, cancellationToken); + return Ok(); + } +} \ No newline at end of file diff --git a/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs b/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs index 5c398ac..c365334 100644 --- a/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs +++ b/SchengenVisaApi/SchengenVisaApi/ExceptionFilters/GlobalExceptionsFilter.cs @@ -6,67 +6,66 @@ using FluentValidation; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -namespace SchengenVisaApi.ExceptionFilters +namespace SchengenVisaApi.ExceptionFilters; + +/// Handles +public class GlobalExceptionsFilter : IAsyncExceptionFilter { - /// Handles - public class GlobalExceptionsFilter : IAsyncExceptionFilter + /// + public async Task OnExceptionAsync(ExceptionContext context) { - /// - public async Task OnExceptionAsync(ExceptionContext context) + var exception = context.Exception; + var problemDetails = new ProblemDetails(); + + switch (exception) { - var exception = context.Exception; - var problemDetails = new ProblemDetails(); + case ValidationException validationException: + problemDetails.Extensions.Add("Errors", validationException.Errors.Select(e => e.ErrorMessage)); + problemDetails.Detail = "Validation errors occured"; + problemDetails.Status = StatusCodes.Status400BadRequest; + problemDetails.Title = "Bad request"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"; + break; + case ApiException: + problemDetails.Detail = exception.Message; + switch (exception) + { + case EntityNotFoundException: + problemDetails.Status = StatusCodes.Status404NotFound; + problemDetails.Title = "Requested entity not found"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4"; + break; + case IncorrectLoginDataException: + problemDetails.Status = StatusCodes.Status403Forbidden; + problemDetails.Title = "Auth failed"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.3"; + break; + case AlreadyExistsException: + problemDetails.Status = StatusCodes.Status409Conflict; + problemDetails.Title = "Already exists"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.8"; + break; + case ApplicationAlreadyProcessedException: + problemDetails.Status = StatusCodes.Status409Conflict; + problemDetails.Title = "Already processed"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.8"; + break; + default: + problemDetails.Status = StatusCodes.Status400BadRequest; + problemDetails.Title = "Bad request"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"; + break; + } - switch (exception) - { - case ValidationException validationException: - problemDetails.Extensions.Add("Errors", validationException.Errors.Select(e => e.ErrorMessage)); - problemDetails.Detail = "Validation errors occured"; - problemDetails.Status = StatusCodes.Status400BadRequest; - problemDetails.Title = "Bad request"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"; - break; - case ApiException: - problemDetails.Detail = exception.Message; - switch (exception) - { - case EntityNotFoundException: - problemDetails.Status = StatusCodes.Status404NotFound; - problemDetails.Title = "Requested entity not found"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4"; - break; - case IncorrectLoginDataException: - problemDetails.Status = StatusCodes.Status403Forbidden; - problemDetails.Title = "Auth failed"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.3"; - break; - case AlreadyExistsException: - problemDetails.Status = StatusCodes.Status409Conflict; - problemDetails.Title = "Already exists"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.8"; - break; - case ApplicationAlreadyProcessedException: - problemDetails.Status = StatusCodes.Status409Conflict; - problemDetails.Title = "Already processed"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.8"; - break; - default: - problemDetails.Status = StatusCodes.Status400BadRequest; - problemDetails.Title = "Bad request"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.1"; - break; - } - - break; - default: - problemDetails.Status = StatusCodes.Status500InternalServerError; - problemDetails.Title = "An unhandled error occured"; - problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.6.1"; - break; - } - - await Results.Problem(problemDetails).ExecuteAsync(context.HttpContext); - context.ExceptionHandled = true; + break; + default: + problemDetails.Status = StatusCodes.Status500InternalServerError; + problemDetails.Title = "An unhandled error occured"; + problemDetails.Type = "https://datatracker.ietf.org/doc/html/rfc7231#section-6.6.1"; + break; } + + await Results.Problem(problemDetails).ExecuteAsync(context.HttpContext); + context.ExceptionHandled = true; } -} +} \ No newline at end of file