1
0
forked from PGL/Clyde

moved portective method to Static ProtectiveService

This commit is contained in:
2024-03-17 03:06:19 +01:00
parent d855bbe911
commit f7df234312
5 changed files with 59 additions and 48 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.ProtectionService;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
@ -35,7 +36,7 @@ public class UserController {
User user = authServ.getUserFromToken(token);
if (user == null) return new UnauthorizedResponse<>(null);
return new ResponseEntity<>(authServ.userWithoutPassword(user), HttpStatus.OK);
return new ResponseEntity<>(ProtectionService.userWithoutPassword(user), HttpStatus.OK);
}
@PostMapping("/user")
@ -44,7 +45,7 @@ public class UserController {
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService,Role.Secretary},token))
return new UnauthorizedResponse<>(null);
return new ResponseEntity<>(authServ.userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
return new ResponseEntity<>(ProtectionService.userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
}
@GetMapping("/users")
@ -57,7 +58,7 @@ public class UserController {
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
for (User u :users){
withoutPassword.add(authServ.userWithoutPassword(u));
withoutPassword.add(ProtectionService.userWithoutPassword(u));
}
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
}
@ -95,7 +96,7 @@ public class UserController {
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
for (User t: teachers){
withoutPassword.add(authServ.userWithoutPassword(t));
withoutPassword.add(ProtectionService.userWithoutPassword(t));
}
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);