Compare commits

...

3 Commits

Author SHA1 Message Date
cc89d7f5b7 added ResponseEntity and TODOs 2024-03-04 23:35:15 +01:00
45bfe08c9a added .idea/ to .gitignore 2024-03-04 21:27:22 +01:00
6c688dab59 added Admin and Secretary 2024-03-04 21:25:44 +01:00
3 changed files with 26 additions and 7 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ build
.project .project
.settings .settings
.idea/

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);
}
} }

View File

@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Tables;
public enum Role { public enum Role {
Teacher, Teacher,
Student; Student,
Admin,
Secretary;
} }