Problem statement
Build a case reader that hands an open case to anyone, keeps a sealed case to its lead alone, and stops the request with the right status, message and header when the case is missing or off limits.
Sample Data
The archive in app/store.py holds five cases under the ids 1_, _2, 4_, _6 and 9_, so _3 and 50 belong to no case. Three of them are sealed, and two leads hold more than one case. Here is one case record:
{
"id": 2,
"title": "Missing Inventory",
"lead": "kai",
"sealed": true
}
API Endpoints to Implement
fetch_case in app/services/cases.py locates the case and then decides whether the requester may read it. The route hands it a case_id from the URL and a requester from the query, text, optional, default anonymous.
- A case the archive does not hold stops the read with 404 and the body {"detail": "Case 3 was not found"}, naming the id that was asked for.
- A sealed case read by anyone but its lead stops the read with 403, the body {"detail": "Case 2 is sealed"} naming the case, and a header X-Sealed-By holding the lead's name.
- The requester must equal the lead exactly, letter case included, so Kai is not kai.
- An open case is read by anyone, named or not, and a sealed case is read by its lead.
- Response code: 200. The body is the case, holding id, title, lead and sealed.
- Neither a successful read nor the 404 carries X-Sealed-By.
- Both rejections stop the service itself rather than being answered by the route, so calling fetch_case directly raises them, carrying the same status, message and header. A rejected read leaves the archive readable.
Sample Requests & Responses
GET /cases/1, naming no requester
Response (200 OK):
{
"id": 1,
"title": "Warehouse Audit",
"lead": "rowan",
"sealed": false
}
GET /cases/2?requester=kai, the lead reading their own sealed case
Response (200 OK):
{
"id": 2,
"title": "Missing Inventory",
"lead": "kai",
"sealed": true
}
GET /cases/2?requester=rowan, a sealed case read by someone else, answered with an X-Sealed-By of kai
Response (403 Forbidden):
{
"detail": "Case 2 is sealed"
}
GET /cases/3
Response (404 Not Found):
{
"detail": "Case 3 was not found"
}
