added the GET /teachers #130
@ -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));
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -103,4 +103,8 @@ public class UserService {
 | 
			
		||||
    public Iterable<User> getAll(){
 | 
			
		||||
        return userRepo.findAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user