using ApplicationLayer.Services.Applicants.NeededServices;
using Domains.ApplicantDomain;
using Infrastructure.Database.Applicants.Repositories.Exceptions;
using Infrastructure.Database.Generic;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Database.Applicants.Repositories;
/// Repository pattern for
///
///
public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter writer)
: GenericRepository(reader, writer), IApplicantsRepository
{
protected override IQueryable LoadDomain()
{
return base.LoadDomain()
.Include(a => a.CountryOfBirth)
.Include(a => a.CityOfBirth)
.Include(a => a.PlaceOfWork);
}
async Task IApplicantsRepository.FindByUserIdAsync(Guid userId, CancellationToken cancellationToken)
{
var result = await LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken);
return result ?? throw new ApplicantNotFoundByUserIdException(userId);
}
}