diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java index 2ace404..4be3443 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/UserController.java @@ -40,6 +40,16 @@ public class UserController { return new ResponseEntity<>(ProtectionService.userWithoutPassword(user), HttpStatus.OK); } + + @GetMapping("/user/{id}") + public ResponseEntity> getUserById(@RequestHeader("Authorization") String token, @PathVariable Long id){ + + if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token)) + return new UnauthorizedResponse<>(null); + + return new ResponseEntity<>(ProtectionService.userWithoutPassword(userService.getUserById(id)), HttpStatus.OK); + } + @PostMapping("/user") public ResponseEntity> postUser(@RequestBody User user,@RequestHeader("Authorization") String token){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java index 3d30a89..b4409e9 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java @@ -122,4 +122,8 @@ public class UserService { public Iterable getAllTeachers (){return userRepo.findAllTeachers();} public Iterable getAllStudents(){return userRepo.findAllStudents();} + + public User getUserById(long id) { + return userRepo.findById(id); + } } \ No newline at end of file