39 lines
1004 B
C#
39 lines
1004 B
C#
using MediatR;
|
|
using cuqmbr.TravelGuide.Application.Common.Interfaces.Persistence;
|
|
using cuqmbr.TravelGuide.Application.Common.Exceptions;
|
|
using AutoMapper;
|
|
|
|
namespace cuqmbr.TravelGuide.Application.Companies.Queries.GetCompany;
|
|
|
|
public class GetCompanyQueryHandler :
|
|
IRequestHandler<GetCompanyQuery, CompanyDto>
|
|
{
|
|
private readonly UnitOfWork _unitOfWork;
|
|
private readonly IMapper _mapper;
|
|
|
|
public GetCompanyQueryHandler(
|
|
UnitOfWork unitOfWork,
|
|
IMapper mapper)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<CompanyDto> Handle(
|
|
GetCompanyQuery request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var entity = await _unitOfWork.CompanyRepository.GetOneAsync(
|
|
e => e.Guid == request.Guid, cancellationToken);
|
|
|
|
_unitOfWork.Dispose();
|
|
|
|
if (entity == null)
|
|
{
|
|
throw new NotFoundException();
|
|
}
|
|
|
|
return _mapper.Map<CompanyDto>(entity);
|
|
}
|
|
}
|