LeoMoulin/Backend/Leo #55

Merged
tonitch merged 11 commits from LeoMoulin/Backend/Leo into master 2024-03-05 23:42:00 +01:00
Showing only changes of commit cc89d7f5b7 - Show all commits

View File

@ -1,6 +1,9 @@
package ovh.herisson.Clyde.EndPoints; 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 org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.User;
@ -16,12 +19,26 @@ public class UserController {
this.userRepo = userRepo; 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") @GetMapping("/users")
public Iterable<User> getUsers(){ public Iterable<User> getAllUsers(){//TODO ne l'accepter que si c'est le secrétariat
return userRepo.findAll(); return userRepo.findAll();
} }
@PostMapping("/users")
public void postUser(@RequestBody User user ){
userRepo.save(user);
}
} }