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
