request for applications for applicant
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| namespace ApplicationLayer.GeneralNeededServices | namespace ApplicationLayer.GeneralNeededServices | ||||||
| { | { | ||||||
|     public interface IDateTimeProvider |     public interface IDateTimeProvider | ||||||
|     { |     {//todo rename folder | ||||||
|         /// Returns current date and time |         /// Returns current date and time | ||||||
|         DateTime Now(); |         DateTime Now(); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -8,4 +8,7 @@ public interface IApplicantsRepository : IGenericRepository<Applicant> | |||||||
| { | { | ||||||
|     /// Find <see cref="Applicant"/> by Identifier |     /// Find <see cref="Applicant"/> by Identifier | ||||||
|     Task<Applicant> FindByUserIdAsync(Guid userId, CancellationToken cancellationToken); |     Task<Applicant> FindByUserIdAsync(Guid userId, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|  |     /// Get identifier of applicant by user identifier | ||||||
|  |     Task<Guid> GetApplicantIdByUserId(Guid userId, CancellationToken cancellationToken); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| using ApplicationLayer.Services.VisaApplications.Requests; | using ApplicationLayer.Services.VisaApplications.Models; | ||||||
|  | using ApplicationLayer.Services.VisaApplications.Requests; | ||||||
| using Domains.VisaApplicationDomain; | using Domains.VisaApplicationDomain; | ||||||
|  |  | ||||||
| namespace ApplicationLayer.Services.VisaApplications.Handlers; | namespace ApplicationLayer.Services.VisaApplications.Handlers; | ||||||
| @@ -6,6 +7,7 @@ namespace ApplicationLayer.Services.VisaApplications.Handlers; | |||||||
| public interface IVisaApplicationRequestsHandler | public interface IVisaApplicationRequestsHandler | ||||||
| { | { | ||||||
|     Task<List<VisaApplication>> Get(CancellationToken cancellationToken); |     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 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 fix | ||||||
|         //TODO mapper |         //TODO mapper | ||||||
| @@ -45,13 +66,13 @@ public class VisaApplicationRequestsHandler( | |||||||
|         await unitOfWork.SaveAsync(cancellationToken); |         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 |         return new PastVisit | ||||||
|         { |         { | ||||||
|             DestinationCountry = await countries.GetByIdAsync(model.DestinationCountryId, cancellationToken), |             DestinationCountry = await countries.GetByIdAsync(modelForRequest.DestinationCountryId, cancellationToken), | ||||||
|             StartDate = model.StartDate, |             StartDate = modelForRequest.StartDate, | ||||||
|             EndDate = model.EndDate |             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 |     public class PastVisitModel | ||||||
|     { |     { | ||||||
|         /// First day of <see cref="PastVisitModel"/> |         /// <inheritdoc cref="PastVisit.StartDate"/> | ||||||
|         public DateTime StartDate { get; set; } |         public DateTime StartDate { get; set; } | ||||||
|  |  | ||||||
|         /// Last day of <see cref="PastVisitModel"/> |         /// <inheritdoc cref="PastVisit.EndDate"/> | ||||||
|         public DateTime EndDate { get; set; } |         public DateTime EndDate { get; set; } | ||||||
|  |  | ||||||
|         /// Identifier of destination country of <see cref="PastVisitModel"/> |         /// <inheritdoc cref="PastVisit.DestinationCountry"/> | ||||||
|         public Guid DestinationCountryId { get; set; } |         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; | 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, |     int ValidDaysRequested, | ||||||
|     PastVisa[] PastVisas, |     PastVisa[] PastVisas, | ||||||
|     PermissionToDestCountry? PermissionToDestCountry, |     PermissionToDestCountry? PermissionToDestCountry, | ||||||
|     PastVisitModel[] PastVisits |     PastVisitModelForRequest[] PastVisits | ||||||
| ); | ); | ||||||
|   | |||||||
| @@ -25,4 +25,10 @@ public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter w | |||||||
|         var result = await LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken); |         var result = await LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken); | ||||||
|         return result ?? throw new ApplicantNotFoundByUserIdException(userId); |         return result ?? throw new ApplicantNotFoundByUserIdException(userId); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     async Task<Guid> IApplicantsRepository.GetApplicantIdByUserId(Guid userId, CancellationToken cancellationToken) | ||||||
|  |     { | ||||||
|  |         var result = await base.LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken); | ||||||
|  |         return result?.Id ?? throw new ApplicantNotFoundByUserIdException(userId); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,10 +9,12 @@ public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWr | |||||||
|     : GenericRepository<VisaApplication>(reader, writer), IVisaApplicationsRepository |     : GenericRepository<VisaApplication>(reader, writer), IVisaApplicationsRepository | ||||||
| { | { | ||||||
|     protected override IQueryable<VisaApplication> LoadDomain() |     protected override IQueryable<VisaApplication> LoadDomain() | ||||||
|     { |         => base.LoadDomain() | ||||||
|         return base.LoadDomain() |             .Include(va => va.DestinationCountry) | ||||||
|             .Include(a => a.DestinationCountry) |             .Include(va => va.PastVisas) | ||||||
|             .Include(a => a.PastVisas) |             .Include(va => va.PastVisits); | ||||||
|             .Include(a => a.PastVisits); |  | ||||||
|     } |  | ||||||
|  |     async Task<List<VisaApplication>> IVisaApplicationsRepository.GetOfApplicantAsync(Guid applicantId, CancellationToken cancellationToken) | ||||||
|  |         => await LoadDomain().Where(va => va.ApplicantId == applicantId).ToListAsync(cancellationToken); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -19,11 +19,24 @@ public class VisaApplicationController(IVisaApplicationRequestsHandler visaAppli | |||||||
|         return Ok(result); |         return Ok(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     [HttpGet] | ||||||
|  |     [Authorize(policy: PolicyConstants.ApplicantPolicy)] | ||||||
|  |     [Route("OfApplicant")] | ||||||
|  |     public async Task<IActionResult> GetForApplicant(CancellationToken cancellationToken) | ||||||
|  |     { | ||||||
|  |         var userId = GetUserId(); | ||||||
|  |         var result = await visaApplicationRequestsHandler.GetForApplicant(userId, cancellationToken); | ||||||
|  |         return Ok(result); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     [HttpPost] |     [HttpPost] | ||||||
|     [Authorize(policy: PolicyConstants.ApplicantPolicy)] |     [Authorize(policy: PolicyConstants.ApplicantPolicy)] | ||||||
|     public void Create(VisaApplicationCreateRequest request, CancellationToken cancellationToken) |     public async Task<IActionResult> Create(VisaApplicationCreateRequest request, CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         var userId = Guid.Parse(HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value); |         var userId = GetUserId(); | ||||||
|         visaApplicationRequestsHandler.HandleCreateRequest(userId, request, cancellationToken); |         await visaApplicationRequestsHandler.HandleCreateRequest(userId, request, cancellationToken); | ||||||
|  |         return Created(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private Guid GetUserId() => Guid.Parse(HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user