1
0
forked from PGL/Clyde

added the GET /teachers (#130)

had to fix the mock and the UserController isAdminOrSecretary

Reviewed-on: PGL/Clyde#130
Reviewed-by: Wal <karpinskiwal@gmail.com>
Reviewed-by: Debucquoy Anthony <d.tonitch@gmail.com>
Co-authored-by: Bartha Maxime <231026@umons.ac.be>
Co-committed-by: Bartha Maxime <231026@umons.ac.be>
This commit is contained in:
Bartha Maxime 2024-03-16 17:16:46 +01:00 committed by Maxime
parent 32e26f35cb
commit d5f6656e2b
4 changed files with 28 additions and 1 deletions

View File

@ -49,7 +49,7 @@ public class MockController {
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary"));
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary"));
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.Teacher,passwordEncoder.encode("inscriptionService"));
mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke));

View File

@ -9,6 +9,8 @@ import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.security.Key;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -72,6 +74,23 @@ public class UserController {
return new ResponseEntity<>("data modified", HttpStatus.OK);
}
@GetMapping("/teachers")
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllTeachers(@RequestHeader("Authorization") String token){
if (authServ.getUserFromToken(token) == null)
return new UnauthorizedResponse<>(null);
Iterable<User> teachers = userService.getAllTeachers();
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
for (User t: teachers){
withoutPassword.add(userWithoutPassword(t));
}
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
}
/** return user's data except password
* @param user the user to return
* @return all the user data without the password

View File

@ -15,4 +15,8 @@ public interface UserRepository extends CrudRepository<User, Long> {
/**
@Query(value = "select a.* from Users a ",nativeQuery = true)
Iterable<User> findAllUsers();**/
@Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher")
Iterable<User> findAllTeachers();
}

View File

@ -103,4 +103,8 @@ public class UserService {
public Iterable<User> getAll(){
return userRepo.findAll();
}
public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
}