Application creating but without past visas and visits
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Domains.ApplicantDomain;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Domains.ApplicantDomain;
|
||||
|
||||
namespace ApplicationLayer.Services.Applicants.Models;
|
||||
|
||||
@@ -6,44 +7,58 @@ namespace ApplicationLayer.Services.Applicants.Models;
|
||||
public class ApplicantModel
|
||||
{
|
||||
/// <inheritdoc cref="Applicant.Name" />
|
||||
[Required]
|
||||
public NameModel Name { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.Passport" />
|
||||
[Required]
|
||||
public PassportModel Passport { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.BirthDate" />
|
||||
[Required]
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
/// <inheritdoc cref="Applicant.CountryOfBirth" />
|
||||
[Required]
|
||||
public string CountryOfBirth { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.CityOfBirth" />
|
||||
[Required]
|
||||
public string CityOfBirth { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.Citizenship" />
|
||||
[Required]
|
||||
public string Citizenship { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.CitizenshipByBirth" />
|
||||
[Required]
|
||||
public string CitizenshipByBirth { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.Gender" />
|
||||
[Required]
|
||||
public Gender Gender { get; set; }
|
||||
|
||||
/// <inheritdoc cref="Applicant.MaritalStatus" />
|
||||
[Required]
|
||||
public MaritalStatus MaritalStatus { get; set; }
|
||||
|
||||
/// <inheritdoc cref="Applicant.FatherName" />
|
||||
[Required]
|
||||
public NameModel FatherName { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.MotherName" />
|
||||
[Required]
|
||||
public NameModel MotherName { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.JobTitle" />
|
||||
[Required]
|
||||
public string JobTitle { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.PlaceOfWork" />
|
||||
[Required]
|
||||
public PlaceOfWorkModel PlaceOfWork { get; set; } = null!;
|
||||
|
||||
/// <inheritdoc cref="Applicant.IsNonResident" />
|
||||
[Required]
|
||||
public bool IsNonResident { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ApplicationLayer.Services.Users.Models;
|
||||
using ApplicationLayer.Services.Applicants.Models;
|
||||
using ApplicationLayer.Services.Users.Models;
|
||||
using ApplicationLayer.Services.Users.Requests;
|
||||
|
||||
namespace ApplicationLayer.Services.Users;
|
||||
@@ -19,4 +20,8 @@ public interface IUsersService
|
||||
/// <param name="userId">Identifier of account</param>
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
Task RemoveAuthorityAccount(Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
/// Get applicant that made request
|
||||
/// <param name="cancellationToken">cancellation token</param>
|
||||
Task<ApplicantModel> GetAuthenticatedApplicant(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using ApplicationLayer.InfrastructureServicesInterfaces;
|
||||
using ApplicationLayer.Services.Applicants.Models;
|
||||
using ApplicationLayer.Services.Applicants.NeededServices;
|
||||
using ApplicationLayer.Services.AuthServices.Common;
|
||||
using ApplicationLayer.Services.AuthServices.NeededServices;
|
||||
using ApplicationLayer.Services.Users.Exceptions;
|
||||
@@ -9,7 +11,12 @@ using Domains.Users;
|
||||
|
||||
namespace ApplicationLayer.Services.Users;
|
||||
|
||||
public class UsersService(IMapper mapper, IUsersRepository users, IUnitOfWork unitOfWork) : IUsersService
|
||||
public class UsersService(
|
||||
IMapper mapper,
|
||||
IUserIdProvider userIdProvider,
|
||||
IUsersRepository users,
|
||||
IApplicantsRepository applicants,
|
||||
IUnitOfWork unitOfWork) : IUsersService
|
||||
{
|
||||
async Task<List<UserModel>> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -35,6 +42,13 @@ public class UsersService(IMapper mapper, IUsersRepository users, IUnitOfWork un
|
||||
await RemoveUserAccount(user, cancellationToken);
|
||||
}
|
||||
|
||||
async Task<ApplicantModel> IUsersService.GetAuthenticatedApplicant(CancellationToken cancellationToken)
|
||||
{
|
||||
var applicant = await applicants.FindByUserIdAsync(userIdProvider.GetUserId(), cancellationToken);
|
||||
|
||||
return mapper.Map<ApplicantModel>(applicant);
|
||||
}
|
||||
|
||||
/// Updates user account auth data
|
||||
/// <param name="user">User to remove</param>
|
||||
/// <param name="authData">New auth data</param>
|
||||
|
||||
@@ -7,9 +7,11 @@ namespace ApplicationLayer.Services.VisaApplications.Models;
|
||||
public class PermissionToDestCountryModel
|
||||
{
|
||||
/// Date when permission to destination country expires
|
||||
[Required]
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
|
||||
/// Issuing authority
|
||||
[MaxLength(ConfigurationConstraints.IssuerNameLength)]
|
||||
[Required]
|
||||
public string Issuer { get; set; } = null!;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ public class ReentryPermitModel
|
||||
{
|
||||
/// Number of re-entry permit
|
||||
[MaxLength(ConfigurationConstraints.ReentryPermitNumberLength)]
|
||||
[Required]
|
||||
public string Number { get; set; } = null!;
|
||||
|
||||
/// Date when re-entry permit expires
|
||||
[Required]
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
Expiration date:<br/>
|
||||
<InputDate DisplayName="Expiration date of permission to destination Country" class="rounded"
|
||||
@bind-Value="PermissionToDestCountry.ExpirationDate"
|
||||
max="@formattedDate"/>
|
||||
min="@formattedDate"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => PermissionToDestCountry.ExpirationDate"></ValidationMessage>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
||||
@using VisaApiClient
|
||||
|
||||
<div>
|
||||
<label>
|
||||
Number:<br/>
|
||||
<InputText DisplayName="Number of re-entry permit" class="rounded"
|
||||
@bind-Value="ReentryPermit.Number"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => ReentryPermit.Number"></ValidationMessage><br/>
|
||||
|
||||
<label>
|
||||
Expiration date:<br/>
|
||||
<InputDate DisplayName="Expiration date of re-entry permit" class="rounded"
|
||||
@bind-Value="ReentryPermit.ExpirationDate"
|
||||
min="@formattedDate"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => ReentryPermit.ExpirationDate"></ValidationMessage>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private string formattedDate = null!;
|
||||
|
||||
[Parameter, EditorRequired] public ReentryPermitModel ReentryPermit { get; set; } = null!;
|
||||
|
||||
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
formattedDate = DateTimeProvider.FormattedNow();
|
||||
ReentryPermit.ExpirationDate = DateTimeProvider.Now();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<CascadingValue Value="this">
|
||||
@using System.Net
|
||||
@using VisaApiClient
|
||||
<CascadingValue Value="this">
|
||||
@ChildContent
|
||||
</CascadingValue>
|
||||
|
||||
@@ -7,8 +9,13 @@
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
[Inject] private NavigationManager Nav { get; set; } = null!;
|
||||
|
||||
public void Handle(Exception ex)
|
||||
{
|
||||
|
||||
if (ex is ApiException<ProblemDetails> { StatusCode: (int)HttpStatusCode.Unauthorized or (int)HttpStatusCode.Forbidden })
|
||||
{
|
||||
Nav.NavigateTo("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using AutoMapper;
|
||||
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
|
||||
using VisaApiClient;
|
||||
|
||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.AutoMapper.Profiles
|
||||
{
|
||||
public class VisaApplicationCreateRequestProfile : Profile
|
||||
{
|
||||
public VisaApplicationCreateRequestProfile()
|
||||
{
|
||||
CreateMap<VisaApplicationCreateRequestModel, VisaApplicationCreateRequest>(MemberList.Destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Text;
|
||||
using FluentValidation.Results;
|
||||
|
||||
namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
||||
{
|
||||
public static class ValidationResultExtensions
|
||||
{
|
||||
public static string ToErrorsString(this ValidationResult validationResult)
|
||||
=> ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage));
|
||||
|
||||
private static string ErrorsToString(IEnumerable<string> errors)
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
foreach (var error in errors)
|
||||
{
|
||||
stringBuilder.Append($"{error}<br/>");
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
|
||||
public interface IUserDataProvider
|
||||
{
|
||||
|
||||
public ApplicantModel? GetApplicant();
|
||||
public Task<ApplicantModel> GetApplicant();
|
||||
|
||||
public string? GetCurrentRole();
|
||||
}
|
||||
|
||||
@@ -8,10 +8,9 @@ namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvide
|
||||
{
|
||||
private static readonly JwtSecurityTokenHandler tokenHandler = new ();
|
||||
|
||||
public ApplicantModel? GetApplicant()
|
||||
public async Task<ApplicantModel> GetApplicant()
|
||||
{
|
||||
//todo api action
|
||||
return null;
|
||||
return await client.GetApplicantAsync();
|
||||
}
|
||||
|
||||
public string? GetCurrentRole()
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
</NavLink>
|
||||
</div>
|
||||
</nav>
|
||||
<nav class="flex-column">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="applications/new" Match="NavLinkMatch.All">
|
||||
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> New application
|
||||
</NavLink>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@page "/applications"
|
||||
@using System.Net
|
||||
@using System.Text
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
|
||||
@@ -61,14 +60,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (e is ApiException<ProblemDetails> { Result.Status: (int)HttpStatusCode.Unauthorized } problemDetailsException)
|
||||
{
|
||||
htmlBody = $"<p>{problemDetailsException.Result.Detail!}</p>";
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
@page "/visaApplications/new"
|
||||
@page "/applications/new"
|
||||
@using System.Net
|
||||
@using AutoMapper
|
||||
@using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models
|
||||
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants
|
||||
@using VisaApiClient
|
||||
@using BlazorWebAssemblyVisaApiClient.Components
|
||||
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.VisaApplications
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider
|
||||
@using FluentValidation
|
||||
@using Newtonsoft.Json
|
||||
@using Newtonsoft.Json.Linq
|
||||
@inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase
|
||||
|
||||
<PageTitle>New Application</PageTitle>
|
||||
@@ -23,9 +30,10 @@
|
||||
<ValidationMessage For="() => requestModel.DestinationCountry"></ValidationMessage><br/>
|
||||
|
||||
<label>
|
||||
Category: <EnumInputList Model="requestModel"
|
||||
EnumProperty="r => r.VisaCategory"
|
||||
OnChanged="StateHasChanged"/>
|
||||
Category:
|
||||
<EnumInputList Model="requestModel"
|
||||
EnumProperty="r => r.VisaCategory"
|
||||
OnChanged="StateHasChanged"/>
|
||||
</label><br/>
|
||||
<ValidationMessage For="() => requestModel.VisaCategory"></ValidationMessage><br/>
|
||||
|
||||
@@ -46,33 +54,98 @@
|
||||
<ValidationMessage For="() => requestModel.ValidDaysRequested"></ValidationMessage><br/>
|
||||
</div>
|
||||
|
||||
<div class="form-block">
|
||||
<fieldset disabled="@(requestModel.VisaCategory is not VisaCategory.Transit)">
|
||||
@if (requestModel.VisaCategory is VisaCategory.Transit)
|
||||
{
|
||||
<div class="form-block">
|
||||
<h5>Permission to destination Country</h5>
|
||||
<PermissionToDestCountryInput PermissionToDestCountry="requestModel.PermissionToDestCountry" />
|
||||
</fieldset>
|
||||
</div><br/>
|
||||
<PermissionToDestCountryInput PermissionToDestCountry="requestModel.PermissionToDestCountry"/>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (isNonResident)
|
||||
{
|
||||
<div class="form-block">
|
||||
<h5>Re-entry permission</h5>
|
||||
<ReentryPermitInput ReentryPermit="requestModel.ReentryPermit" />
|
||||
</div>
|
||||
<br/>
|
||||
}
|
||||
|
||||
<input type="submit" class="btn-outline-primary" value="Register"/>
|
||||
<ValidationSummary/>
|
||||
<Status @ref="status"/>
|
||||
</EditForm>
|
||||
</div>
|
||||
|
||||
//todo past visas and visits
|
||||
|
||||
@code {
|
||||
private VisaApplicationCreateRequestModel requestModel = new();
|
||||
private Status status = null!;
|
||||
private bool isNonResident;
|
||||
|
||||
[Inject] IDateTimeProvider DateTimeProvider { get; set; } = null!;
|
||||
|
||||
protected override void OnInitialized()
|
||||
[Inject] IUserDataProvider UserDataProvider { get; set; } = null!;
|
||||
|
||||
[Inject] IValidator<VisaApplicationCreateRequestModel> VisaApplicationCreateRequestValidator { get; set; } = null!;
|
||||
|
||||
[Inject] IMapper Mapper { get; set; } = null!;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
isNonResident = (await UserDataProvider.GetApplicant()).IsNonResident;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
|
||||
requestModel.PermissionToDestCountry!.ExpirationDate = DateTimeProvider.Now();
|
||||
}
|
||||
|
||||
private static void TryCreate()
|
||||
private async Task TryCreate()
|
||||
{
|
||||
var validationResult = await VisaApplicationCreateRequestValidator.ValidateAsync(requestModel);
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
var errorsString = validationResult.ToErrorsString();
|
||||
status.SetError(errorsString);
|
||||
}
|
||||
|
||||
status.SetMessage("Wait...");
|
||||
|
||||
var request = Mapper.Map<VisaApplicationCreateRequest>(requestModel);
|
||||
try
|
||||
{
|
||||
await Client.CreateApplicationAsync(request);
|
||||
status.SetSucces("Application created successfully.");
|
||||
}
|
||||
catch (ApiException<ProblemDetails> e)
|
||||
{
|
||||
if (e.StatusCode == (int)HttpStatusCode.BadRequest
|
||||
&& e.Result.AdditionalProperties.TryGetValue("errors", out var errors))
|
||||
{
|
||||
var errorsList = ((JArray)errors).ToObject<List<string>>();
|
||||
if (errorsList is null)
|
||||
{
|
||||
ErrorHandler.Handle(new JsonException("Can't convert validation errors to list"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
status.SetError(string.Join("<br/>", errorsList));
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
@page "/register"
|
||||
@using System.Net
|
||||
@using System.Text
|
||||
@using AutoMapper
|
||||
@using VisaApiClient
|
||||
@using BlazorWebAssemblyVisaApiClient.Components.FormComponents.Applicants
|
||||
@@ -8,6 +7,7 @@
|
||||
@using Newtonsoft.Json
|
||||
@using Newtonsoft.Json.Linq
|
||||
@using BlazorWebAssemblyVisaApiClient.Components
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers
|
||||
@using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider
|
||||
@using BlazorWebAssemblyVisaApiClient.Validation.Applicants.Models
|
||||
@inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase
|
||||
@@ -144,23 +144,12 @@
|
||||
requestModel.BirthDate = DateTime.Now;
|
||||
}
|
||||
|
||||
private string ErrorsToString(IEnumerable<string> errors)
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
foreach (var error in errors)
|
||||
{
|
||||
stringBuilder.Append($"{error}<br/>");
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private async void TryRegisterApplicant()
|
||||
{
|
||||
var validationResult = await RegisterApplicantRequestValidator.ValidateAsync(requestModel);
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
var errorsString = ErrorsToString(validationResult.Errors.Select(e => e.ErrorMessage));
|
||||
var errorsString = validationResult.ToErrorsString();
|
||||
status.SetError(errorsString);
|
||||
|
||||
return;
|
||||
@@ -187,7 +176,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
status.SetError(ErrorsToString(errorsList));
|
||||
status.SetError(string.Join("<br/>", errorsList));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -196,6 +185,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
status.SetError("Error occured");
|
||||
ErrorHandler.Handle(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,14 +26,12 @@ namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models
|
||||
[Range(0, ConfigurationConstraints.MaxValidDays)]
|
||||
public int ValidDaysRequested { get; set; }
|
||||
|
||||
[Required]
|
||||
[ValidateComplexType]
|
||||
public PastVisaModel[] PastVisas { get; set; } = default!;
|
||||
|
||||
[ValidateComplexType]
|
||||
public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
[ValidateComplexType]
|
||||
public PastVisitModel[] PastVisits { get; set; } = default!;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
|
||||
using FluentValidation;
|
||||
using VisaApiClient;
|
||||
|
||||
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Validators;
|
||||
|
||||
public class PastVisaModelValidator : AbstractValidator<PastVisaModel>
|
||||
{
|
||||
public PastVisaModelValidator(IDateTimeProvider dateTimeProvider)
|
||||
{
|
||||
RuleFor(v => v.ExpirationDate)
|
||||
.NotEmpty()
|
||||
.WithMessage("Expiration date of past visa can not be empty")
|
||||
.GreaterThan(v => v.IssueDate)
|
||||
.WithMessage("Past visa expiration date can not be earlier than issue date");
|
||||
|
||||
RuleFor(v => v.IssueDate)
|
||||
.NotEmpty()
|
||||
.WithMessage("Issue date of past visa can not be empty")
|
||||
.LessThan(dateTimeProvider.Now())
|
||||
.WithMessage("Issue date of past visa must be in past");
|
||||
|
||||
RuleFor(v => v.Name)
|
||||
.NotEmpty()
|
||||
.WithMessage("Name of past visa can not be empty");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
|
||||
using FluentValidation;
|
||||
using VisaApiClient;
|
||||
|
||||
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Validators;
|
||||
|
||||
public class PastVisitModelValidator : AbstractValidator<PastVisitModel>
|
||||
{
|
||||
public PastVisitModelValidator(IDateTimeProvider dateTimeProvider)
|
||||
{
|
||||
RuleFor(v => v.StartDate)
|
||||
.NotEmpty()
|
||||
.WithMessage("Start date of past visit can not be empty")
|
||||
.LessThan(v => v.EndDate)
|
||||
.WithMessage("Start date of past visit must be earlier than end date")
|
||||
.LessThan(dateTimeProvider.Now())
|
||||
.WithMessage("Start date of past visit must be in past");
|
||||
|
||||
RuleFor(v => v.EndDate)
|
||||
.NotEmpty()
|
||||
.WithMessage("End date of past visit can not be empty");
|
||||
|
||||
RuleFor(v => v.DestinationCountry)
|
||||
.NotEmpty()
|
||||
.WithMessage("Destination Country of past visit can not be null")
|
||||
.MaximumLength(ConfigurationConstraints.CountryNameLength)
|
||||
.WithMessage($"Destination Country of past visit length must be less than {ConfigurationConstraints.CountryNameLength}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
|
||||
using FluentValidation;
|
||||
using VisaApiClient;
|
||||
|
||||
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Validators;
|
||||
|
||||
public class PermissionToDestCountryModelValidator : AbstractValidator<PermissionToDestCountryModel?>
|
||||
{
|
||||
public PermissionToDestCountryModelValidator(IDateTimeProvider dateTimeProvider)
|
||||
{
|
||||
RuleFor(p => p!.ExpirationDate)
|
||||
.NotEmpty()
|
||||
.WithMessage("Expiration date of permission to destination Country can not be empty")
|
||||
.GreaterThan(dateTimeProvider.Now())
|
||||
.WithMessage("Permission to destination Country must not be expired");
|
||||
|
||||
RuleFor(p => p!.Issuer)
|
||||
.NotEmpty()
|
||||
.WithMessage("Issuer of permission for destination Country can not be empty")
|
||||
.MaximumLength(ConfigurationConstraints.IssuerNameLength)
|
||||
.WithMessage($"Issuer of permission to destination Country length must be less than {ConfigurationConstraints.IssuerNameLength}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
|
||||
using FluentValidation;
|
||||
using VisaApiClient;
|
||||
|
||||
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Validators;
|
||||
|
||||
public class VisaApplicationCreateRequestModelValidator : AbstractValidator<VisaApplicationCreateRequestModel>
|
||||
{
|
||||
public VisaApplicationCreateRequestModelValidator(
|
||||
IValidator<PastVisaModel> pastVisaModelValidator,
|
||||
IValidator<PermissionToDestCountryModel?> permissionToDestCountryModelValidator,
|
||||
IValidator<PastVisitModel> pastVisitModelValidator)
|
||||
{
|
||||
RuleFor(r => r.PermissionToDestCountry)
|
||||
.NotEmpty()
|
||||
.WithMessage("For transit you must provide permission to destination country")
|
||||
.SetValidator(permissionToDestCountryModelValidator)
|
||||
.When(r => r.VisaCategory is VisaCategory.Transit);
|
||||
|
||||
RuleFor(r => r.DestinationCountry)
|
||||
.NotEmpty()
|
||||
.WithMessage("Destination country can not be empty");
|
||||
|
||||
RuleFor(r => r.VisaCategory)
|
||||
.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}");
|
||||
|
||||
RuleForEach(r => r.PastVisas)
|
||||
.SetValidator(pastVisaModelValidator);
|
||||
|
||||
RuleForEach(r => r.PastVisits)
|
||||
.SetValidator(pastVisitModelValidator);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using ApplicationLayer.Services.AuthServices.Common;
|
||||
using ApplicationLayer.Services.Applicants.Models;
|
||||
using ApplicationLayer.Services.AuthServices.Common;
|
||||
using ApplicationLayer.Services.AuthServices.LoginService;
|
||||
using ApplicationLayer.Services.AuthServices.RegisterService;
|
||||
using ApplicationLayer.Services.AuthServices.Requests;
|
||||
@@ -109,4 +110,17 @@ public class UsersController(
|
||||
await usersService.RemoveAuthorityAccount(authorityAccountId, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary> Returns applicant info </summary>
|
||||
[HttpGet("applicant")]
|
||||
[ProducesResponseType<ApplicantModel>(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
[Authorize(policy: PolicyConstants.ApplicantPolicy)]
|
||||
public async Task<IActionResult> GetApplicant(CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var result = await usersService.GetAuthenticatedApplicant(cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,6 +742,110 @@ namespace VisaApiClient
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns applicant info
|
||||
/// </summary>
|
||||
/// <returns>Success</returns>
|
||||
/// <exception cref="ApiException">A server side error occurred.</exception>
|
||||
public virtual System.Threading.Tasks.Task<ApplicantModel> GetApplicantAsync()
|
||||
{
|
||||
return GetApplicantAsync(System.Threading.CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
|
||||
/// <summary>
|
||||
/// Returns applicant info
|
||||
/// </summary>
|
||||
/// <returns>Success</returns>
|
||||
/// <exception cref="ApiException">A server side error occurred.</exception>
|
||||
public virtual async System.Threading.Tasks.Task<ApplicantModel> GetApplicantAsync(System.Threading.CancellationToken cancellationToken)
|
||||
{
|
||||
var client_ = _httpClient;
|
||||
var disposeClient_ = false;
|
||||
try
|
||||
{
|
||||
using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
request_.Method = new System.Net.Http.HttpMethod("GET");
|
||||
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain"));
|
||||
|
||||
var urlBuilder_ = new System.Text.StringBuilder();
|
||||
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
|
||||
// Operation Path: "users/applicant"
|
||||
urlBuilder_.Append("users/applicant");
|
||||
|
||||
await PrepareRequestAsync(client_, request_, urlBuilder_, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var url_ = urlBuilder_.ToString();
|
||||
request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
|
||||
|
||||
await PrepareRequestAsync(client_, request_, url_, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
|
||||
var disposeResponse_ = true;
|
||||
try
|
||||
{
|
||||
var headers_ = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.IEnumerable<string>>();
|
||||
foreach (var item_ in response_.Headers)
|
||||
headers_[item_.Key] = item_.Value;
|
||||
if (response_.Content != null && response_.Content.Headers != null)
|
||||
{
|
||||
foreach (var item_ in response_.Content.Headers)
|
||||
headers_[item_.Key] = item_.Value;
|
||||
}
|
||||
|
||||
await ProcessResponseAsync(client_, response_, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var status_ = (int)response_.StatusCode;
|
||||
if (status_ == 200)
|
||||
{
|
||||
var objectResponse_ = await ReadObjectResponseAsync<ApplicantModel>(response_, headers_, cancellationToken).ConfigureAwait(false);
|
||||
if (objectResponse_.Object == null)
|
||||
{
|
||||
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
|
||||
}
|
||||
return objectResponse_.Object;
|
||||
}
|
||||
else
|
||||
if (status_ == 401)
|
||||
{
|
||||
var objectResponse_ = await ReadObjectResponseAsync<ProblemDetails>(response_, headers_, cancellationToken).ConfigureAwait(false);
|
||||
if (objectResponse_.Object == null)
|
||||
{
|
||||
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
|
||||
}
|
||||
throw new ApiException<ProblemDetails>("Unauthorized", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
|
||||
}
|
||||
else
|
||||
if (status_ == 403)
|
||||
{
|
||||
var objectResponse_ = await ReadObjectResponseAsync<ProblemDetails>(response_, headers_, cancellationToken).ConfigureAwait(false);
|
||||
if (objectResponse_.Object == null)
|
||||
{
|
||||
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
|
||||
}
|
||||
throw new ApiException<ProblemDetails>("Forbidden", status_, objectResponse_.Text, headers_, objectResponse_.Object, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (disposeResponse_)
|
||||
response_.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (disposeClient_)
|
||||
client_.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns pending applications
|
||||
/// </summary>
|
||||
@@ -1494,49 +1598,62 @@ namespace VisaApiClient
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
public partial class ApplicantModel
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public NameModel? Name { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public NameModel Name { get; set; } = new NameModel();
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("passport", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public PassportModel? Passport { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("passport", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public PassportModel Passport { get; set; } = new PassportModel();
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("birthDate", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public System.DateTimeOffset? BirthDate { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("birthDate", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
|
||||
public System.DateTimeOffset BirthDate { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("countryOfBirth", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public string? CountryOfBirth { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("countryOfBirth", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public string CountryOfBirth { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("cityOfBirth", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public string? CityOfBirth { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("cityOfBirth", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public string CityOfBirth { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("citizenship", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public string? Citizenship { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("citizenship", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public string Citizenship { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("citizenshipByBirth", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public string? CitizenshipByBirth { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("citizenshipByBirth", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public string CitizenshipByBirth { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("gender", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
[Newtonsoft.Json.JsonProperty("gender", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public Gender? Gender { get; set; } = default!;
|
||||
public Gender Gender { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("maritalStatus", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
[Newtonsoft.Json.JsonProperty("maritalStatus", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||
public MaritalStatus? MaritalStatus { get; set; } = default!;
|
||||
public MaritalStatus MaritalStatus { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("fatherName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public NameModel? FatherName { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("fatherName", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public NameModel FatherName { get; set; } = new NameModel();
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("motherName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public NameModel? MotherName { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("motherName", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public NameModel MotherName { get; set; } = new NameModel();
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("jobTitle", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public string? JobTitle { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("jobTitle", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public string JobTitle { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("placeOfWork", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public PlaceOfWorkModel? PlaceOfWork { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("placeOfWork", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
public PlaceOfWorkModel PlaceOfWork { get; set; } = new PlaceOfWorkModel();
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("isNonResident", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public bool? IsNonResident { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("isNonResident", Required = Newtonsoft.Json.Required.Always)]
|
||||
public bool IsNonResident { get; set; } = default!;
|
||||
|
||||
}
|
||||
|
||||
@@ -1714,12 +1831,14 @@ namespace VisaApiClient
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
public partial class PermissionToDestCountryModel
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("expirationDate", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public System.DateTimeOffset? ExpirationDate { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("expirationDate", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
|
||||
public System.DateTimeOffset ExpirationDate { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("issuer", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
[System.ComponentModel.DataAnnotations.StringLength(200)]
|
||||
public string? Issuer { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("issuer", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
[System.ComponentModel.DataAnnotations.StringLength(200, MinimumLength = 1)]
|
||||
public string Issuer { get; set; } = default!;
|
||||
|
||||
}
|
||||
|
||||
@@ -1774,12 +1893,14 @@ namespace VisaApiClient
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
public partial class ReentryPermitModel
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("number", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
[System.ComponentModel.DataAnnotations.StringLength(25)]
|
||||
public string? Number { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("number", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required]
|
||||
[System.ComponentModel.DataAnnotations.StringLength(25, MinimumLength = 1)]
|
||||
public string Number { get; set; } = default!;
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("expirationDate", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
|
||||
public System.DateTimeOffset? ExpirationDate { get; set; } = default!;
|
||||
[Newtonsoft.Json.JsonProperty("expirationDate", Required = Newtonsoft.Json.Required.Always)]
|
||||
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
|
||||
public System.DateTimeOffset ExpirationDate { get; set; } = default!;
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user