Problem statement
Build a REST API for tracking board game collections where every game belongs to one owner.
Requirements
GameRepository
Give the repository a way to fetch every game that belongs to one owner, ordered by title ascending. The controller uses it to build the list response.
CollectionController
Implement the three REST endpoints. Each endpoint must be reachable at exactly the verb and path listed below. On every endpoint, an ownerId that matches no owner returns 404 Not Found with error message: "Owner not found with id: " followed by the requested ownerId, and changes nothing.
GET /owners/{ownerId}/games
- Return 200 OK with that owner's games ordered by title ascending
- Each listed game carries its id, title, minPlayers, and ownerId
- Games of other owners never appear in the list, whatever their titles
- Return 200 OK with an empty array when the owner has no games
POST /owners/{ownerId}/games
- Accept a JSON body with title and minPlayers and validate it
- If title is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Title must not be blank"
- If minPlayers is missing, return 400 Bad Request with error message: "Minimum players is required"
- If minPlayers is less than 1, return 400 Bad Request with error message: "Minimum players must be at least 1"; a value of exactly 1 is valid
- A rejected request must not add anything, and neither must a request addressed to an unknown owner
- On a valid body, save the game under that owner and return 201 Created with the created game, including its generated id and the ownerId of that owner
- The created game appears in its own owner's list at its place in title order, and in no other owner's list
DELETE /owners/{ownerId}
- Remove the owner and return 204 No Content with an empty body
- Removing the owner also removes every game of that owner's collection; afterwards no game of that owner remains stored
- An owner that has no games can be removed the same way
- The other owner and that owner's games are left untouched
- After a successful removal, listing the removed owner's games returns 404 Not Found, because the owner no longer exists
Sample Requests & Responses
Expand to view details on sample requests and responses.
POST /owners/1/games
Request:
{
"title": "Wingspan",
"minPlayers": 1
}
Response (201 Created):
{
"id": 1,
"title": "Wingspan",
"minPlayers": 1,
"ownerId": 1
}
POST /owners/1/games
Request:
{
"title": "Azul",
"minPlayers": 2
}
Response (201 Created):
{
"id": 2,
"title": "Azul",
"minPlayers": 2,
"ownerId": 1
}
GET /owners/1/games
Response (200 OK):
[
{
"id": 2,
"title": "Azul",
"minPlayers": 2,
"ownerId": 1
},
{
"id": 1,
"title": "Wingspan",
"minPlayers": 1,
"ownerId": 1
}
]
POST /owners/1/games
Request:
{
"title": "",
"minPlayers": 2
}
Response (400 Bad Request):
{
"error": "Title must not be blank",
"timestamp": "2026-07-30T10:17:41.518921",
"path": "/owners/1/games"
}
POST /owners/1/games
Request:
{
"title": "Catan"
}
Response (400 Bad Request):
{
"error": "Minimum players is required",
"timestamp": "2026-07-30T10:17:41.818039",
"path": "/owners/1/games"
}
POST /owners/1/games
Request:
{
"title": "Catan",
"minPlayers": 0
}
Response (400 Bad Request):
{
"error": "Minimum players must be at least 1",
"timestamp": "2026-07-30T10:17:42.701093",
"path": "/owners/1/games"
}
GET /owners/9999/games
Response (404 Not Found):
{
"error": "Owner not found with id: 9999",
"timestamp": "2026-07-30T10:17:43.364203",
"path": "/owners/9999/games"
}
DELETE /owners/1
Response (204 No Content): empty body
GET /owners/1/games
Response (404 Not Found):
{
"error": "Owner not found with id: 1",
"timestamp": "2026-07-30T10:17:44.143267",
"path": "/owners/1/games"
}
