Class UsersController
java.lang.Object
edu.ucsb.cs156.dining.controllers.ApiController
edu.ucsb.cs156.dining.controllers.UsersController
This is a REST controller for getting information about the users.
These endpoints are only accessible to users with the role "ROLE_ADMIN".
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String> Get all users whose proposed alias is awaiting moderation.org.springframework.http.ResponseEntity<String> This method returns list of all users with a proposed alias.org.springframework.data.domain.Page<UserDTO> pagedUsers(org.springframework.data.domain.Pageable pageable) Returns a paginated list of users sorted by user ID.updateAliasModeration(long id, Boolean approved) This method allows an admin to update the moderation status of a user's alias.org.springframework.http.ResponseEntity<User> updateProposedAlias(String proposedAlias) This method allows the user to update their alias.org.springframework.http.ResponseEntity<String> users()This method returns a list of all users.Methods inherited from class ApiController
genericMessage, getCurrentUser, handleGenericException, handleUnsupportedOperation
-
Constructor Details
-
UsersController
public UsersController()
-
-
Method Details
-
users
@PreAuthorize("hasRole('ROLE_ADMIN')") @GetMapping("/admin/users") public org.springframework.http.ResponseEntity<String> users() throws com.fasterxml.jackson.core.JsonProcessingExceptionThis method returns a list of all users. Accessible only to users with the role "ROLE_ADMIN".- Returns:
- a list of all users
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if there is an error processing the JSON
-
pagedUsers
@PreAuthorize("hasRole('ROLE_ADMIN')") @GetMapping("/admin/users/paged") public org.springframework.data.domain.Page<UserDTO> pagedUsers(org.springframework.data.domain.Pageable pageable) Returns a paginated list of users sorted by user ID.- Parameters:
pageable- pagination parameters- Returns:
- a page of users with computed admin and moderator flags
-
getUsersWithProposedAlias
@PreAuthorize("hasRole('ROLE_ADMIN')") @GetMapping("/admin/usersWithProposedAlias") public org.springframework.http.ResponseEntity<String> getUsersWithProposedAlias() throws com.fasterxml.jackson.core.JsonProcessingExceptionThis method returns list of all users with a proposed alias.- Returns:
- a list of users with a proposed alias
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if there is an error processing the JSON
-
getAliasesNeedingModeration
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MODERATOR')") @GetMapping("/admin/users/needsmoderation") public org.springframework.http.ResponseEntity<String> getAliasesNeedingModeration() throws com.fasterxml.jackson.core.JsonProcessingExceptionGet all users whose proposed alias is awaiting moderation.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
updateProposedAlias
@PreAuthorize("hasRole('ROLE_USER')") @PostMapping("/currentUser/updateAlias") public org.springframework.http.ResponseEntity<User> updateProposedAlias(@RequestParam String proposedAlias) This method allows the user to update their alias.- Parameters:
proposedAlias- the new alias- Returns:
- the updated user
-
updateAliasModeration
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_MODERATOR')") @PutMapping("/currentUser/updateAliasModeration") public User updateAliasModeration(@RequestParam long id, @RequestParam Boolean approved) This method allows an admin to update the moderation status of a user's alias.- Parameters:
id- the id of the user to updateapproved- the new moderation status- Returns:
- the updated user
-