Api/Brizco.Repository/Handlers/Complexes/GetComplexQueryHandler.cs

17 lines
683 B
C#

namespace Brizco.Repository.Handlers.Complexes;
public class GetComplexQueryHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<GetComplexQuery, ComplexSDto>
{
public async Task<ComplexSDto> Handle(GetComplexQuery request, CancellationToken cancellationToken)
{
var complex = await repositoryWrapper.SetRepository<Complex>()
.TableNoTracking
.Where(s => s.Id == request.Id)
.Select(ComplexMapper.ProjectToSDto)
.FirstOrDefaultAsync(cancellationToken);
if (complex == null)
throw new AppException("Complex not found", ApiResultStatusCode.NotFound);
return complex;
}
}