After adding the toggle features to the admin users page, one thing that you'll notice is that as soon as you click on a row, it jumps to another spot.
This is because there is no sorting and paging in the backend for the admin users endpoint.
In addition, the users are not paged; if/when we release this app into real production, the number of users will be too many to display on a single page at once.
Fix this by adding sorting and paging in the backend.
Compare, this code from proj-dining:
@Operation(summary = "Get a list of all users")
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("/admin/users")
public ResponseEntity<String> users() throws JsonProcessingException {
Iterable<User> users = userRepository.findAll();
String body = mapper.writeValueAsString(users);
return ResponseEntity.ok().body(body);
}
Vs. proj-frontiers: https://github.com/ucsb-cs156/proj-frontiers/blob/main/src/main/java/edu/ucsb/cs156/frontiers/controllers/UsersController.java
@Tag(name = "User information (admin only)")
@RequestMapping("/api/admin/users")
@RestController
public class UsersController extends ApiController {
@Autowired private UserDataDTOService userDataDTOService;
/**
* This method returns a list of all users. Accessible only to users with the role "ROLE_ADMIN".
*
* @return a list of all users
* @throws JsonProcessingException if there is an error processing the JSON
*/
@Operation(summary = "Get a list of all users")
@PreAuthorize("hasRole('ROLE_ADMIN')")
@GetMapping("")
public Page<UserDataDTO> users(Pageable pageable) throws JsonProcessingException {
return userDataDTOService.getUserDataDTOs(pageable);
}
}
But we can't just change this in one step; that would break the frontend.
You'll need to proceed in stages. Each of these is a subissue.
Note that if you need to temporarily remove the ability to toggle users moderator and admin status, that's ok, as long as you can still add/delete moderators in some fashion through either swagger or through a dedicated page for adding and deleting admins and moderators by their email (as is done in frontiers.)
Subissues
After adding the toggle features to the admin users page, one thing that you'll notice is that as soon as you click on a row, it jumps to another spot.
This is because there is no sorting and paging in the backend for the admin users endpoint.
In addition, the users are not paged; if/when we release this app into real production, the number of users will be too many to display on a single page at once.
Fix this by adding sorting and paging in the backend.
Compare, this code from proj-dining:
Vs. proj-frontiers: https://github.com/ucsb-cs156/proj-frontiers/blob/main/src/main/java/edu/ucsb/cs156/frontiers/controllers/UsersController.java
But we can't just change this in one step; that would break the frontend.
You'll need to proceed in stages. Each of these is a subissue.
Note that if you need to temporarily remove the ability to toggle users moderator and admin status, that's ok, as long as you can still add/delete moderators in some fashion through either swagger or through a dedicated page for adding and deleting admins and moderators by their email (as is done in frontiers.)
Subissues
/api/admin/users/pagedthat matches the functionality in proj-frontiers. Look into how theuserDataDTOServiceworks; you'll need to add that as well.