| 1234567891011121314151617181920212223242526272829303132333435 |
- using Diligent.WebAPI.Business.Interfaces;
- using Diligent.WebAPI.Business.Services;
- using Diligent.WebAPI.Host.Exceptions;
- using Diligent.WebAPI.Host.Mediator.Request.Queries;
- using MediatR;
-
- namespace Diligent.WebAPI.Host.Mediator.Request.Handlers
- {
- public class GetRequestHandler : IRequestHandler<GetRequestQuery, Data.Entities.Request>
- {
- private readonly IRequestRepository _requestService;
-
-
- public GetRequestHandler(IRequestRepository requestService)
- {
- _requestService = requestService;
- }
- public async Task<Data.Entities.Request> Handle(GetRequestQuery request, CancellationToken cancellationToken)
- {
- if (request.Id == null)
- {
- throw new BadHttpRequestException("Id cannot be null");
- }
-
- var req = await _requestService.GetByIdAsync(request.Id);
-
- if (request == null)
- {
- throw new NotFoundException("Request not found");
- }
-
- return req;
- }
- }
- }
|