Renamed folder

This commit is contained in:
2024-08-19 22:25:08 +03:00
parent bd43611edf
commit 0afe775d85
45 changed files with 103 additions and 95 deletions

View File

@@ -0,0 +1,36 @@
using ApplicationLayer.GeneralNeededServices;
using ApplicationLayer.Services.Locations.NeededServices;
using ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests.Exceptions;
using ApplicationLayer.Services.Locations.Requests;
using Domains.LocationDomain;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests
{
/// <inheritdoc cref="IEditLocationsRequestsHandler"/>
public class EditLocationsRequestsHandler(ICountriesRepository countries, IUnitOfWork unitOfWork) : IEditLocationsRequestsHandler
{
async Task IEditLocationsRequestsHandler.AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken)
{
if (await countries.FindByName(request.CountryName, cancellationToken) is not null)
{
throw new CountryAlreadyExists(request.CountryName);
}
if (request.Cities.Distinct().Count() < request.Cities.Length)
{
throw new MultipleIdenticalCitiesInCountryException();
}
var country = new Country
{
Name = request.CountryName,
IsSchengen = request.IsSchengen,
Cities = request.Cities.Select(cityName => new City { Name = cityName }).ToList()
};
await countries.AddAsync(country, cancellationToken);
await unitOfWork.SaveAsync(cancellationToken);
}
}
}

View File

@@ -0,0 +1,6 @@
using ApplicationLayer.GeneralExceptions;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests.Exceptions
{
public class CountryAlreadyExists(string countryName) : AlreadyExistsException($"{countryName} already exists.");
}

View File

@@ -0,0 +1,6 @@
using ApplicationLayer.GeneralExceptions;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests.Exceptions
{
public class MultipleIdenticalCitiesInCountryException() : ApiException("There are multiple cities with one name in the country.");
}

View File

@@ -0,0 +1,11 @@
using ApplicationLayer.Services.Locations.Requests;
namespace ApplicationLayer.Services.Locations.RequestHandlers.AdminRequests
{
/// Handles edit requests of locations from admins
public interface IEditLocationsRequestsHandler
{
/// Handles add country requests
Task AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken);
}
}