Validation fixes, finished application creation, added required char (*) for required fields

This commit is contained in:
2024-09-08 14:13:08 +03:00
parent 142148368f
commit c128349f3b
34 changed files with 372 additions and 100 deletions

View File

@@ -22,6 +22,10 @@ public class PastVisaModelValidator : AbstractValidator<PastVisaModel>
RuleFor(v => v.Name)
.NotEmpty()
.WithMessage("Name of past visa can not be empty");
.WithMessage("Name of past visa can not be empty")
.Matches(Constants.EnglishPhraseRegex)
.WithMessage("Name of past visa can contain only english letters, digits and special symbols")
.MaximumLength(ConfigurationConstraints.VisaNameLength)
.WithMessage($"Past visa name length must be less than {ConfigurationConstraints.VisaNameLength}");
}
}

View File

@@ -23,6 +23,8 @@ public class PastVisitModelValidator : AbstractValidator<PastVisitModel>
RuleFor(v => v.DestinationCountry)
.NotEmpty()
.WithMessage("Destination Country of past visit can not be null")
.Matches(Constants.EnglishPhraseRegex)
.WithMessage("Destination Country of past visit can contain only english letters, digits and special symbols")
.MaximumLength(ConfigurationConstraints.CountryNameLength)
.WithMessage($"Destination Country of past visit length must be less than {ConfigurationConstraints.CountryNameLength}");
}

View File

@@ -17,6 +17,8 @@ public class PermissionToDestCountryModelValidator : AbstractValidator<Permissio
RuleFor(p => p!.Issuer)
.NotEmpty()
.WithMessage("Issuer of permission for destination Country can not be empty")
.Matches(Constants.EnglishPhraseRegex)
.WithMessage("Issuer of permission for destination Country can contain only english letters, digits and special symbols")
.MaximumLength(ConfigurationConstraints.IssuerNameLength)
.WithMessage($"Issuer of permission to destination Country length must be less than {ConfigurationConstraints.IssuerNameLength}");
}

View File

@@ -0,0 +1,25 @@
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider;
using FluentValidation;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Validators;
public class ReentryPermitModelValidator : AbstractValidator<ReentryPermitModel?>
{
public ReentryPermitModelValidator(IDateTimeProvider dateTimeProvider)
{
RuleFor(p => p!.Number)
.NotEmpty()
.WithMessage("Re-entry permit number can not be empty")
.Matches(Constants.EnglishPhraseRegex)
.WithMessage("Re-entry permit number can contain only english letters, digits and special symbols")
.MaximumLength(ConfigurationConstraints.ReentryPermitNumberLength)
.WithMessage($"Re-entry permit number length must be less than {ConfigurationConstraints.ReentryPermitNumberLength}");
RuleFor(p => p!.ExpirationDate)
.NotEmpty()
.WithMessage("Re-entry permit expiration date can not be empty")
.GreaterThan(dateTimeProvider.Now())
.WithMessage("Re-entry permit must not be expired");
}
}

View File

@@ -1,15 +1,18 @@
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider;
using BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Models;
using FluentValidation;
using VisaApiClient;
namespace BlazorWebAssemblyVisaApiClient.Validation.VisaApplications.Validators;
public class VisaApplicationCreateRequestModelValidator : AbstractValidator<VisaApplicationCreateRequestModel>
public class VisaApplicationCreateRequestValidator : AbstractValidator<VisaApplicationCreateRequestModel>
{
public VisaApplicationCreateRequestModelValidator(
public VisaApplicationCreateRequestValidator(
IValidator<ReentryPermitModel?> reentryPermitModelValidator,
IValidator<PastVisaModel> pastVisaModelValidator,
IValidator<PermissionToDestCountryModel?> permissionToDestCountryModelValidator,
IValidator<PastVisitModel> pastVisitModelValidator)
IValidator<PastVisitModel> pastVisitModelValidator,
IUserDataProvider userDataProvider)
{
RuleFor(r => r.PermissionToDestCountry)
.NotEmpty()
@@ -17,6 +20,13 @@ public class VisaApplicationCreateRequestModelValidator : AbstractValidator<Visa
.SetValidator(permissionToDestCountryModelValidator)
.When(r => r.VisaCategory is VisaCategory.Transit);
RuleFor(r => r.ReentryPermit)
.NotEmpty()
.WithMessage("Non-residents must provide re-entry permission")
.SetValidator(reentryPermitModelValidator)
.WhenAsync(async (_, _) =>
(await userDataProvider.GetApplicant()).IsNonResident);
RuleFor(r => r.DestinationCountry)
.NotEmpty()
.WithMessage("Destination country can not be empty");