Modification filtres (utilisation de null par défaut au lieu de -1)

Springboot
Alix JEUDI--LEMOINE 1 year ago
parent 9a451618bd
commit e9a6768341

@ -38,10 +38,10 @@ public class ScientifiqueController {
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public PagedModel<ScientifiqueDTO> 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<Scientifique> page = (thematiqueId.equals(-1) && difficulteId.equals(-1) ? this.scientifiqueService.findAll(p) : this.scientifiqueService.findAllWithCriteria(p, thematiqueId, difficulteId));
Page<Scientifique> page = (thematiqueId == null && difficulteId == null ? this.scientifiqueService.findAll(p) : this.scientifiqueService.findAllWithCriteria(p, thematiqueId, difficulteId));
return pagedResourcesAssembler.toModel(page, scientifiqueModelAssembler);
}

@ -40,16 +40,12 @@ public class ScientifiqueService implements IScientifiqueService {
@Override
public Page<Scientifique> findAll(Pageable page) {
return scientifiqueRepository.findAll(page);
}
public Page<Scientifique> 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);

Loading…
Cancel
Save