Added models for presentation layer with data annotations
This commit is contained in:
		| @@ -29,18 +29,6 @@ public class VisaApplicationRequestsHandler( | ||||
|         return applicationModels; | ||||
|     } | ||||
|  | ||||
|     private async Task<VisaApplicationModelForAuthority> MapVisaApplicationToModelForAuthorities(VisaApplication visaApplication, | ||||
|         CancellationToken cancellationToken) | ||||
|     { | ||||
|         var applicant = await applicants.GetByIdAsync(visaApplication.ApplicantId, cancellationToken); | ||||
|         var applicantModel = mapper.Map<ApplicantModel>(applicant); | ||||
|  | ||||
|         var model = mapper.Map<VisaApplicationModelForAuthority>(visaApplication); | ||||
|         model.Applicant = applicantModel; | ||||
|  | ||||
|         return model; | ||||
|     } | ||||
|  | ||||
|     public async Task<List<VisaApplicationModelForApplicant>> GetForApplicantAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         var applicantId = await applicants.GetApplicantIdByUserId(userIdProvider.GetUserId(), cancellationToken); | ||||
| @@ -83,7 +71,7 @@ public class VisaApplicationRequestsHandler( | ||||
|             throw new ApplicationAlreadyProcessedException(); | ||||
|         } | ||||
|  | ||||
|         ApplicationStatus statusToSet = status switch | ||||
|         var statusToSet = status switch | ||||
|         { | ||||
|             AuthorityRequestStatuses.Approved => ApplicationStatus.Approved, | ||||
|             AuthorityRequestStatuses.Rejected => ApplicationStatus.Rejected, | ||||
| @@ -95,4 +83,16 @@ public class VisaApplicationRequestsHandler( | ||||
|  | ||||
|         await unitOfWork.SaveAsync(cancellationToken); | ||||
|     } | ||||
| } | ||||
|  | ||||
|     private async Task<VisaApplicationModelForAuthority> MapVisaApplicationToModelForAuthorities(VisaApplication visaApplication, | ||||
|         CancellationToken cancellationToken) | ||||
|     { | ||||
|         var applicant = await applicants.GetByIdAsync(visaApplication.ApplicantId, cancellationToken); | ||||
|         var applicantModel = mapper.Map<ApplicantModel>(applicant); | ||||
|  | ||||
|         var model = mapper.Map<VisaApplicationModelForAuthority>(visaApplication); | ||||
|         model.Applicant = applicantModel; | ||||
|  | ||||
|         return model; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models; | ||||
|  | ||||
| /// Model of past visa for presentation layer | ||||
| public class PastVisaModel | ||||
| { | ||||
|     // Date of issue | ||||
|     [Required] | ||||
|     public DateTime IssueDate { get; set; } | ||||
|  | ||||
|     /// Name of visa | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.VisaNameLength)] | ||||
|     public string Name { get; set; } = null!; | ||||
|  | ||||
|     /// Date when visa expires | ||||
|     [Required] | ||||
|     public DateTime ExpirationDate { get; set; } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models; | ||||
|  | ||||
| /// Model of past visit for presentation layer | ||||
| public class PastVisitModel | ||||
| { | ||||
|     /// First day of past visit | ||||
|     [Required] | ||||
|     public DateTime StartDate { get; set; } | ||||
|  | ||||
|     /// Last day of past visit | ||||
|     [Required] | ||||
|     public DateTime EndDate { get; set; } | ||||
|  | ||||
|     /// Destination country of past visit | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.CountryNameLength)] | ||||
|     public string DestinationCountry { get; set; } = null!; | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models; | ||||
|  | ||||
| /// Model of permission to destination country for presentation layer | ||||
| public class PermissionToDestCountryModel | ||||
| { | ||||
|     /// Date when permission to destination country expires | ||||
|     [Required] | ||||
|     public DateTime ExpirationDate { get; set; } | ||||
|  | ||||
|     /// Issuing authority | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.IssuerNameLength)] | ||||
|     public string Issuer { get; set; } = null!; | ||||
| } | ||||
| @@ -0,0 +1,17 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models; | ||||
|  | ||||
| /// Model of re-entry permit for presentation layer | ||||
| public class ReentryPermitModel | ||||
| { | ||||
|     /// Number of re-entry permit | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.ReentryPermitNumberLength)] | ||||
|     public string Number { get; set; } = null!; | ||||
|  | ||||
|     /// Date when re-entry permit expires | ||||
|     [Required] | ||||
|     public DateTime ExpirationDate { get; set; } | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models.Validation; | ||||
|  | ||||
| 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 ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models.Validation; | ||||
|  | ||||
| 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 ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models.Validation; | ||||
|  | ||||
| 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,23 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models.Validation; | ||||
|  | ||||
| public class ReentryPermitModelValidator : AbstractValidator<ReentryPermitModel?> | ||||
| { | ||||
|     public ReentryPermitModelValidator(IDateTimeProvider dateTimeProvider) | ||||
|     { | ||||
|         RuleFor(p => p!.Number) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Re-entry permit number can not be empty") | ||||
|             .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"); | ||||
|     } | ||||
| } | ||||
| @@ -2,42 +2,42 @@ | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models; | ||||
|  | ||||
| /// Model of <see cref="VisaApplication"/> | ||||
| /// Model of <see cref="VisaApplication" /> | ||||
| public class VisaApplicationModelForApplicant | ||||
| { | ||||
|     /// <inheritdoc cref="VisaApplication.Id"/> | ||||
|     /// <inheritdoc cref="VisaApplication.Id" /> | ||||
|     public Guid Id { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.Status"/> | ||||
|     /// <inheritdoc cref="VisaApplication.Status" /> | ||||
|     public ApplicationStatus Status { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.ReentryPermit"/> | ||||
|     public ReentryPermit? ReentryPermit { get; set; } | ||||
|     /// <inheritdoc cref="VisaApplication.ReentryPermit" /> | ||||
|     public ReentryPermitModel? ReentryPermit { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.DestinationCountry"/> | ||||
|     /// <inheritdoc cref="VisaApplication.DestinationCountry" /> | ||||
|     public string DestinationCountry { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.PastVisas"/> | ||||
|     public List<PastVisa> PastVisas { get; set; } = null!; | ||||
|     /// <inheritdoc cref="VisaApplication.PastVisas" /> | ||||
|     public List<PastVisaModel> PastVisas { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.PermissionToDestCountry"/> | ||||
|     public PermissionToDestCountry? PermissionToDestCountry { get; set; } | ||||
|     /// <inheritdoc cref="VisaApplication.PermissionToDestCountry" /> | ||||
|     public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.PastVisits"/> | ||||
|     public List<PastVisit> PastVisits { get; set; } = null!; | ||||
|     /// <inheritdoc cref="VisaApplication.PastVisits" /> | ||||
|     public List<PastVisitModel> PastVisits { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.VisaCategory"/> | ||||
|     /// <inheritdoc cref="VisaApplication.VisaCategory" /> | ||||
|     public VisaCategory VisaCategory { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.ForGroup"/> | ||||
|     /// <inheritdoc cref="VisaApplication.ForGroup" /> | ||||
|     public bool ForGroup { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.RequestedNumberOfEntries"/> | ||||
|     /// <inheritdoc cref="VisaApplication.RequestedNumberOfEntries" /> | ||||
|     public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.RequestDate"/> | ||||
|     /// <inheritdoc cref="VisaApplication.RequestDate" /> | ||||
|     public DateTime RequestDate { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.ValidDaysRequested"/> | ||||
|     /// <inheritdoc cref="VisaApplication.ValidDaysRequested" /> | ||||
|     public int ValidDaysRequested { get; set; } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -3,44 +3,44 @@ using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models; | ||||
|  | ||||
| /// Model of <see cref="VisaApplication"/> with applicant property | ||||
| /// Model of <see cref="VisaApplication" /> with applicant property | ||||
| public class VisaApplicationModelForAuthority | ||||
| { | ||||
|     /// <inheritdoc cref="VisaApplication.Id"/> | ||||
|     /// <inheritdoc cref="VisaApplication.Id" /> | ||||
|     public Guid Id { get; set; } | ||||
|  | ||||
|     /// Applicant of application | ||||
|     public ApplicantModel Applicant { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.Status"/> | ||||
|     /// <inheritdoc cref="VisaApplication.Status" /> | ||||
|     public ApplicationStatus Status { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.ReentryPermit"/> | ||||
|     public ReentryPermit? ReentryPermit { get; set; } | ||||
|     /// <inheritdoc cref="VisaApplication.ReentryPermit" /> | ||||
|     public ReentryPermitModel? ReentryPermit { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.DestinationCountry"/> | ||||
|     /// <inheritdoc cref="VisaApplication.DestinationCountry" /> | ||||
|     public string DestinationCountry { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.PastVisas"/> | ||||
|     public List<PastVisa> PastVisas { get; set; } = null!; | ||||
|     /// <inheritdoc cref="VisaApplication.PastVisas" /> | ||||
|     public List<PastVisaModel> PastVisas { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.PermissionToDestCountry"/> | ||||
|     public PermissionToDestCountry? PermissionToDestCountry { get; set; } | ||||
|     /// <inheritdoc cref="VisaApplication.PermissionToDestCountry" /> | ||||
|     public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } | ||||
|  | ||||
|     public List<PastVisit> PastVisits { get; set; } = null!; | ||||
|     public List<PastVisitModel> PastVisits { get; set; } = null!; | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.VisaCategory"/> | ||||
|     /// <inheritdoc cref="VisaApplication.VisaCategory" /> | ||||
|     public VisaCategory VisaCategory { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.ForGroup"/> | ||||
|     /// <inheritdoc cref="VisaApplication.ForGroup" /> | ||||
|     public bool ForGroup { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.RequestedNumberOfEntries"/> | ||||
|     /// <inheritdoc cref="VisaApplication.RequestedNumberOfEntries" /> | ||||
|     public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.RequestDate"/> | ||||
|     /// <inheritdoc cref="VisaApplication.RequestDate" /> | ||||
|     public DateTime RequestDate { get; set; } | ||||
|  | ||||
|     /// <inheritdoc cref="VisaApplication.ValidDaysRequested"/> | ||||
|     /// <inheritdoc cref="VisaApplication.ValidDaysRequested" /> | ||||
|     public int ValidDaysRequested { get; set; } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -1,27 +0,0 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; | ||||
|  | ||||
| public class PastVisaValidator : AbstractValidator<PastVisa> | ||||
| { | ||||
|     public PastVisaValidator(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"); | ||||
|         } | ||||
| } | ||||
| @@ -1,30 +0,0 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; | ||||
|  | ||||
| public class PastVisitValidator : AbstractValidator<PastVisit> | ||||
| { | ||||
|     public PastVisitValidator(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}"); | ||||
|         } | ||||
| } | ||||
| @@ -1,24 +0,0 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; | ||||
|  | ||||
| public class PermissionToDestCountryValidator : AbstractValidator<PermissionToDestCountry?> | ||||
| { | ||||
|     public PermissionToDestCountryValidator(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}"); | ||||
|         } | ||||
| } | ||||
| @@ -1,24 +0,0 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Domains; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; | ||||
|  | ||||
| public class ReentryPermitValidator : AbstractValidator<ReentryPermit?> | ||||
| { | ||||
|     public ReentryPermitValidator(IDateTimeProvider dateTimeProvider) | ||||
|     { | ||||
|             RuleFor(p => p!.Number) | ||||
|                 .NotEmpty() | ||||
|                 .WithMessage("Re-entry permit number can not be empty") | ||||
|                 .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"); | ||||
|         } | ||||
| } | ||||
| @@ -1,5 +1,6 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.Applicants.NeededServices; | ||||
| using ApplicationLayer.Services.VisaApplications.Models; | ||||
| using Domains; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using FluentValidation; | ||||
| @@ -9,17 +10,17 @@ namespace ApplicationLayer.Services.VisaApplications.Requests.Validation; | ||||
| public class VisaApplicationCreateRequestValidator : AbstractValidator<VisaApplicationCreateRequest> | ||||
| { | ||||
|     public VisaApplicationCreateRequestValidator( | ||||
|         IValidator<ReentryPermit?> reentryPermitValidator, | ||||
|         IValidator<PastVisa> pastVisaValidator, | ||||
|         IValidator<PermissionToDestCountry?> permissionToDestCountryValidator, | ||||
|         IValidator<PastVisit> pastVisitValidator, | ||||
|         IValidator<ReentryPermitModel?> reentryPermitModelValidator, | ||||
|         IValidator<PastVisaModel> pastVisaModelValidator, | ||||
|         IValidator<PermissionToDestCountryModel?> permissionToDestCountryModelValidator, | ||||
|         IValidator<PastVisitModel> pastVisitModelValidator, | ||||
|         IApplicantsRepository applicants, | ||||
|         IUserIdProvider userIdProvider) | ||||
|     { | ||||
|         RuleFor(r => r.ReentryPermit) | ||||
|             .NotEmpty() | ||||
|             .WithMessage("Non-residents must provide re-entry permission") | ||||
|             .SetValidator(reentryPermitValidator) | ||||
|             .SetValidator(reentryPermitModelValidator) | ||||
|             .WhenAsync(async (_, ct) => | ||||
|                 await applicants.IsApplicantNonResidentByUserId(userIdProvider.GetUserId(), ct)); | ||||
|  | ||||
| @@ -40,14 +41,14 @@ public class VisaApplicationCreateRequestValidator : AbstractValidator<VisaAppli | ||||
|             .WithMessage($"Valid days requested must be less than or equal to {ConfigurationConstraints.MaxValidDays}"); | ||||
|  | ||||
|         RuleForEach(r => r.PastVisas) | ||||
|             .SetValidator(pastVisaValidator); | ||||
|             .SetValidator(pastVisaModelValidator); | ||||
|  | ||||
|         When(r => r.VisaCategory == VisaCategory.Transit, | ||||
|             () => | ||||
|                 RuleFor(r => r.PermissionToDestCountry) | ||||
|                     .SetValidator(permissionToDestCountryValidator)); | ||||
|                     .SetValidator(permissionToDestCountryModelValidator)); | ||||
|  | ||||
|         RuleForEach(r => r.PastVisits) | ||||
|             .SetValidator(pastVisitValidator); | ||||
|             .SetValidator(pastVisitModelValidator); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,16 +1,40 @@ | ||||
| using Domains.VisaApplicationDomain; | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using ApplicationLayer.Services.VisaApplications.Models; | ||||
| using Domains; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Requests; | ||||
|  | ||||
| /// Model of visa request from user | ||||
| public record VisaApplicationCreateRequest( | ||||
|     ReentryPermit? ReentryPermit, | ||||
|     string DestinationCountry, | ||||
|     VisaCategory VisaCategory, | ||||
|     bool IsForGroup, | ||||
|     RequestedNumberOfEntries RequestedNumberOfEntries, | ||||
|     int ValidDaysRequested, | ||||
|     PastVisa[] PastVisas, | ||||
|     PermissionToDestCountry? PermissionToDestCountry, | ||||
|     PastVisit[] PastVisits | ||||
| ); | ||||
| public class VisaApplicationCreateRequest | ||||
| { | ||||
|  | ||||
|     [Required] | ||||
|     public ReentryPermitModel? ReentryPermit { get; set; } | ||||
|  | ||||
|     [Required] | ||||
|     [MaxLength(ConfigurationConstraints.CountryNameLength)] | ||||
|     public string DestinationCountry { get; set; } = null!; | ||||
|  | ||||
|     [Required] | ||||
|     public VisaCategory VisaCategory { get; set; } | ||||
|  | ||||
|     [Required] | ||||
|     public bool IsForGroup { get; set; } | ||||
|  | ||||
|     [Required] | ||||
|     public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } | ||||
|  | ||||
|     [Required] | ||||
|     [Range(0, ConfigurationConstraints.MaxValidDays)] | ||||
|     public int ValidDaysRequested { get; set; } | ||||
|  | ||||
|     [Required] | ||||
|     public PastVisaModel[] PastVisas { get; set; } = null!; | ||||
|  | ||||
|     [Required] | ||||
|     public PermissionToDestCountryModel? PermissionToDestCountry { get; set; } | ||||
|  | ||||
|     [Required] | ||||
|     public PastVisitModel[] PastVisits { get; set; } = null!; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user