Last active
May 8, 2017 19:04
-
-
Save rasheedamir/c5b043b77d0543880e8f19f9b5ed2cf9 to your computer and use it in GitHub Desktop.
Spring REST Resource - Set Default Page & Default Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final int DEFAULT_PAGE_NUMBER = 0; | |
private static final int DEFAULT_PAGE_SIZE = 50; | |
@RequestMapping(value = API_VERSION_1_OBSERVATION, | |
method = RequestMethod.GET, | |
produces = MediaType.APPLICATION_JSON_VALUE) | |
@Timed | |
public ResponseEntity<List<ApiAttachmentObservation>> findObservations(@RequestParam(required = false) String encounterId, | |
@RequestParam(required = false) String patientId, | |
@PageableDefault(page = DEFAULT_PAGE_NUMBER, size = DEFAULT_PAGE_SIZE) | |
@SortDefault.SortDefaults({ | |
@SortDefault(sort = "dateRecorded", direction = Sort.Direction.DESC), | |
@SortDefault(sort = "encounterId", direction = Sort.Direction.ASC) | |
}) | |
Pageable pageable) throws URISyntaxException | |
{ | |
LOGGER.info(String.format("REST request to find observations - [patientId : %s] & [encounterId : %s] & [pageable : %s]", patientId, encounterId, pageable)); | |
Page<ApiAttachmentObservation> page = observationService.findObservations(encounterId, patientId, pageable); | |
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, API_VERSION_1_OBSERVATION); | |
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment