Created more proper NotFound exceptions

This commit is contained in:
2024-08-15 18:53:36 +03:00
parent 604081e047
commit 4c3380ee8d
7 changed files with 37 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
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;
@@ -12,4 +13,12 @@ public sealed class CitiesRepository(IGenericReader reader, IGenericWriter write
{
return base.LoadDomain().Include(c => c.Country);
}
}
///<inheritdoc cref="ICitiesRepository.GetByNameAsync"/>
/// <exception cref="CityNotFoundByNameException">city with provided name and country not found</exception>
public async Task<City> 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);
}
}