using ApplicationLayer.Locations; using Domains.LocationDomain; using Infrastructure.Database.Generic; using Infrastructure.Database.Locations.Repositories.Cities.Exceptions; using Microsoft.EntityFrameworkCore; namespace Infrastructure.Database.Locations.Repositories.Cities; public sealed class CitiesRepository(IGenericReader reader, IGenericWriter writer, IUnitOfWork unitOfWork) : GenericRepository(reader, writer, unitOfWork), ICitiesRepository { protected override IQueryable LoadDomain() { return base.LoadDomain().Include(c => c.Country); } /// /// city with provided name and country not found public async Task GetByNameAsync(string name, string countryName, CancellationToken cancellationToken) { var result = await LoadDomain().Where(c => c.Name == name && c.Country.Name == countryName).SingleOrDefaultAsync(cancellationToken); return result ?? throw new CityNotFoundByNameException(name, countryName); } }