using MediatR; using cuqmbr.TravelGuide.Application.Common.Persistence; using cuqmbr.TravelGuide.Application.Common.Exceptions; using AutoMapper; namespace cuqmbr.TravelGuide.Application.Cities.Queries.GetCity; public class GetCityQueryHandler : IRequestHandler { private readonly UnitOfWork _unitOfWork; private readonly IMapper _mapper; public GetCityQueryHandler( UnitOfWork unitOfWork, IMapper mapper) { _unitOfWork = unitOfWork; _mapper = mapper; } public async Task 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(entity); } }