StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 2 · REST Controllers & Endpoints

Planetarium Show Catalog

easyREST ControllersCRUD Endpoints50%2 of 4 solved

Problem statement

Expose a planetarium's show catalog through REST endpoints with the right HTTP verbs and status codes.

Requirements

The Show entity, the ShowCreateRequest body and the ShowService are already provided. Your task is to expose the catalog through four endpoints in ShowController.

ShowService

  • findAll() returns every show
  • findById(id) returns an Optional holding the show, or an empty Optional when no show has that id
  • create(request) saves a new show and returns it with its generated id
  • delete(id) deletes the show and returns true, or returns false when no show has that id

ShowController

GET /shows

  • Return 200 OK with every show in the catalog

GET /shows/{id}

  • Read the id from the path and return 200 OK with that show
  • Return 404 Not Found when no show has that id

POST /shows

  • Read a JSON body with title and durationMinutes, save the show, and return 201 Created with the saved show, including its generated id

DELETE /shows/{id}

  • Delete the show with that id and return 204 No Content with an empty body
  • Return 404 Not Found when no show has that id
Sample Requests & Responses

POST /shows

Request:

{
  "title": "Journey to the Rings",
  "durationMinutes": 45
}

Response (201 Created):

{
  "title": "Journey to the Rings",
  "durationMinutes": 45,
  "id": 1
}

GET /shows

Response (200 OK):

[
  {
    "title": "Journey to the Rings",
    "durationMinutes": 45,
    "id": 1
  },
  {
    "title": "Black Hole Frontier",
    "durationMinutes": 30,
    "id": 2
  }
]

GET /shows/2

Response (200 OK):

{
  "title": "Black Hole Frontier",
  "durationMinutes": 30,
  "id": 2
}

GET /shows/99

Response (404 Not Found): empty body

DELETE /shows/2

Response (204 No Content): empty body

DELETE /shows/2 again

Response (404 Not Found): empty body

More in REST Controllers & Endpoints

See the module
Bird Sightings APIThis problem covers recording bird sightings and finding them by species, and what to show when nothing matches.100%2 of 2 solvedeasyVending Machine InventoryThis problem covers changing stored state from a request, and telling apart a slot that is empty from one that does not exist.100%2 of 2 solvedeasyComic Book Issue APIThis problem covers keeping child records inside their own parent, so one series never shows another series' issues.67%2 of 3 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.