Changed exceptions, added action for closing applications by applicant
This commit is contained in:
		| @@ -21,12 +21,12 @@ public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter w | ||||
|     async Task<Applicant> IApplicantsRepository.FindByUserIdAsync(Guid userId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var result = await LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken); | ||||
|         return result ?? throw new ApplicantNotFoundByUserIdException(userId); | ||||
|         return result ?? throw new ApplicantNotFoundByUserIdException(); | ||||
|     } | ||||
|  | ||||
|     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); | ||||
|         return result?.Id ?? throw new ApplicantNotFoundByUserIdException(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,8 +3,5 @@ using Domains.ApplicantDomain; | ||||
|  | ||||
| namespace Infrastructure.Database.Applicants.Repositories.Exceptions | ||||
| { | ||||
|     public class ApplicantNotFoundByUserIdException(Guid id) : EntityNotFoundException<Applicant>("Applicant not found.") | ||||
|     { | ||||
|         public Guid UserId { get; private set; } = id; | ||||
|     } | ||||
|     public class ApplicantNotFoundByUserIdException() : EntityNotFoundException("Applicant not found."); | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,7 @@ | ||||
| using ApplicationLayer.Services.GeneralExceptions; | ||||
|  | ||||
| namespace Infrastructure.Database.VisaApplications.Repositories.Exceptions | ||||
| { | ||||
|     public class ApplicationNotFoundByApplicantAndApplicationIdException(Guid applicationId) | ||||
|         : EntityNotFoundException($"Application with id {applicationId} not found for authenticated user"); | ||||
| } | ||||
| @@ -1,6 +1,7 @@ | ||||
| using ApplicationLayer.Services.VisaApplications.NeededServices; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using Infrastructure.Database.Generic; | ||||
| using Infrastructure.Database.VisaApplications.Repositories.Exceptions; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
|  | ||||
| namespace Infrastructure.Database.VisaApplications.Repositories; | ||||
| @@ -16,4 +17,14 @@ public sealed class VisaApplicationsRepository(IGenericReader reader, IGenericWr | ||||
|  | ||||
|     async Task<List<VisaApplication>> IVisaApplicationsRepository.GetOfApplicantAsync(Guid applicantId, CancellationToken cancellationToken) | ||||
|         => await LoadDomain().Where(va => va.ApplicantId == applicantId).ToListAsync(cancellationToken); | ||||
|  | ||||
|     async Task<VisaApplication> IVisaApplicationsRepository.GetByApplicantAndApplicationIdAsync( | ||||
|         Guid applicantId, | ||||
|         Guid applicationId, | ||||
|         CancellationToken cancellationToken) | ||||
|     { | ||||
|         var result = await LoadDomain() | ||||
|             .SingleOrDefaultAsync(va => va.Id == applicationId && va.ApplicantId == applicantId, cancellationToken); | ||||
|         return result ?? throw new ApplicationNotFoundByApplicantAndApplicationIdException(applicationId); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user