40 lines
1009 B
C#
40 lines
1009 B
C#
using MediatR;
|
|
using cuqmbr.TravelGuide.Application.Common.Interfaces.Persistence;
|
|
using cuqmbr.TravelGuide.Application.Common.Exceptions;
|
|
using AutoMapper;
|
|
|
|
namespace cuqmbr.TravelGuide.Application.Cities.Queries.GetCity;
|
|
|
|
public class GetCityQueryHandler :
|
|
IRequestHandler<GetCityQuery, CityDto>
|
|
{
|
|
private readonly UnitOfWork _unitOfWork;
|
|
private readonly IMapper _mapper;
|
|
|
|
public GetCityQueryHandler(
|
|
UnitOfWork unitOfWork,
|
|
IMapper mapper)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<CityDto> Handle(
|
|
GetCityQuery request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var entity = await _unitOfWork.CityRepository.GetOneAsync(
|
|
e => e.Guid == request.Guid, e => e.Region.Country,
|
|
cancellationToken);
|
|
|
|
_unitOfWork.Dispose();
|
|
|
|
if (entity == null)
|
|
{
|
|
throw new NotFoundException();
|
|
}
|
|
|
|
return _mapper.Map<CityDto>(entity);
|
|
}
|
|
}
|