1
0
forked from PGL/Clyde
This commit is contained in:
2024-03-07 17:02:19 +01:00
parent 8b35b3dc01
commit 6b58c852a2
4 changed files with 66 additions and 51 deletions

View File

@ -6,7 +6,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.TokenService;
import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.User;
@ -16,24 +16,19 @@ import ovh.herisson.Clyde.Tables.User;
public class UserController {
private final UserService userService;
private final TokenService tokenService;
public UserController(UserService userService, TokenService tokenService){
private final AuthenticatorService authServ;
public UserController(UserService userService, AuthenticatorService authServ){
this.userService = userService;
this.tokenService = tokenService; // todo find a way to be clearer
tokenService.postMockToken(userService.postMockUsers());// todo find a better place to put that
this.authServ = authServ;
}
@GetMapping("/user")
public ResponseEntity<User> getUsers(@RequestHeader("Authorization") String token){
User user = tokenService.getUserFromToken(token);
public ResponseEntity<User> getUser(@RequestHeader("Authorization") String token){
User user = authServ.getUserFromToken(token);
if (user == null) {
return new UnauthorizedResponse<User>(null);
return new UnauthorizedResponse<>(null);
}
return new ResponseEntity<User>(user, HttpStatus.OK);
return new ResponseEntity<>(user, HttpStatus.OK);
}
@PostMapping("/user")
@ -43,7 +38,7 @@ public class UserController {
}
@GetMapping("/users")
public Iterable<User> getAllUsers(){//TODO ne l'accepter que si c'est le secrétariat
public Iterable<User> getAllUsers(){
return userService.getAll();
}