From 64c5df029dc478c3b6857943a0426b4240769ad9 Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Fri, 5 Apr 2024 13:53:25 +0200 Subject: [PATCH] Ajout d'1 DELETE pour exemple --- .../sae/controllers/ScientifiqueController.java | 7 +++++++ .../fr/iut/sciencequest/sae/services/IndiceService.java | 7 +++++++ 2 files changed, 14 insertions(+) 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 9d03bd0..d8421e8 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 @@ -21,6 +21,7 @@ import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.PagedModel; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @RestController @@ -62,4 +63,10 @@ public class ScientifiqueController { indice.setScientifique(this.scientifiqueService.findById(id)); return this.modelMapper.map(this.indiceService.create(indice), IndiceSimpleWithScientifiquesIdDTO.class); } + + @DeleteMapping(value="/{id}/indices/{indiceId}") + @ResponseStatus(HttpStatus.ACCEPTED) + public void deleteIndice(@PathVariable Integer id, @PathVariable Integer indiceId) { + this.indiceService.delete(indiceId); + } } diff --git a/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/IndiceService.java b/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/IndiceService.java index 15b7246..c199b9f 100644 --- a/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/IndiceService.java +++ b/SpringBootProject/src/main/java/fr/iut/sciencequest/sae/services/IndiceService.java @@ -48,4 +48,11 @@ public class IndiceService { } return destIndice; } + + public void delete(int id){ + if(!this.indiceRepository.existsById(id)){ + throw new IndiceNotFoundException(id); + } + this.indiceRepository.deleteById(id); + } }