public async Task <PagedApiResponse <IEnumerable <ReadDocumentListResponse> > > Handle(GetDocumentsByTermsQuery request, CancellationToken cancellationToken) { // validate page request.ValidateValues(); // check if type exist if (request.Type != null && await _documentTypeRepository.FindByIdAsync(request.Type.Value) == null) { throw new ApiProblemDetailsException($"Type with id: {request.Type} does not exist.", StatusCodes.Status404NotFound); } // check if tag exist DocumentTag tag = null; if (!string.IsNullOrWhiteSpace(request.Tag)) { tag = await _documentTagRepository.FindBySlugAsync(_authenticatedUser.UserId, request.Tag); if (tag == null) { throw new ApiProblemDetailsException($"Tag with name: {request.Tag} does not exist.", StatusCodes.Status404NotFound); } } // make request PaginatedList <Document> paginatedList = await _repository.GetPagedReponseAsync(_authenticatedUser.UserId, request.Page, request.PageSize, request.Term, request.Type, tag?.Id); IEnumerable <ReadDocumentListResponse> dto = _mapper.Map <IEnumerable <ReadDocumentListResponse> >(paginatedList.Items); ApiResponsePagination pagination = ApiResponsePagination.Build(paginatedList); return(new PagedApiResponse <IEnumerable <ReadDocumentListResponse> >(dto, pagination)); }
public async Task <PagedApiResponse <IEnumerable <ReadDocumentListResponse> > > Handle(GetAllDocumentsQuery request, CancellationToken cancellationToken) { request.ValidateValues(); PaginatedList <Document> paginatedList = await _repository.GetPagedReponseAsync(_authenticatedUser.UserId, request.Page, request.PageSize); IEnumerable <ReadDocumentListResponse> dto = _mapper.Map <IEnumerable <ReadDocumentListResponse> >(paginatedList.Items); ApiResponsePagination pagination = ApiResponsePagination.Build(paginatedList); return(new PagedApiResponse <IEnumerable <ReadDocumentListResponse> >(dto, pagination)); }