Class UsersController

java.lang.Object
edu.ucsb.cs156.dining.controllers.ApiController
edu.ucsb.cs156.dining.controllers.UsersController

@RequestMapping("/api") @RestController public class UsersController extends ApiController
This is a REST controller for getting information about the users.

These endpoints are only accessible to users with the role "ROLE_ADMIN".

  • 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.JsonProcessingException
      This 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
    • usersPaged

      @PreAuthorize("hasRole('ROLE_ADMIN')") @GetMapping("/admin/users/paged") public org.springframework.data.domain.Page<UserDTO> usersPaged(org.springframework.data.domain.Pageable pageable)
      This method returns one page of users, with their admin and moderator flags. Accessible only to users with the role "ROLE_ADMIN".

      Use the standard Spring query parameters to choose the page, e.g. /api/admin/users/paged?page=0&size=10. Pages are always sorted by user id; a sort parameter is ignored.

      Parameters:
      pageable - page number, page size, and sort order (from the query parameters)
      Returns:
      the requested page of users
    • getUsersWithProposedAlias

      @PreAuthorize("hasRole('ROLE_ADMIN')") @GetMapping("/admin/usersWithProposedAlias") public org.springframework.http.ResponseEntity<String> getUsersWithProposedAlias() throws com.fasterxml.jackson.core.JsonProcessingException
      This 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("hasRole('ROLE_MODERATOR')") @GetMapping("/admin/users/needsmoderation") public org.springframework.http.ResponseEntity<String> getAliasesNeedingModeration() throws com.fasterxml.jackson.core.JsonProcessingException
      Get 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("hasRole('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 update
      approved - the new moderation status
      Returns:
      the updated user