Skip to content

Commit

Permalink
delete cours
Browse files Browse the repository at this point in the history
  • Loading branch information
KuhlMatthis committed Feb 11, 2022
1 parent d2c4806 commit 4cddfd8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/main/java/Model/Controllers/ModuleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public ArrayList<String> 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<Module> omodule = moduleRepository.findByName(name);
Optional<Ressource> oressource = ressourcesRepository.findByName(ressouceName);
Optional<Ressource> oressource = ressourcesRepository.findByName(ressoucename);
if (!omodule.isPresent()) {
return ResponseEntity
.badRequest()
Expand All @@ -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<Module> omodule = moduleRepository.findById(id);
Optional<Ressource> oressource = ressourcesRepository.findById(questionaireid);
public ResponseEntity<?> deleteRessource(Principal principal,@PathVariable String name, @PathVariable String ressourcename){
Optional<Module> omodule = moduleRepository.findByName(name);
Optional<Ressource> oressource = ressourcesRepository.findByName(ressourcename);
if (!omodule.isPresent()) {
return ResponseEntity
.badRequest()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Model/Documents/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ressource> ressources = new HashSet<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/DeleteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4cddfd8

Please sign in to comment.