From e9a67683413956d00e83830db22e72ed43063c2b Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Fri, 1 Mar 2024 12:14:45 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20filtres=20(utilisation=20de=20nu?= =?UTF-8?q?ll=20par=20d=C3=A9faut=20au=20lieu=20de=20-1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sae/controllers/ScientifiqueController.java | 6 +++--- .../sciencequest/sae/services/ScientifiqueService.java | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/controllers/ScientifiqueController.java b/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/controllers/ScientifiqueController.java index e19acc4..e5dc152 100644 --- a/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/controllers/ScientifiqueController.java +++ b/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/controllers/ScientifiqueController.java @@ -38,10 +38,10 @@ public class ScientifiqueController { @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public PagedModel getAllScientists(@PageableDefault(size = ApplicationConfig.DEFAULT_PAGEABLE_SIZE) Pageable p, - @RequestParam(value = "thematiqueId", defaultValue = "-1") Integer thematiqueId, - @RequestParam(value = "difficulteId", defaultValue = "-1") Integer difficulteId) { + @RequestParam(value = "thematiqueId", defaultValue = "") Integer thematiqueId, + @RequestParam(value = "difficulteId", defaultValue = "") Integer difficulteId) { - Page page = (thematiqueId.equals(-1) && difficulteId.equals(-1) ? this.scientifiqueService.findAll(p) : this.scientifiqueService.findAllWithCriteria(p, thematiqueId, difficulteId)); + Page page = (thematiqueId == null && difficulteId == null ? this.scientifiqueService.findAll(p) : this.scientifiqueService.findAllWithCriteria(p, thematiqueId, difficulteId)); return pagedResourcesAssembler.toModel(page, scientifiqueModelAssembler); } diff --git a/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/ScientifiqueService.java b/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/ScientifiqueService.java index 1ee8818..e94052e 100644 --- a/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/ScientifiqueService.java +++ b/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/ScientifiqueService.java @@ -40,16 +40,12 @@ public class ScientifiqueService implements IScientifiqueService { @Override public Page findAll(Pageable page) { - return scientifiqueRepository.findAll(page); } public Page findAllWithCriteria(Pageable page, Integer tId, Integer dId) { - Thematique thematique = null; - Difficulte difficulte = null; - - if (tId != -1) thematique = thematiqueRepository.findById(tId).orElseThrow(() -> new ThematiqueNotFoundException(tId)); - if (dId != -1) difficulte = difficulteRepository.findById(dId).orElseThrow(() -> new DifficulteNotFoundException(dId)); + Thematique thematique = (tId != null ? thematiqueRepository.findById(tId).orElseThrow(() -> new ThematiqueNotFoundException(tId)) : null); + Difficulte difficulte = (dId != null ? difficulteRepository.findById(dId).orElseThrow(() -> new DifficulteNotFoundException(dId)) : null); if (thematique != null && difficulte != null) { return scientifiqueRepository.findAllByThematiqueEqualsAndDifficulteEquals(thematique, difficulte, page);