public async Task <IActionResult> GetPatients([FromQuery] PatientParametersDto patientParametersDto, CancellationToken cancellationToken) { var patientQuery = new PatientListQuery(patientParametersDto); var patientsDto = await _mediator.Send(patientQuery, cancellationToken); var paginationMetadata = new { totalCount = patientsDto.TotalCount, pageSize = patientsDto.PageSize, currentPageSize = patientsDto.CurrentPageSize, currentStartIndex = patientsDto.CurrentStartIndex, currentEndIndex = patientsDto.CurrentEndIndex, pageNumber = patientsDto.PageNumber, totalPages = patientsDto.TotalPages, hasPrevious = patientsDto.HasPrevious, hasNext = patientsDto.HasNext }; Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata)); var response = new Response <IEnumerable <PatientDto> >(patientsDto); return(Ok(response)); }
public async Task <PagedList <PatientDto> > Handle(PatientListQuery request, CancellationToken cancellationToken) { if (request.QueryParameters == null) { // log error throw new ApiException("Invalid query parameters."); } // include marker -- to accomodate adding includes with craftsman commands, the next line must stay as `var result = await _db.Patients`. -- do not delete this comment var collection = _db.Patients as IQueryable <Patient>; var sieveModel = new SieveModel { Sorts = request.QueryParameters.SortOrder ?? "PatientId", Filters = request.QueryParameters.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); var dtoCollection = _db.Patients .ProjectTo <PatientDto>(_mapper.ConfigurationProvider); return(await PagedList <PatientDto> .CreateAsync(dtoCollection, request.QueryParameters.PageNumber, request.QueryParameters.PageSize)); }
public async Task <IActionResult> GetPatients([FromQuery] PatientParametersDto patientParametersDto) { // add error handling var query = new PatientListQuery(patientParametersDto); var queryResponse = await _mediator.Send(query); var paginationMetadata = new { totalCount = queryResponse.TotalCount, pageSize = queryResponse.PageSize, currentPageSize = queryResponse.CurrentPageSize, currentStartIndex = queryResponse.CurrentStartIndex, currentEndIndex = queryResponse.CurrentEndIndex, pageNumber = queryResponse.PageNumber, totalPages = queryResponse.TotalPages, hasPrevious = queryResponse.HasPrevious, hasNext = queryResponse.HasNext }; Response.Headers.Add("X-Pagination", JsonSerializer.Serialize(paginationMetadata)); var response = new Response <IEnumerable <PatientDto> >(queryResponse); return(Ok(response)); }
public async Task <PagedList <PatientDto> > Handle(PatientListQuery request, CancellationToken cancellationToken = default) { if (request.PatientParametersDto == null) { // log error throw new ApiException("Invalid query parameters."); } var collection = _db.Patients .ProjectTo <PatientDto>(_mapper.ConfigurationProvider); var sieveModel = new SieveModel { Sorts = request.PatientParametersDto.SortOrder ?? "PatientId", Filters = request.PatientParametersDto.Filters }; collection = _sieveProcessor.Apply(sieveModel, collection); return(await PagedList <PatientDto> .CreateAsync(collection, request.PatientParametersDto.PageNumber, request.PatientParametersDto.PageSize, cancellationToken)); }