diff --git a/.gitignore b/.gitignore index 4cbaf9d..b86c9c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ **/*~ .idea +*.properties **/*.class *.iml target/* diff --git a/src/main/java/Model/Controllers/AuthController.java b/src/main/java/Model/Controllers/AuthController.java index a8cb1c2..c018951 100644 --- a/src/main/java/Model/Controllers/AuthController.java +++ b/src/main/java/Model/Controllers/AuthController.java @@ -61,6 +61,8 @@ public String generateJwt(String userName, String password) { } + + @PostMapping("/a") public ResponseEntity authenticateUser(@RequestBody SignupRequest signupRequest){ diff --git a/src/main/java/Model/Controllers/ModuleController.java b/src/main/java/Model/Controllers/ModuleController.java index 5773581..2123bda 100644 --- a/src/main/java/Model/Controllers/ModuleController.java +++ b/src/main/java/Model/Controllers/ModuleController.java @@ -25,7 +25,7 @@ @CrossOrigin(origins = "*", maxAge = 3600) @RestController -@RequestMapping("/api/module") +@RequestMapping("/api/modules") public class ModuleController { @Autowired AuthenticationManager authenticationManager; @@ -49,22 +49,37 @@ public class ModuleController { JwtUtils jwtUtils; - @GetMapping("/{name}/getModules") - public ArrayList getmodules(@PathVariable String name){ - ArrayList strings = new ArrayList<>(); - Optional ouser = userRepository.findByUsername(name); + @PreAuthorize("hasRole('TEACHER')") + @GetMapping("/who") + public ArrayList getPersonne(Principal principal) { + ArrayList data = new ArrayList<>(); + data.add("la personne connectée est " +principal.getName()); + return data ; + + } + + + @GetMapping("/{idUser}") + public ArrayList getmodules(@PathVariable Long idUser){ + ArrayList userModules = new ArrayList<>(); + Optional ouser = userRepository.findById(idUser); if (!ouser.isPresent()) { return null; } User user= ouser.get(); Set modules = user.getModules(); + for (Module module:modules) { - strings.add(module.name + "/" + module.id); + userModules.add("module name : "+module.name + "| id : " + module.id); } - return strings; + return userModules; } + + + + @GetMapping("/{id}/getRessources") public ArrayList getRessources(@PathVariable long id){ ArrayList strings = new ArrayList<>(); @@ -163,22 +178,24 @@ public ResponseEntity addUser(Principal principal, @PathVariable long id, @Pa User actor = userRepository.findByUsername(principal.getName()).get(); Set participants = module.getParticipants(); - if ((participants.isEmpty() && actor.equals(user)) - || participants.contains(actor)) { +// if ((participants.isEmpty() && actor.equals(user)) +// || participants.contains(actor)) { // verifie si user n'apartient pas déjà à participants if(!participants.contains(user)) { participants.add(user); + user.getModules().add(module); }else{ return ResponseEntity .badRequest() .body(new MessageResponse("Error: User y apartient deja !")); } - } else { - return ResponseEntity - .badRequest() - .body(new MessageResponse("Error: Not allowed to add user!")); - } +// } else { +// return ResponseEntity +// .badRequest() +// .body(new MessageResponse("Error: Not allowed to add user!")); +// } moduleRepository.save(module); + userRepository.save(user); return ResponseEntity.ok(new MessageResponse("User successfully added to module!")); } diff --git a/src/main/java/Model/Documents/Module.java b/src/main/java/Model/Documents/Module.java index fd21d7b..d9fcbbf 100644 --- a/src/main/java/Model/Documents/Module.java +++ b/src/main/java/Model/Documents/Module.java @@ -24,11 +24,11 @@ public class Module { inverseJoinColumns = @JoinColumn(name = "ressource_id")) public Set ressources = new HashSet<>(); - @ManyToMany(fetch = FetchType.LAZY) + @ManyToMany(fetch = FetchType.EAGER) @JoinTable( name = "module_user", joinColumns = @JoinColumn(name = "module_id"), inverseJoinColumns = @JoinColumn(name = "user_id")) - public Set users; + public Set users = new HashSet<>(); public Module() { } diff --git a/src/main/java/Model/Repositories/ModuleRepository.java b/src/main/java/Model/Repositories/ModuleRepository.java index 29fe975..ded3d02 100644 --- a/src/main/java/Model/Repositories/ModuleRepository.java +++ b/src/main/java/Model/Repositories/ModuleRepository.java @@ -10,5 +10,4 @@ public interface ModuleRepository extends JpaRepository { Optional findByName(String name); - Optional findById(String name); } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 23b0436..7723645 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,7 @@ - spring.datasource.url= jdbc:postgresql://localhost:5432/postgres spring.datasource.username= postgres -spring.datasource.password= p34kleiorntk09kslQ - +spring.datasource.password= gestionduprojet +#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/resources/features/Get.feature b/src/test/resources/features/Get.feature new file mode 100644 index 0000000..10a7a76 --- /dev/null +++ b/src/test/resources/features/Get.feature @@ -0,0 +1,10 @@ +Feature: Get + + Background: + Given a user with login "steve" + And a module named "Gestion de projet" + And a cours named "Gestion" + + Scenario: user check all modules that he subsccribe to + When "steve" check his modules + Then return all modules names \ No newline at end of file