request for applications for applicant
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| using ApplicationLayer.Services.VisaApplications.Requests; | ||||
| using ApplicationLayer.Services.VisaApplications.Models; | ||||
| using ApplicationLayer.Services.VisaApplications.Requests; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Handlers; | ||||
| @@ -6,6 +7,7 @@ namespace ApplicationLayer.Services.VisaApplications.Handlers; | ||||
| public interface IVisaApplicationRequestsHandler | ||||
| { | ||||
|     Task<List<VisaApplication>> Get(CancellationToken cancellationToken); | ||||
|     Task<List<VisaApplicationModelForApplicant>> GetForApplicant(Guid userId, CancellationToken cancellationToken); | ||||
|  | ||||
|     void HandleCreateRequest(Guid userId, VisaApplicationCreateRequest request, CancellationToken cancellationToken); | ||||
|     Task HandleCreateRequest(Guid userId, VisaApplicationCreateRequest request, CancellationToken cancellationToken); | ||||
| } | ||||
|   | ||||
| @@ -17,7 +17,28 @@ public class VisaApplicationRequestsHandler( | ||||
| { | ||||
|     public async Task<List<VisaApplication>> Get(CancellationToken cancellationToken) => await applications.GetAllAsync(cancellationToken); | ||||
|  | ||||
|     public async void HandleCreateRequest(Guid userId, VisaApplicationCreateRequest request, CancellationToken cancellationToken) | ||||
|     public async Task<List<VisaApplicationModelForApplicant>> GetForApplicant(Guid userId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         //todo mapper | ||||
|         var applicantId = await applicants.GetApplicantIdByUserId(userId, cancellationToken); | ||||
|         var visaApplications = await applications.GetOfApplicantAsync(applicantId, cancellationToken); | ||||
|         return visaApplications.Select(va => new VisaApplicationModelForApplicant | ||||
|             { | ||||
|                 DestinationCountry = va.DestinationCountry.Name, | ||||
|                 ValidDaysRequested = va.ValidDaysRequested, | ||||
|                 ReentryPermit = va.ReentryPermit, | ||||
|                 VisaCategory = va.VisaCategory, | ||||
|                 RequestedNumberOfEntries = va.RequestedNumberOfEntries, | ||||
|                 PermissionToDestCountry = va.PermissionToDestCountry, | ||||
|                 ForGroup = va.ForGroup, | ||||
|                 PastVisas = va.PastVisas, | ||||
|                 RequestDate = va.RequestDate, | ||||
|                 PastVisits = va.PastVisits.Select(pv => | ||||
|                     new PastVisitModel { DestinationCountry = pv.DestinationCountry.Name, StartDate = pv.StartDate, EndDate = pv.EndDate }).ToList() | ||||
|             }).ToList(); | ||||
|     } | ||||
|  | ||||
|     public async Task HandleCreateRequest(Guid userId, VisaApplicationCreateRequest request, CancellationToken cancellationToken) | ||||
|     { | ||||
|         //TODO fix | ||||
|         //TODO mapper | ||||
| @@ -45,13 +66,13 @@ public class VisaApplicationRequestsHandler( | ||||
|         await unitOfWork.SaveAsync(cancellationToken); | ||||
|     } | ||||
|  | ||||
|     private async Task<PastVisit> ConvertPastVisitModelToPastVisit(PastVisitModel model, CancellationToken cancellationToken) | ||||
|     private async Task<PastVisit> ConvertPastVisitModelToPastVisit(PastVisitModelForRequest modelForRequest, CancellationToken cancellationToken) | ||||
|     { | ||||
|         return new PastVisit | ||||
|         { | ||||
|             DestinationCountry = await countries.GetByIdAsync(model.DestinationCountryId, cancellationToken), | ||||
|             StartDate = model.StartDate, | ||||
|             EndDate = model.EndDate | ||||
|             DestinationCountry = await countries.GetByIdAsync(modelForRequest.DestinationCountryId, cancellationToken), | ||||
|             StartDate = modelForRequest.StartDate, | ||||
|             EndDate = modelForRequest.EndDate | ||||
|         }; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,14 +1,18 @@ | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models | ||||
| using Domains.LocationDomain; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models | ||||
| { | ||||
|     /// Model of <see cref="PastVisit"/> with only name of the destination country | ||||
|     public class PastVisitModel | ||||
|     { | ||||
|         /// First day of <see cref="PastVisitModel"/> | ||||
|         /// <inheritdoc cref="PastVisit.StartDate"/> | ||||
|         public DateTime StartDate { get; set; } | ||||
|  | ||||
|         /// Last day of <see cref="PastVisitModel"/> | ||||
|         /// <inheritdoc cref="PastVisit.EndDate"/> | ||||
|         public DateTime EndDate { get; set; } | ||||
|  | ||||
|         /// Identifier of destination country of <see cref="PastVisitModel"/> | ||||
|         public Guid DestinationCountryId { get; set; } | ||||
|         /// <inheritdoc cref="PastVisit.DestinationCountry"/> | ||||
|         public string DestinationCountry { get; set; } = null!; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,17 @@ | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models | ||||
| { | ||||
|     /// Model of <see cref="PastVisit"/> with only identifier of country | ||||
|     public class PastVisitModelForRequest | ||||
|     { | ||||
|         /// First day of <see cref="PastVisitModelForRequest"/> | ||||
|         public DateTime StartDate { get; set; } | ||||
|  | ||||
|         /// Last day of <see cref="PastVisitModelForRequest"/> | ||||
|         public DateTime EndDate { get; set; } | ||||
|  | ||||
|         /// Identifier of destination country of <see cref="PastVisitModelForRequest"/> | ||||
|         public Guid DestinationCountryId { get; set; } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,40 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains.LocationDomain; | ||||
| using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.Models | ||||
| { | ||||
|     /// Model of <see cref="VisaApplication"/> | ||||
|     public class VisaApplicationModelForApplicant | ||||
|     { | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.ReentryPermit"/> | ||||
|         public ReentryPermit? ReentryPermit { get; set; } | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.DestinationCountry"/> | ||||
|         public string DestinationCountry { get; set; } = null!; | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.PastVisas"/> | ||||
|         public List<PastVisa> PastVisas { get; set; } = null!; | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.PermissionToDestCountry"/> | ||||
|         public PermissionToDestCountry? PermissionToDestCountry { get; set; } | ||||
|  | ||||
|         public List<PastVisitModel> PastVisits { get; set; } = null!; | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.VisaCategory"/> | ||||
|         public VisaCategory VisaCategory { get; set; } | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.ForGroup"/> | ||||
|         public bool ForGroup { get; set; } | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.RequestedNumberOfEntries"/> | ||||
|         public RequestedNumberOfEntries RequestedNumberOfEntries { get; set; } | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.RequestDate"/> | ||||
|         public DateTime RequestDate { get; set; } | ||||
|  | ||||
|         /// <inheritdoc cref="VisaApplication.ValidDaysRequested"/> | ||||
|         public int ValidDaysRequested { get; set; } | ||||
|     } | ||||
| } | ||||
| @@ -3,4 +3,8 @@ using Domains.VisaApplicationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.Services.VisaApplications.NeededServices; | ||||
|  | ||||
| public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication>; | ||||
| public interface IVisaApplicationsRepository : IGenericRepository<VisaApplication> | ||||
| { | ||||
|     /// Get applications of one applicant | ||||
|     Task<List<VisaApplication>> GetOfApplicantAsync(Guid applicantId, CancellationToken cancellationToken); | ||||
| } | ||||
|   | ||||
| @@ -13,5 +13,5 @@ public record VisaApplicationCreateRequest( | ||||
|     int ValidDaysRequested, | ||||
|     PastVisa[] PastVisas, | ||||
|     PermissionToDestCountry? PermissionToDestCountry, | ||||
|     PastVisitModel[] PastVisits | ||||
|     PastVisitModelForRequest[] PastVisits | ||||
| ); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user