1
0
forked from PGL/Clyde

added GET /user/{id}

This commit is contained in:
Bartha Maxime 2024-03-17 21:48:58 +01:00
parent 7a23dcc96a
commit 2fb6aef67c
2 changed files with 14 additions and 0 deletions

View File

@ -40,6 +40,16 @@ public class UserController {
return new ResponseEntity<>(ProtectionService.userWithoutPassword(user), HttpStatus.OK);
}
@GetMapping("/user/{id}")
public ResponseEntity<HashMap<String ,Object>> 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<Map<String ,Object>> postUser(@RequestBody User user,@RequestHeader("Authorization") String token){

View File

@ -122,4 +122,8 @@ public class UserService {
public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
public Iterable<User> getAllStudents(){return userRepo.findAllStudents();}
public User getUserById(long id) {
return userRepo.findById(id);
}
}