Class OrdersRest

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

public class OrdersRest extends PetstoreConsolePage
The Orders page and its endpoints: the server-mode datatable query over BeanQuery, the approve and deliver status transitions, and the cancel dialog form with its DELETE.
Example:

// PLACED to APPROVED; any other status is a 409. @RestPost(path="/{id}/approve") public ActionResult approve(RestRequest req, @Path("id") long id) { return transition(req, id, "approve", OrderStatus.PLACED, OrderStatus.APPROVED); }

<@card type="datatables" id="orders"> { dataMode:'server', dataUrl:'/console/orders/query', rowActions:[{id:'approve', endpoint:'/console/orders/{id}/approve', method:'POST'}] } </@card>

See Also:
  • Constructor Details

  • Method Details

    • page

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

      public DataTablesResults<Order> query(@Content DataTablesRequest req, @Query("day") @Schema(aev=true) String day, @Query("start") @Schema(aev=true) String start, @Query("end") @Schema(aev=true) String end)
      Server-mode DataTables query over all orders.

      The optional day query parameter (yyyy-mm-dd) narrows the orders to those whose ship date falls in that day's window, before the request's own column filters apply, so the two combine. A missing, blank or malformed value is ignored.

      The optional start and end query parameters (the window URL-state directive's defaults; each a yyyy-mm-dd date or an ISO date-time, whose calendar date is used) keep the orders whose ship date falls between them, both days included, and either may be given alone. A bound that is blank or malformed is ignored. An order with no readable ship date is outside any window that has a usable bound. The window and day combine with each other and with the request's own column filters.

      Parameters:
      req - The DataTables request.
      day - The day to keep, or null.
      start - The first ship day to keep, or null.
      end - The last ship day to keep, or null.
      Returns:
      One page of orders, or a 200 error envelope for a malformed search expression.
    • newForm

      public ModalDef newForm()
      The new-order wizard, step one: pick a pet that is for sale and an optional ship date.

      The review button opens the stacked second step and carries these inputs to it as drafts. That step's Confirm posts to /console/orders, as declared on the child action.

      Returns:
      The modal, on the compact chrome.
    • reviewForm

      public ModalDef reviewForm(@Query("juneauDrafts") String drafts)
      The new-order wizard, step two: the order about to be placed, read back from the first step's drafts.
      Parameters:
      drafts - The first step's inputs as JSON, carried by the dialog as juneauDrafts.
      Returns:
      The modal, on the compact chrome, whose form re-posts the validated values.
      Throws:
      BadRequest - If the drafts are missing, not JSON, or carry a bad ship date.
      NotFound - If the pet does not exist.
      Conflict - If the pet is not available.
    • create

      Places a new order.
      Parameters:
      req - The request (audit actor).
      body - The order, as the plain {petId, shipDate} or the dialog envelope {fields:{...}}.
      Returns:
      The result toast, carrying the stored order.
      Throws:
      BadRequest - On a missing body, non-object fields, missing pet or a bad ship date.
      NotFound - If the pet does not exist.
      Conflict - If the pet is not available.
    • approve

      public ActionResult approve(RestRequest req, @Path("id") long id)
      Approves a placed order.
      Parameters:
      req - The request.
      id - The order id.
      Returns:
      The result toast, carrying the order.
      Throws:
      NotFound - If the order does not exist.
      Conflict - If it is not PLACED.
    • deliver

      public ActionResult deliver(RestRequest req, @Path("id") long id)
      Delivers an approved order.
      Parameters:
      req - The request.
      id - The order id.
      Returns:
      The result toast, carrying the order.
      Throws:
      NotFound - If the order does not exist.
      Conflict - If it is not APPROVED.
    • cancelForm

      public ModalDef cancelForm(@Path("id") long id)
      The cancel dialog form: a reason and whether to notify the customer.
      Parameters:
      id - The order id.
      Returns:
      The modal.
      Throws:
      NotFound - If the order does not exist.
    • cancel

      public ActionResult cancel(RestRequest req, @Path("id") long id)
      Deletes (cancels) an order.
      Parameters:
      req - The request.
      id - The order id.
      Returns:
      The result toast.
      Throws:
      BadRequest - If the optional body is not a JSON object.
      NotFound - If the order does not exist.