LeoMoulin/Backend/Leo #55
@ -1,6 +1,9 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
@ -16,12 +19,26 @@ public class UserController {
|
||||
this.userRepo = userRepo;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
public ResponseEntity<User> getUsers(@RequestHeader("Authorization") String token){
|
||||
//TODO
|
||||
// Get the token thru the data base
|
||||
// tokenRepo.findToken(token) => User userFromToken
|
||||
// si role != secretary => return error : ResponseEntity<User>(null, HttpStatus.UNAUTHORIZED)
|
||||
return new ResponseEntity<User>(/**userRepo.findById(userFromToken.id),**/ HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/user")
|
||||
public ResponseEntity<String> postUser(@RequestBody User user){
|
||||
userRepo.save(user);
|
||||
return new ResponseEntity<String>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping("/users")
|
||||
public Iterable<User> getUsers(){
|
||||
public Iterable<User> getAllUsers(){//TODO ne l'accepter que si c'est le secrétariat
|
||||
return userRepo.findAll();
|
||||
}
|
||||
@PostMapping("/users")
|
||||
public void postUser(@RequestBody User user ){
|
||||
userRepo.save(user);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user