Problem statement
Build the REST endpoints for comic book issues that live under a series, using every verb, status code and parameter type from this module.
Requirements
The Series and Issue entities, the request bodies, the ErrorResponse body and the IssueService are already provided. Your task is to write the four endpoints in IssueController. Issues live under a series, so every path starts with /series/{seriesId}/issues, and a seriesId or id that is not a number returns 400 Bad Request.
IssueService
- seriesExists(seriesId) tells whether the series exists, and titleTaken(seriesId, title) whether it already has an issue with that title
- findBySeries(seriesId) returns the issues of the series, and findBySeriesAndTitle(seriesId, title) only those with exactly that title
- findInSeries(seriesId, id) returns an Optional holding the issue only when it belongs to the series
- create(seriesId, request), save(issue) and delete(issue) create, save and delete issues
IssueController
GET /series/{seriesId}/issues
- Return 200 OK with the issues of the series; issues of other series never appear
- Read an optional title query parameter; when it is sent, return only the issues of the series with that title
- Return 404 Not Found when no series has that seriesId
POST /series/{seriesId}/issues
- Read a JSON body with title and pageCount, save the issue in the series, and return 201 Created with the saved issue
- When the series already has an issue with that title, return 409 Conflict with an ErrorResponse whose error is "Issue already exists: " followed by the title
- Return 404 Not Found when no series has that seriesId
PATCH /series/{seriesId}/issues/{id}
- Read a JSON body in which title and pageCount are both optional
- Change only the fields that are sent, keep the others, save the issue, and return 200 OK with it
DELETE /series/{seriesId}/issues/{id}
- Delete the issue and return 204 No Content with an empty body
On PATCH and DELETE, return 404 Not Found when no issue with that id belongs to the series, even if the issue exists under another series.
Sample Requests & Responses
GET /series/1/issues
Response (200 OK):
[
{
"title": "Origins",
"pageCount": 32,
"seriesId": 1,
"id": 1
},
{
"title": "Dark Moon",
"pageCount": 28,
"seriesId": 1,
"id": 2
}
]
GET /series/1/issues?title=Dark Moon
Response (200 OK):
[
{
"title": "Dark Moon",
"pageCount": 28,
"seriesId": 1,
"id": 2
}
]
POST /series/1/issues
Request:
{
"title": "Dark Moon",
"pageCount": 30
}
Response (409 Conflict):
{
"error": "Issue already exists: Dark Moon"
}
PATCH /series/1/issues/2
Request:
{
"title": "Dark Moon Rising"
}
Response (200 OK):
{
"title": "Dark Moon Rising",
"pageCount": 28,
"seriesId": 1,
"id": 2
}
PATCH /series/2/issues/2
Request:
{
"title": "Wrong Series"
}
Response (404 Not Found): empty body
DELETE /series/1/issues/2
Response (204 No Content): empty body
GET /series/99/issues
Response (404 Not Found): empty body
