Class PetsRest

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

public class PetsRest extends PetstoreConsolePage
The pets JSON endpoints (server-mode datatable query over BeanQuery, create/replace/delete, sell, stage, and the per-pet feeds), the Pets and Sold pages, the add/edit dialog form, and the P4 pet pages: Summary (inline edit), Photo, Orders (with a row detail, and one order selected at nav depth 4) and History, whose nav nodes the page appends under pets as p<petId> and o<orderId>. The Pending changes page is the ChangesRest child.
Example:

// The BQ#6 endpoint behind the table. @RestPost(path="/query") public DataTablesResults<Pet> query(@Content DataTablesRequest req) { try (var s = store().queryPets()) { return DataTablesQuery.run(req, s); } }

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

// The same table in the builder twin. TableSpec.create("pets").dataMode(DataMode.SERVER).dataUrl("/console/pets/query") .columns(Column.create("name").label("Name"));

See Also:
  • Constructor Details

  • Method Details

    • page

      public View page(RestRequest req)
      The Pets page.
      Parameters:
      req - The request; ?mixed renders the half-FTL variant, ?builder the builder twin.
      Returns:
      The page.
    • sold

      public View sold(RestRequest req)
      The Sold pets page.
      Parameters:
      req - The request; ?builder renders the builder twin.
      Returns:
      The page.
    • soldRows

      public List<Pet> soldRows()
      Returns:
      The client-mode rows for the Sold page: every sold pet, by id.
    • form

      public ModalDef form(@Query("id") Long id)
      The add/edit dialog form.
      Parameters:
      id - The pet to edit, or null to add.
      Returns:
      The modal.
      Throws:
      NotFound - If id names no pet.
    • query

      Server-mode DataTables query over all pets.

      The optional ids query parameter (comma-separated pet ids, as the ids URL-state directive sends it) narrows the pets to those ids, before the request's own column filters apply, so the two combine. Tokens that are not numbers are dropped, and a blank value or one with no usable token is ignored.

      Parameters:
      req - The DataTables request.
      ids - The ids to keep, or null.
      Returns:
      One page of pets, or a 200 error envelope for a malformed search expression.
    • create

      Creates a pet. Status defaults to AVAILABLE.
      Parameters:
      req - The request (write gate, audit actor).
      body - The new pet, either as the plain pet or as the dialog envelope {fields:{...}}.
      Returns:
      The result toast, carrying the stored pet.
      Throws:
      BadRequest - On a blank name or negative price.
    • update

      public ActionResult update(RestRequest req, @Path("id") long id, @Content JsonMap body)
      Replaces a pet. Name and price are required; a species, tags or photo left out of the body keep their current values, as does the status.
      Parameters:
      req - The request.
      id - The pet id.
      body - The new state, either as the plain pet or as the dialog envelope {fields:{...}}.
      Returns:
      The result toast.
      Throws:
      NotFound - If the pet does not exist.
    • delete

      public ActionResult delete(RestRequest req, @Path("id") long id)
      Deletes a pet.
      Parameters:
      req - The request.
      id - The pet id.
      Returns:
      The result toast.
      Throws:
      NotFound - If the pet does not exist.
    • sell

      public ActionResult sell(RestRequest req, @Path("id") long id)
      Marks a pet sold. The Pets page bulk "Mark sold (N)" action calls this per row.
      Parameters:
      req - The request.
      id - The pet id.
      Returns:
      The result toast, carrying the updated pet.
      Throws:
      NotFound - If the pet does not exist.
      Conflict - If it is already sold.
    • stage

      public ActionResult stage(RestRequest req, @Path("id") long id, @Content JsonMap body)
      Stages an inline edit for review on the Pending changes page. The pet itself is not changed until the change is applied.

      PendingChanges.stage(long, java.lang.String, java.lang.String, java.lang.String) owns which fields are stageable and its messages. The photo is deliberately not stageable: the pet detail Photo tab edits it directly through the API's own PUT /petstore/pets/{id}/photo.

      Parameters:
      req - The request.
      id - The pet id.
      body - {field, value}, or the inline-edit envelope {fields:{<field>:value}} with exactly one field.
      Returns:
      success carrying the new PendingChange.
      Throws:
      BadRequest - If the field is missing or not stageable, or the value is invalid.
      NotFound - If the pet does not exist.
    • orderRows

      public List<Order> orderRows(@Path("id") long id)
      Parameters:
      id - The pet id.
      Returns:
      This pet's orders (the related list), by id.
      Throws:
      NotFound - If the pet does not exist.
    • historyRows

      public List<AuditEntry> historyRows(@Path("id") long id)
      Parameters:
      id - The pet id.
      Returns:
      The audit rows for this pet, oldest first.
      Throws:
      NotFound - If the pet does not exist.
    • detail

      public SeeOther detail(RestRequest req, @Path("id") long id)
      The bare pet URL; lands on the first tab.
      Parameters:
      req - The request.
      id - The pet id.
      Returns:
      A 303 to /console/pets/{id}/summary.
    • detailTab

      public View detailTab(RestRequest req, RestResponse res, @Path("id") long id, @Path("tab") String tab)
      P4, one tab.
      Parameters:
      req - The request (viewer roles).
      res - The response (404 status for the not-found card).
      id - The pet id.
      tab - One of TABS.
      Returns:
      The tab page, or the not-found card with a 404 status.
      Throws:
      NotFound - If the tab is unknown.
    • detailOrder

      public View detailOrder(RestRequest req, RestResponse res, @Path("id") long id, @Path("orderId") long orderId)
      P4 at nav depth 4: the Orders tab with one of this pet's orders selected.
      Parameters:
      req - The request.
      res - The response.
      id - The pet id.
      orderId - The order id.
      Returns:
      The Orders tab with the order card, or the not-found card with a 404 status if the pet does not exist.
      Throws:
      NotFound - If the order does not exist or is not this pet's.
    • row

      public List<Pet> row(@Path("id") long id)
      Parameters:
      id - The pet id.
      Returns:
      The Summary card's single row: this pet, as a one-element list (the card is client-mode).
      Throws:
      NotFound - If the pet does not exist.
    • orderDetail

      public JsonMap orderDetail(@Path("id") long id, @Path("orderId") long orderId)
      The Orders tab's row-detail GET.
      Parameters:
      id - The pet id.
      orderId - The order id.
      Returns:
      {contractVersion, fields} (see RowDetail.response(Object)).
      Throws:
      NotFound - If the order does not exist or is not this pet's.
    • require

      protected Pet require(long id)
      Parameters:
      id - The pet id.
      Returns:
      The live pet.
      Throws:
      NotFound - If it does not exist.