Admin controller, Locations controller, requests to add available countries, request to get available countries
This commit is contained in:
		| @@ -0,0 +1,36 @@ | ||||
| using ApplicationLayer.DataAccessingServices.Locations.NeededServices; | ||||
| using ApplicationLayer.DataAccessingServices.Locations.RequestHandlers.AdminRequests.Exceptions; | ||||
| using ApplicationLayer.DataAccessingServices.Locations.Requests; | ||||
| using ApplicationLayer.GeneralNeededServices; | ||||
| using Domains.LocationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.DataAccessingServices.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 MultipleIdenticalCitiesInCountry(); | ||||
|             } | ||||
|  | ||||
|             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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,6 @@ | ||||
| using ApplicationLayer.GeneralExceptions; | ||||
|  | ||||
| namespace ApplicationLayer.DataAccessingServices.Locations.RequestHandlers.AdminRequests.Exceptions | ||||
| { | ||||
|     public class CountryAlreadyExists(string countryName) : AlreadyExistsException($"{countryName} already exists."); | ||||
| } | ||||
| @@ -0,0 +1,6 @@ | ||||
| using ApplicationLayer.GeneralExceptions; | ||||
|  | ||||
| namespace ApplicationLayer.DataAccessingServices.Locations.RequestHandlers.AdminRequests.Exceptions | ||||
| { | ||||
|     public class MultipleIdenticalCitiesInCountry() : ApiException("There are multiple cities with one name in the country."); | ||||
| } | ||||
| @@ -0,0 +1,11 @@ | ||||
| using ApplicationLayer.DataAccessingServices.Locations.Requests; | ||||
|  | ||||
| namespace ApplicationLayer.DataAccessingServices.Locations.RequestHandlers.AdminRequests | ||||
| { | ||||
|     /// Handles edit requests of locations from admins | ||||
|     public interface IEditLocationsRequestsHandler | ||||
|     { | ||||
|         /// Handles add country requests | ||||
|         Task AddCountryAsync(AddCountryRequest request, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using Domains.LocationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.DataAccessingServices.Locations.RequestHandlers.ApplicantRequests | ||||
| { | ||||
|     /// Handles location requests | ||||
|     public interface ILocationRequestsHandler | ||||
|     { | ||||
|         /// Handle get request | ||||
|         /// <returns>List of available countries</returns> | ||||
|         Task<List<Country>> HandleGetRequestAsync(CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,14 @@ | ||||
| using ApplicationLayer.DataAccessingServices.Locations.NeededServices; | ||||
| using Domains.LocationDomain; | ||||
|  | ||||
| namespace ApplicationLayer.DataAccessingServices.Locations.RequestHandlers.ApplicantRequests | ||||
| { | ||||
|     /// <inheritdoc cref="ILocationRequestsHandler"/> | ||||
|     public class LocationRequestsHandler(ICountriesRepository countries) : ILocationRequestsHandler | ||||
|     { | ||||
|         async Task<List<Country>> ILocationRequestsHandler.HandleGetRequestAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             return await countries.GetAllAsync(cancellationToken); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user