Class OrdersRest

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

public class OrdersRest extends PetstoreConsolePage implements RowDetailMixin
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.
    • rowDetails

      Description copied from interface: RowDetailMixin
      The bean-backed details this resource serves.
      Specified by:
      rowDetails in interface RowDetailMixin
      Returns:
      The details. Each must have a distinct key.
    • petRows

      public List<Pet> petRows(@Query("orderId") Long orderId)
      The Pet tab of the order row detail: the pet an order is for, as a one-row table.
      Parameters:
      orderId - The order id.
      Returns:
      The pet.
      Throws:
      NotFound - If orderId is missing or names no order, or its pet is gone.
    • 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 dialog: pick a pet that is for sale and an optional ship date.

      The dialog submits to the ribbon item's endpoint.

      Returns:
      The modal, on the compact chrome.
    • 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.