@@ -1,4 +1,3 @@
|
||||
namespace ApplicationLayer.GeneralExceptions
|
||||
{
|
||||
namespace ApplicationLayer.GeneralExceptions;
|
||||
|
||||
public class AlreadyExistsException(string message) : ApiException(message);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
namespace ApplicationLayer.GeneralExceptions
|
||||
{
|
||||
namespace ApplicationLayer.GeneralExceptions;
|
||||
|
||||
public class ApiException(string message) : Exception(message);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace ApplicationLayer.InfrastructureServicesInterfaces
|
||||
{
|
||||
namespace ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
|
||||
public interface IDateTimeProvider
|
||||
{
|
||||
/// Returns current date and time
|
||||
DateTime Now();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace ApplicationLayer.InfrastructureServicesInterfaces
|
||||
{
|
||||
namespace ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
|
||||
public interface IUserIdProvider
|
||||
{
|
||||
/// Returns identifier of authenticated user who sent the request
|
||||
Guid GetUserId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.Applicants.Models
|
||||
{
|
||||
namespace ApplicationLayer.Services.Applicants.Models;
|
||||
|
||||
/// Model of <see cref="Applicant"/>
|
||||
public class ApplicantModel
|
||||
{
|
||||
@@ -47,4 +47,3 @@ namespace ApplicationLayer.Services.Applicants.Models
|
||||
/// <inheritdoc cref="Applicant.IsNonResident"/>
|
||||
public bool IsNonResident { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.Applicants.Models
|
||||
{
|
||||
namespace ApplicationLayer.Services.Applicants.Models;
|
||||
|
||||
public class PlaceOfWorkModel
|
||||
{
|
||||
/// Name of hirer
|
||||
@@ -13,4 +13,3 @@ namespace ApplicationLayer.Services.Applicants.Models
|
||||
/// Phone number of hirer
|
||||
public string PhoneNum { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
namespace ApplicationLayer.Services.AuthServices.Common
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.Common;
|
||||
|
||||
public record AuthData(string Email, string Password);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
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
|
||||
{
|
||||
async Task<string> ILoginService.LoginAsync(string email, string password, CancellationToken cancellationToken)
|
||||
@@ -24,4 +24,3 @@ namespace ApplicationLayer.Services.AuthServices.LoginService
|
||||
return tokenGenerator.CreateToken(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ApplicationLayer.GeneralExceptions;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.LoginService.Exceptions
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.LoginService.Exceptions;
|
||||
|
||||
public class IncorrectLoginDataException() : ApiException("Incorrect email or password");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace ApplicationLayer.Services.AuthServices.LoginService
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.LoginService;
|
||||
|
||||
/// Handles login requests
|
||||
public interface ILoginService
|
||||
{
|
||||
@@ -7,4 +7,3 @@
|
||||
/// <returns>JWT-token</returns>
|
||||
Task<string> LoginAsync(string email, string password, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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
|
||||
{
|
||||
@@ -17,4 +17,3 @@ namespace ApplicationLayer.Services.AuthServices.LoginService
|
||||
return tokenGenerator.CreateToken(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using Domains.Users;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.NeededServices
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.NeededServices;
|
||||
|
||||
/// Generates jwt-tokens
|
||||
public interface ITokenGenerator
|
||||
{
|
||||
/// returns jwt-token for specific user
|
||||
string CreateToken(User user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using Domains.Users;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.NeededServices
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.NeededServices;
|
||||
|
||||
/// Repository pattern for <see cref="User"/>
|
||||
public interface IUsersRepository : IGenericRepository<User>
|
||||
{
|
||||
@@ -18,4 +18,3 @@ namespace ApplicationLayer.Services.AuthServices.NeededServices
|
||||
/// <returns>list of accounts</returns>
|
||||
Task<List<User>> GetAllOfRoleAsync(Role role, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using ApplicationLayer.Services.AuthServices.Requests;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.RegisterService
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.RegisterService;
|
||||
|
||||
/// Handles register request
|
||||
public interface IRegisterService
|
||||
{
|
||||
@@ -11,4 +11,3 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService
|
||||
/// Handles <see cref="RegisterRequest"/> and adds approving authority account
|
||||
Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ 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,
|
||||
@@ -39,4 +39,3 @@ namespace ApplicationLayer.Services.AuthServices.RegisterService
|
||||
await unitOfWork.SaveAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using ApplicationLayer.Services.AuthServices.Common;
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests;
|
||||
|
||||
public record RegisterApplicantRequest(
|
||||
AuthData AuthData,
|
||||
Name ApplicantName,
|
||||
@@ -20,4 +20,3 @@ namespace ApplicationLayer.Services.AuthServices.Requests
|
||||
string JobTitle,
|
||||
PlaceOfWorkModel PlaceOfWork,
|
||||
bool IsNonResident) : RegisterRequest(AuthData);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ApplicationLayer.Services.AuthServices.Common;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests;
|
||||
|
||||
public record RegisterRequest(AuthData AuthData);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ 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 AuthDataValidator(IUsersRepository users)
|
||||
@@ -29,4 +29,3 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
.WithMessage($"Password length must be less than {ConfigurationConstraints.PasswordLength}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using Domains.ApplicantDomain;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests.Validation;
|
||||
|
||||
public class NameValidator : AbstractValidator<Name>
|
||||
{
|
||||
public NameValidator()
|
||||
@@ -25,4 +25,3 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
.WithMessage($"Patronymic length must be less than {ConfigurationConstraints.NameLength}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ 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 PassportValidator(IDateTimeProvider dateTimeProvider)
|
||||
@@ -34,4 +34,3 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
.WithMessage("Passport issue date must be in past");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using Domains;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.AuthServices.Requests.Validation;
|
||||
|
||||
public class PlaceOfWorkModelValidator : AbstractValidator<PlaceOfWorkModel>
|
||||
{
|
||||
public PlaceOfWorkModelValidator()
|
||||
@@ -47,4 +47,3 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
.WithMessage($"Building of place of work length must be less than {ConfigurationConstraints.BuildingNumberLength}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ 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 RegisterApplicantRequestValidator(
|
||||
@@ -75,4 +75,3 @@ namespace ApplicationLayer.Services.AuthServices.Requests.Validation
|
||||
.SetValidator(placeOfWorkModelValidator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using ApplicationLayer.Services.Users.Requests;
|
||||
using Domains.Users;
|
||||
|
||||
namespace ApplicationLayer.Services.Users
|
||||
{
|
||||
namespace ApplicationLayer.Services.Users;
|
||||
|
||||
/// user accounts service
|
||||
public interface IUsersService
|
||||
{
|
||||
@@ -20,4 +20,3 @@ namespace ApplicationLayer.Services.Users
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
Task RemoveUserAccount(Guid userId, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ApplicationLayer.Services.AuthServices.Common;
|
||||
|
||||
namespace ApplicationLayer.Services.Users.Requests
|
||||
{
|
||||
namespace ApplicationLayer.Services.Users.Requests;
|
||||
|
||||
public record ChangeUserAuthDataRequest(Guid UserId, AuthData NewAuthData);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ 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
|
||||
{
|
||||
async Task<List<User>> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken)
|
||||
@@ -31,4 +31,3 @@ namespace ApplicationLayer.Services.Users
|
||||
await unitOfWork.SaveAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ApplicationLayer.GeneralExceptions;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Exceptions
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Exceptions;
|
||||
|
||||
public class ApplicationAlreadyProcessedException() : ApiException("This application already processed or closed by applicant.");
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ public interface IVisaApplicationRequestsHandler
|
||||
Task<List<VisaApplicationModelForAuthority>> GetAllAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// Returns all applications of one applicant
|
||||
Task<List<VisaApplicationModelForApplicant>> GetForApplicantAsync(Guid userId, CancellationToken cancellationToken);
|
||||
Task<List<VisaApplicationModelForApplicant>> GetForApplicantAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// Creates application for applicant with specific user identifier
|
||||
Task HandleCreateRequestAsync(Guid userId, VisaApplicationCreateRequest request, CancellationToken cancellationToken);
|
||||
Task HandleCreateRequestAsync(VisaApplicationCreateRequest request, CancellationToken cancellationToken);
|
||||
|
||||
/// Sets application status to closed
|
||||
Task HandleCloseRequestAsync(Guid userId, Guid applicationId, CancellationToken cancellationToken);
|
||||
Task HandleCloseRequestAsync(Guid applicationId, CancellationToken cancellationToken);
|
||||
|
||||
Task SetApplicationStatusFromAuthorityAsync(Guid applicationId, AuthorityRequestStatuses status, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ public class VisaApplicationRequestsHandler(
|
||||
IApplicantsRepository applicants,
|
||||
IUnitOfWork unitOfWork,
|
||||
IMapper mapper,
|
||||
IDateTimeProvider dateTimeProvider) : IVisaApplicationRequestsHandler
|
||||
IDateTimeProvider dateTimeProvider,
|
||||
IUserIdProvider userIdProvider) : IVisaApplicationRequestsHandler
|
||||
{
|
||||
async Task<List<VisaApplicationModelForAuthority>> IVisaApplicationRequestsHandler.GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -40,16 +41,16 @@ public class VisaApplicationRequestsHandler(
|
||||
return model;
|
||||
}
|
||||
|
||||
public async Task<List<VisaApplicationModelForApplicant>> GetForApplicantAsync(Guid userId, CancellationToken cancellationToken)
|
||||
public async Task<List<VisaApplicationModelForApplicant>> GetForApplicantAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var applicantId = await applicants.GetApplicantIdByUserId(userId, cancellationToken);
|
||||
var applicantId = await applicants.GetApplicantIdByUserId(userIdProvider.GetUserId(), cancellationToken);
|
||||
var visaApplications = await applications.GetOfApplicantAsync(applicantId, cancellationToken);
|
||||
return mapper.Map<List<VisaApplicationModelForApplicant>>(visaApplications);
|
||||
}
|
||||
|
||||
public async Task HandleCreateRequestAsync(Guid userId, VisaApplicationCreateRequest request, CancellationToken cancellationToken)
|
||||
public async Task HandleCreateRequestAsync(VisaApplicationCreateRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var applicant = await applicants.FindByUserIdAsync(userId, cancellationToken);
|
||||
var applicant = await applicants.FindByUserIdAsync(userIdProvider.GetUserId(), cancellationToken);
|
||||
|
||||
var visaApplication = mapper.Map<VisaApplication>(request);
|
||||
visaApplication.RequestDate = dateTimeProvider.Now();
|
||||
@@ -60,9 +61,9 @@ public class VisaApplicationRequestsHandler(
|
||||
await unitOfWork.SaveAsync(cancellationToken);
|
||||
}
|
||||
|
||||
async Task IVisaApplicationRequestsHandler.HandleCloseRequestAsync(Guid userId, Guid applicationId, CancellationToken cancellationToken)
|
||||
async Task IVisaApplicationRequestsHandler.HandleCloseRequestAsync(Guid applicationId, CancellationToken cancellationToken)
|
||||
{
|
||||
var applicantId = await applicants.GetApplicantIdByUserId(userId, cancellationToken);
|
||||
var applicantId = await applicants.GetApplicantIdByUserId(userIdProvider.GetUserId(), cancellationToken);
|
||||
var application = await applications.GetByApplicantAndApplicationIdAsync(applicantId, applicationId, cancellationToken);
|
||||
|
||||
application.Status = ApplicationStatus.Closed;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models;
|
||||
|
||||
public enum AuthorityRequestStatuses
|
||||
{
|
||||
Approved,
|
||||
Rejected
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models;
|
||||
|
||||
/// Model of <see cref="VisaApplication"/>
|
||||
public class VisaApplicationModelForApplicant
|
||||
{
|
||||
@@ -41,4 +41,3 @@ namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
/// <inheritdoc cref="VisaApplication.ValidDaysRequested"/>
|
||||
public int ValidDaysRequested { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using ApplicationLayer.Services.Applicants.Models;
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Models;
|
||||
|
||||
/// Model of <see cref="VisaApplication"/> with applicant property
|
||||
public class VisaApplicationModelForAuthority
|
||||
{
|
||||
@@ -44,4 +44,3 @@ namespace ApplicationLayer.Services.VisaApplications.Models
|
||||
/// <inheritdoc cref="VisaApplication.ValidDaysRequested"/>
|
||||
public int ValidDaysRequested { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using Domains.VisaApplicationDomain;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation;
|
||||
|
||||
public class PastVisaValidator : AbstractValidator<PastVisa>
|
||||
{
|
||||
public PastVisaValidator(IDateTimeProvider dateTimeProvider)
|
||||
@@ -25,4 +25,3 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
.WithMessage("Name of past visa can not be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using Domains;
|
||||
using Domains.VisaApplicationDomain;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation;
|
||||
|
||||
public class PastVisitValidator : AbstractValidator<PastVisit>
|
||||
{
|
||||
public PastVisitValidator(IDateTimeProvider dateTimeProvider)
|
||||
@@ -28,4 +28,3 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
.WithMessage($"Destination Country of past visit length must be less than {ConfigurationConstraints.CountryNameLength}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using Domains;
|
||||
using Domains.VisaApplicationDomain;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation;
|
||||
|
||||
public class PermissionToDestCountryValidator : AbstractValidator<PermissionToDestCountry?>
|
||||
{
|
||||
public PermissionToDestCountryValidator(IDateTimeProvider dateTimeProvider)
|
||||
@@ -22,4 +22,3 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
.WithMessage($"Issuer of permission to destination Country length must be less than {ConfigurationConstraints.IssuerNameLength}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using Domains;
|
||||
using Domains.VisaApplicationDomain;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation;
|
||||
|
||||
public class ReentryPermitValidator : AbstractValidator<ReentryPermit?>
|
||||
{
|
||||
public ReentryPermitValidator(IDateTimeProvider dateTimeProvider)
|
||||
@@ -22,4 +22,3 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
.WithMessage("Re-entry permit must not be expired");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ using Domains;
|
||||
using Domains.VisaApplicationDomain;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
{
|
||||
namespace ApplicationLayer.Services.VisaApplications.Requests.Validation;
|
||||
|
||||
public class VisaApplicationCreateRequestValidator : AbstractValidator<VisaApplicationCreateRequest>
|
||||
{
|
||||
public VisaApplicationCreateRequestValidator(
|
||||
@@ -20,7 +20,7 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
.NotEmpty()
|
||||
.WithMessage("Non-residents must provide re-entry permission")
|
||||
.SetValidator(reentryPermitValidator)
|
||||
.WhenAsync(async (r, ct) =>
|
||||
.WhenAsync(async (_, ct) =>
|
||||
await applicants.IsApplicantNonResidentByUserId(userIdProvider.GetUserId(), ct));
|
||||
|
||||
RuleFor(r => r.DestinationCountry)
|
||||
@@ -51,4 +51,3 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation
|
||||
.SetValidator(pastVisitValidator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Domains
|
||||
{
|
||||
namespace Domains;
|
||||
|
||||
public static class ConfigurationConstraints
|
||||
{
|
||||
public const int CityNameLength = 70;
|
||||
@@ -21,4 +21,3 @@
|
||||
public const int JobTitleLength = 50;
|
||||
public const int MaxValidDays = 90;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Domains.Users
|
||||
{
|
||||
namespace Domains.Users;
|
||||
|
||||
/// Role of <see cref="User"/>
|
||||
public enum Role
|
||||
{
|
||||
@@ -10,4 +10,3 @@
|
||||
/// Manages approving authorities
|
||||
Admin
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Domains.Users
|
||||
{
|
||||
namespace Domains.Users;
|
||||
|
||||
public class User : IEntity
|
||||
{
|
||||
/// Unique Identifier of <see cref="User"/>
|
||||
@@ -11,4 +11,3 @@
|
||||
|
||||
public string Password { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace Domains.VisaApplicationDomain
|
||||
{
|
||||
namespace Domains.VisaApplicationDomain;
|
||||
|
||||
public enum ApplicationStatus
|
||||
{
|
||||
/// Waits for approve
|
||||
@@ -9,4 +9,3 @@
|
||||
/// Closed by applicant
|
||||
Closed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using ApplicationLayer.Services.AuthServices.NeededServices;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Infrastructure.Auth
|
||||
{
|
||||
public static class ServiceCollectionsExtensions
|
||||
namespace Infrastructure.Auth;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options)
|
||||
{
|
||||
@@ -21,4 +21,3 @@ namespace Infrastructure.Auth
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,16 @@ using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using ApplicationLayer.Services.AuthServices.NeededServices;
|
||||
using Domains.Users;
|
||||
|
||||
namespace Infrastructure.Auth
|
||||
{
|
||||
namespace Infrastructure.Auth;
|
||||
|
||||
/// <inheritdoc cref="ITokenGenerator"/>
|
||||
/// <param name="options">options kind of one in authorization registration in DI methods</param>
|
||||
/// <param name="tokenHandler">token handler</param>
|
||||
/// <param name="dateTimeProvider">date time provider</param>
|
||||
public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider)
|
||||
: ITokenGenerator
|
||||
{
|
||||
/// <inheritdoc cref="ITokenGenerator.CreateToken"/>
|
||||
public string CreateToken(User user)
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
@@ -27,4 +32,3 @@ namespace Infrastructure.Auth
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace Infrastructure.Auth
|
||||
{
|
||||
namespace Infrastructure.Auth;
|
||||
|
||||
public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using ApplicationLayer.Services.AuthServices.Requests;
|
||||
using AutoMapper;
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace Infrastructure.Automapper.Profiles
|
||||
{
|
||||
namespace Infrastructure.Automapper.Profiles;
|
||||
|
||||
public class ApplicantProfile : Profile
|
||||
{
|
||||
public ApplicantProfile()
|
||||
@@ -17,4 +17,3 @@ namespace Infrastructure.Automapper.Profiles
|
||||
opts => opts.MapFrom(r => r.ApplicantName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using AutoMapper;
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace Infrastructure.Automapper.Profiles
|
||||
{
|
||||
namespace Infrastructure.Automapper.Profiles;
|
||||
|
||||
public class PlaceOfWorkProfile : Profile
|
||||
{
|
||||
public PlaceOfWorkProfile()
|
||||
@@ -13,4 +13,3 @@ namespace Infrastructure.Automapper.Profiles
|
||||
opts => opts.UseDestinationValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using AutoMapper;
|
||||
using Domains.Users;
|
||||
|
||||
namespace Infrastructure.Automapper.Profiles
|
||||
{
|
||||
namespace Infrastructure.Automapper.Profiles;
|
||||
|
||||
public class UserProfile : Profile
|
||||
{
|
||||
public UserProfile()
|
||||
@@ -13,4 +13,3 @@ namespace Infrastructure.Automapper.Profiles
|
||||
opts => opts.Ignore());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using ApplicationLayer.Services.VisaApplications.Requests;
|
||||
using AutoMapper;
|
||||
using Domains.VisaApplicationDomain;
|
||||
|
||||
namespace Infrastructure.Automapper.Profiles
|
||||
{
|
||||
namespace Infrastructure.Automapper.Profiles;
|
||||
|
||||
public class VisaApplicationProfile : Profile
|
||||
{
|
||||
public VisaApplicationProfile()
|
||||
@@ -22,4 +22,3 @@ namespace Infrastructure.Automapper.Profiles
|
||||
opts => opts.Ignore());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
|
||||
namespace Infrastructure.Common
|
||||
{
|
||||
namespace Infrastructure.Common;
|
||||
|
||||
/// Implements <see cref="IDateTimeProvider"/>
|
||||
public class DateTimeProvider : IDateTimeProvider
|
||||
{
|
||||
DateTime IDateTimeProvider.Now() => DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Infrastructure.Common
|
||||
{
|
||||
namespace Infrastructure.Common;
|
||||
|
||||
public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider
|
||||
{
|
||||
Guid IUserIdProvider.GetUserId()
|
||||
@@ -16,4 +16,3 @@ namespace Infrastructure.Common
|
||||
return Guid.Parse(claim.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ApplicationLayer.Services.GeneralExceptions;
|
||||
|
||||
namespace Infrastructure.Database.Applicants.Repositories.Exceptions
|
||||
{
|
||||
namespace Infrastructure.Database.Applicants.Repositories.Exceptions;
|
||||
|
||||
public class ApplicantNotFoundByUserIdException() : EntityNotFoundException("Applicant not found.");
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ 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<User>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<User> entity)
|
||||
@@ -20,4 +20,3 @@ namespace Infrastructure.Database.Users.Configuration
|
||||
.HasMaxLength(ConfigurationConstraints.PasswordLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using Domains.Users;
|
||||
using Infrastructure.Database.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Database.Users.Repositories
|
||||
{
|
||||
namespace Infrastructure.Database.Users.Repositories;
|
||||
|
||||
/// <inheritdoc cref="IUsersRepository"/>
|
||||
public class UsersRepository(IGenericReader reader, IGenericWriter writer)
|
||||
: GenericRepository<User>(reader, writer), IUsersRepository
|
||||
@@ -19,4 +19,3 @@ namespace Infrastructure.Database.Users.Repositories
|
||||
return await LoadDomain().Where(u => u.Role == role).ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using Domains.VisaApplicationDomain;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Infrastructure.Database.VisaApplications.Configuration
|
||||
{
|
||||
namespace Infrastructure.Database.VisaApplications.Configuration;
|
||||
|
||||
public static class PastVisitConfiguration<T> where T : class, IEntity
|
||||
{
|
||||
public static void Configure(OwnedNavigationBuilder<T, PastVisit> entity)
|
||||
@@ -13,4 +13,3 @@ namespace Infrastructure.Database.VisaApplications.Configuration
|
||||
.HasMaxLength(ConfigurationConstraints.CountryNameLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using ApplicationLayer.Services.GeneralExceptions;
|
||||
|
||||
namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions
|
||||
{
|
||||
namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions;
|
||||
|
||||
public class ApplicationNotFoundByApplicantAndApplicationIdException(Guid applicationId)
|
||||
: EntityNotFoundException($"Application with id {applicationId} not found for authenticated user");
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace SchengenVisaApi.Common
|
||||
{
|
||||
namespace SchengenVisaApi.Common;
|
||||
|
||||
/// Adds auth for swagger
|
||||
public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions>
|
||||
{
|
||||
@@ -35,4 +35,3 @@ namespace SchengenVisaApi.Common
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
namespace SchengenVisaApi.Common
|
||||
{
|
||||
namespace SchengenVisaApi.Common;
|
||||
#pragma warning disable CS1591
|
||||
public static class PolicyConstants
|
||||
{
|
||||
@@ -8,5 +7,3 @@
|
||||
public const string ApprovingAuthorityPolicy = "ApprovingAuthorityPolicy";
|
||||
}
|
||||
#pragma warning enable CS1591
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SchengenVisaApi.Common;
|
||||
|
||||
namespace SchengenVisaApi.Controllers
|
||||
{
|
||||
namespace SchengenVisaApi.Controllers;
|
||||
|
||||
///<summary> Controller for user-auth and registration </summary>
|
||||
[ApiController]
|
||||
[Route("users")]
|
||||
@@ -112,4 +112,3 @@ namespace SchengenVisaApi.Controllers
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using ApplicationLayer.Services.VisaApplications.Handlers;
|
||||
using ApplicationLayer.Services.VisaApplications.Models;
|
||||
using ApplicationLayer.Services.VisaApplications.Requests;
|
||||
@@ -14,7 +13,6 @@ namespace SchengenVisaApi.Controllers;
|
||||
[Route("visaApplications")]
|
||||
public class VisaApplicationController(
|
||||
IVisaApplicationRequestsHandler visaApplicationRequestsHandler,
|
||||
IUserIdProvider userIdProvider,
|
||||
IValidator<VisaApplicationCreateRequest> visaApplicationCreateRequestValidator) : ControllerBase
|
||||
{
|
||||
/// <summary> Returns all applications from DB </summary>
|
||||
@@ -41,8 +39,7 @@ public class VisaApplicationController(
|
||||
[Route("OfApplicant")]
|
||||
public async Task<IActionResult> GetForApplicant(CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = userIdProvider.GetUserId();
|
||||
var result = await visaApplicationRequestsHandler.GetForApplicantAsync(userId, cancellationToken);
|
||||
var result = await visaApplicationRequestsHandler.GetForApplicantAsync(cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@@ -59,8 +56,7 @@ public class VisaApplicationController(
|
||||
{
|
||||
await visaApplicationCreateRequestValidator.ValidateAndThrowAsync(request, cancellationToken);
|
||||
|
||||
var userId = userIdProvider.GetUserId();
|
||||
await visaApplicationRequestsHandler.HandleCreateRequestAsync(userId, request, cancellationToken);
|
||||
await visaApplicationRequestsHandler.HandleCreateRequestAsync(request, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@@ -75,8 +71,7 @@ public class VisaApplicationController(
|
||||
[Route("{applicationId:guid}")]
|
||||
public async Task<IActionResult> CloseApplication(Guid applicationId, CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = userIdProvider.GetUserId();
|
||||
await visaApplicationRequestsHandler.HandleCloseRequestAsync(userId, applicationId, cancellationToken);
|
||||
await visaApplicationRequestsHandler.HandleCloseRequestAsync(applicationId, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace SchengenVisaApi.ExceptionFilters
|
||||
{
|
||||
namespace SchengenVisaApi.ExceptionFilters;
|
||||
|
||||
/// Handles <see cref="ApiException"/>
|
||||
public class GlobalExceptionsFilter : IAsyncExceptionFilter
|
||||
{
|
||||
@@ -69,4 +69,3 @@ namespace SchengenVisaApi.ExceptionFilters
|
||||
context.ExceptionHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user