diff --git a/src/main/java/Model/Controllers/ModuleController.java b/src/main/java/Model/Controllers/ModuleController.java index 2123bda..e8f24fd 100644 --- a/src/main/java/Model/Controllers/ModuleController.java +++ b/src/main/java/Model/Controllers/ModuleController.java @@ -97,11 +97,11 @@ public ArrayList getRessources(@PathVariable long id){ return strings; } - @PutMapping("/{name}/ressource/{ressouceName}") + @PutMapping("/{name}/ressource/{ressoucename}") @PreAuthorize("hasRole('TEACHER')") - public ResponseEntity addRessource(Principal principal,@PathVariable String name, @PathVariable String ressouceName){ + public ResponseEntity addRessource(Principal principal,@PathVariable String name, @PathVariable String ressoucename){ Optional omodule = moduleRepository.findByName(name); - Optional oressource = ressourcesRepository.findByName(ressouceName); + Optional oressource = ressourcesRepository.findByName(ressoucename); if (!omodule.isPresent()) { return ResponseEntity .badRequest() @@ -127,11 +127,11 @@ public ResponseEntity addRessource(Principal principal,@PathVariable String n return ResponseEntity.ok(new MessageResponse("User successfully added to module!")); } - @DeleteMapping("/{id}/ressource/{ressourceid}") + @DeleteMapping("/{name}/ressource/{ressoucename}") @PreAuthorize("hasRole('TEACHER')") - public ResponseEntity deleteRessource(Principal principal,@PathVariable long id, @PathVariable long questionaireid){ - Optional omodule = moduleRepository.findById(id); - Optional oressource = ressourcesRepository.findById(questionaireid); + public ResponseEntity deleteRessource(Principal principal,@PathVariable String name, @PathVariable String ressourcename){ + Optional omodule = moduleRepository.findByName(name); + Optional oressource = ressourcesRepository.findByName(ressourcename); if (!omodule.isPresent()) { return ResponseEntity .badRequest() diff --git a/src/main/java/Model/Documents/Module.java b/src/main/java/Model/Documents/Module.java index d9fcbbf..5d223a5 100644 --- a/src/main/java/Model/Documents/Module.java +++ b/src/main/java/Model/Documents/Module.java @@ -18,8 +18,8 @@ public class Module { @GeneratedValue(strategy = GenerationType.IDENTITY) public Long id; - @ManyToMany(fetch = FetchType.LAZY) - @JoinTable( name = "module_ressources)", + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( name = "module_ressources", joinColumns = @JoinColumn(name = "module_id"), inverseJoinColumns = @JoinColumn(name = "ressource_id")) public Set ressources = new HashSet<>(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7723645..299144e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.datasource.url= jdbc:postgresql://localhost:5432/postgres spring.datasource.username= postgres -spring.datasource.password= gestionduprojet +spring.datasource.password= p34kleiorntk09kslQ #logging.level.root=error spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect diff --git a/src/test/java/DeleteTest.java b/src/test/java/DeleteTest.java index 2314a26..fc019b4 100644 --- a/src/test/java/DeleteTest.java +++ b/src/test/java/DeleteTest.java @@ -57,8 +57,9 @@ public void deleteQuestionaire(String arg0, String arg1) throws IOException { } @When("{string} remouve cours {string} de module {string}") - public void remouveCours(String arg0, String arg1) throws IOException { + public void remouveCours(String arg0, String arg1,String arg2) throws IOException { String jwt = authController.generateJwt(arg0, PASSWORD); + executeDelete("http://localhost:8080/api/modules/"+ arg2 + "/ressource/" + arg1,jwt); } @Then("{string} is not a student")