Class UsersRest

java.lang.Object
jakarta.servlet.GenericServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable, BasicUniversalConfig, DefaultConfig, DefaultHtmlConfig

public class UsersRest extends PetstoreConsolePage
The Users page and its endpoints. The password is write-only: every read goes through UsersRest.UserView, which has no password, so it never leaves the server; an update with no password keeps the stored one.
Example:

// The wire shape of a create (JSON5): the password is accepted but never echoed. { username:'newbie', firstName:'New', lastName:'Bie', password:'s3cret' }

<@card type="datatables" id="users"> { dataMode:'server', dataUrl:'/console/users/query', columns:[{key:'username', label:'Username'}, ...] } </@card>

See Also:
  • Constructor Details

  • Method Details

    • page

      public View page(RestRequest req)
      The Users page.
      Parameters:
      req - The request; ?builder renders the builder twin.
      Returns:
      The page.
    • form

      public ModalDef form(@Query("username") String username)
      The add/edit dialog form. The password field is write-only: it is never pre-filled.
      Parameters:
      username - The user to edit, or null to add.
      Returns:
      The modal.
      Throws:
      NotFound - If username names no user.
    • query

      Server-mode DataTables query over all users, as password-free views.
      Parameters:
      req - The DataTables request.
      Returns:
      One page of users, or a 200 error envelope for a malformed search expression.
    • get

      public UsersRest.UserView get(@Path("username") String username)
      Parameters:
      username - The username.
      Returns:
      The user, without the password.
      Throws:
      NotFound - If it does not exist.
    • create

      Creates a user.
      Parameters:
      req - The request (write gate, audit actor).
      body - {username, firstName, lastName, password}, either plain or as the dialog envelope {fields:{...}}.
      Returns:
      The result toast, carrying the user without the password.
      Throws:
      BadRequest - On a blank username.
      Conflict - If the username is taken.
    • update

      public ActionResult update(RestRequest req, @Path("username") String username, @Content JsonMap body)
      Updates a user. A field left out of the body, and a null or blank password, keep their stored values.
      Parameters:
      req - The request.
      username - The username.
      body - The new state, either plain or as the dialog envelope {fields:{...}}.
      Returns:
      The result toast, carrying the user without the password.
      Throws:
      NotFound - If the user does not exist.
    • delete

      public ActionResult delete(RestRequest req, @Path("username") String username)
      Deletes a user.
      Parameters:
      req - The request.
      username - The username.
      Returns:
      The result toast.
      Throws:
      NotFound - If the user does not exist.