From 2fb6aef67c8e77c83eb4926c4418112c84c924f7 Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sun, 17 Mar 2024 21:48:58 +0100 Subject: [PATCH] added GET /user/{id} --- .../ovh/herisson/Clyde/EndPoints/UserController.java | 10 ++++++++++ .../java/ovh/herisson/Clyde/Services/UserService.java | 4 ++++ 2 files changed, 14 insertions(+) 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