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

18 lines
677 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Sections;
2023-11-14 16:21:49 +03:30
2024-08-09 21:42:04 +03:30
public class GetSectionQueryHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<GetSectionQuery, SectionLDto>
2023-11-14 16:21:49 +03:30
{
public async Task<SectionLDto> Handle(GetSectionQuery request, CancellationToken cancellationToken)
{
2024-08-09 21:42:04 +03:30
var shift = await repositoryWrapper.SetRepository<Section>()
2023-11-14 16:21:49 +03:30
.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;
}
}