Class PetStoreResource

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

public class PetStoreResource extends BasicRestServlet
Petstore CRUD REST resource.

Deployment-agnostic. Mounted by both juneau-petstore-jetty and juneau-petstore-springboot via the @Rest(children=...) of their root router.

Endpoints:

  • GET /pets — list pets
  • GET /pets/{id} — get pet
  • POST /pets — create pet
  • PUT /pets/{id} — update pet
  • DELETE /pets/{id} — delete pet
  • GET /pets/{id}/photo — get pet photo
  • PUT /pets/{id}/photo — upload pet photo
  • GET /orders — list orders
  • GET /orders/{id} — get order
  • POST /orders — create order
  • PUT /orders/{id} — update order
  • DELETE /orders/{id} — delete order
  • GET /users — list users
  • GET /users/{username} — get user
  • POST /users — create user
  • PUT /users/{username} — update user
  • DELETE /users/{username} — delete user
See Also:
See Also:
  • Constructor Details

  • Method Details

    • getPets

      public Collection<Pet> getPets()
      Lists all pets.
      Returns:
      All pets.
    • getPet

      public Pet getPet(@Path("id") long id)
      Retrieves a pet by ID.
      Parameters:
      id - The pet ID.
      Returns:
      The pet.
      Throws:
      NotFound - If no pet with the given ID exists.
    • createPet

      public Pet createPet(@Content Pet pet)
      Creates a new pet.
      Parameters:
      pet - The pet to create.
      Returns:
      The created pet (with assigned ID).
    • updatePet

      public Pet updatePet(@Path("id") long id, @Content Pet pet)
      Updates an existing pet.
      Parameters:
      id - The pet ID.
      pet - The replacement pet body.
      Returns:
      The updated pet.
      Throws:
      NotFound - If no pet with the given ID exists.
    • deletePet

      public void deletePet(@Path("id") long id)
      Deletes a pet by ID.
      Parameters:
      id - The pet ID.
      Throws:
      NotFound - If no pet with the given ID exists.
    • getPetPhoto

      public BufferedImage getPetPhoto(@Path("id") long id)
      Retrieves the uploaded photo for a pet.
      Parameters:
      id - The pet ID.
      Returns:
      The photo image.
      Throws:
      NotFound - If no pet with the given ID exists, or no photo has been uploaded for it.
    • putPetPhoto

      public Ok putPetPhoto(@Path("id") long id, @Content BufferedImage image)
      Uploads a photo for a pet.

      On success, also updates the pet's photo field to point back at this endpoint.

      Parameters:
      id - The pet ID.
      image - The photo image.
      Returns:
      OK.
      Throws:
      NotFound - If no pet with the given ID exists.
    • getOrders

      Lists all orders.
      Returns:
      All orders.
    • getOrder

      public Order getOrder(@Path("id") long id)
      Retrieves an order by ID.
      Parameters:
      id - The order ID.
      Returns:
      The order.
      Throws:
      NotFound - If no order with the given ID exists.
    • createOrder

      public Order createOrder(@Content Order order)
      Creates a new order.
      Parameters:
      order - The order to create.
      Returns:
      The created order (with assigned ID).
    • updateOrder

      public Order updateOrder(@Path("id") long id, @Content Order order)
      Updates an existing order.
      Parameters:
      id - The order ID.
      order - The replacement order body.
      Returns:
      The updated order.
      Throws:
      NotFound - If no order with the given ID exists.
    • deleteOrder

      public void deleteOrder(@Path("id") long id)
      Deletes an order by ID.
      Parameters:
      id - The order ID.
      Throws:
      NotFound - If no order with the given ID exists.
    • getUsers

      Lists all users.
      Returns:
      All users.
    • getUser

      public User getUser(@Path("username") String username)
      Retrieves a user by username.
      Parameters:
      username - The username.
      Returns:
      The user.
      Throws:
      NotFound - If no user with the given username exists.
    • createUser

      public User createUser(@Content User user)
      Creates a new user.
      Parameters:
      user - The user to create. Must carry a non-null username not already in use.
      Returns:
      The created user.
    • updateUser

      public User updateUser(@Path("username") String username, @Content User user)
      Updates an existing user.

      The body replaces the user, except that the write-only password is kept when the body has none (or a blank one), so a GET followed by a PUT of the same body does not erase it.

      Parameters:
      username - The username.
      user - The replacement user body.
      Returns:
      The updated user.
      Throws:
      NotFound - If no user with the given username exists.
    • deleteUser

      public void deleteUser(@Path("username") String username)
      Deletes a user by username.
      Parameters:
      username - The username.
      Throws:
      NotFound - If no user with the given username exists.