Api/Brizco.Repository/Handlers/Sections/GetSectionQueryHandler.cs

18 lines
677 B
C#

namespace Brizco.Repository.Handlers.Sections;
public class GetSectionQueryHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<GetSectionQuery, SectionLDto>
{
public async Task<SectionLDto> Handle(GetSectionQuery request, CancellationToken cancellationToken)
{
var shift = await repositoryWrapper.SetRepository<Section>()
.TableNoTracking
.Where(s => s.Id == request.Id)
.Select(SectionMapper.ProjectToLDto)
.FirstOrDefaultAsync(cancellationToken);
if (shift == null)
throw new AppException("Section not found", ApiResultStatusCode.NotFound);
return shift;
}
}