You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GetRequestHandler.cs 1007B

123456789101112131415161718192021222324252627282930313233
  1. using Diligent.WebAPI.Business.Services;
  2. using Diligent.WebAPI.Host.Exceptions;
  3. using Diligent.WebAPI.Host.Mediator.Request.Queries;
  4. using MediatR;
  5. namespace Diligent.WebAPI.Host.Mediator.Request.Handlers
  6. {
  7. public class GetRequestHandler : IRequestHandler<GetRequestQuery, Data.Entities.Request>
  8. {
  9. private readonly RequestService _requestService;
  10. public GetRequestHandler(RequestService requestService)
  11. {
  12. _requestService = requestService;
  13. }
  14. public async Task<Data.Entities.Request> Handle(GetRequestQuery request, CancellationToken cancellationToken)
  15. {
  16. if (request.Id == null)
  17. {
  18. throw new BadHttpRequestException("Id cannot be null");
  19. }
  20. var req = await _requestService.GetRequestAsync(request.Id);
  21. if (request == null)
  22. {
  23. throw new NotFoundException("Request not found");
  24. }
  25. return req;
  26. }
  27. }
  28. }