Skip to content

Commit

Permalink
add sorting studies
Browse files Browse the repository at this point in the history
  • Loading branch information
melazaar committed Dec 13, 2024
1 parent 29bb9bf commit be54be6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.rte_france.antares.datamanager_back.mapper.StudyMapper.toStudyPage;

Expand All @@ -28,10 +31,18 @@ public ResponseEntity<Page<StudyDTO>> searchStudies(
@RequestParam(value = "projectId", required = false, defaultValue = "") Integer projectId,
@RequestParam(value = "search", required = false, defaultValue = "") String search,
@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
@RequestParam(value = "size", required = false, defaultValue = "20") Integer size) {
@RequestParam(value = "size", required = false, defaultValue = "20") Integer size,
@RequestParam(value = "sortColumn", required = false) String sortColumn,
@RequestParam(value = "sortDirection", required = false) String sortDirection) {

Pageable paging = PageRequest.of(page-1, size, Sort.by(SORTING_CRITERION));
Sort sorting = Sort.by(SORTING_CRITERION);

return new ResponseEntity<>(toStudyPage(studyService.findStudiesByCriteria(search,projectId, paging)), HttpStatus.OK);
if (!sortColumn.isEmpty() && !sortDirection.isEmpty()) {
Sort.Direction direction = Sort.Direction.fromString(sortDirection);
sorting = Sort.by(direction, sortColumn);
}
Pageable paging = PageRequest.of(page - 1, size, sorting);

return new ResponseEntity<>(toStudyPage(studyService.findStudiesByCriteria(search, projectId, paging)), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ public class StudyDTO {
@JsonProperty("id")
Integer id;

@JsonProperty("study_name")
String name;

@JsonProperty("user_name")
String createdBy;

@JsonProperty("creation_date")
LocalDateTime creationDate;

@JsonProperty("keywords")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void getStudiesReturnsPageOfStudies() throws Exception {
.param("search", "toto")
.param("page", "1")
.param("size", "2")
.param("sortColumn", "createdBy")
.param("sortDirection", "desc")
.accept(MediaType.APPLICATION_JSON_VALUE))

//Then
Expand All @@ -74,6 +76,8 @@ void getStudiesReturnsEmptyPageWhenNoStudiesFound() throws Exception {
.param("search", "toto")
.param("page", "1")
.param("size", "2")
.param("sortColumn", "createdBy")
.param("sortDirection", "desc")
.accept(MediaType.APPLICATION_JSON_VALUE))

//Then
Expand Down

0 comments on commit be54be6

Please sign in to comment.