Problem statement
The four account endpoints answer with nothing, and the detail shape is a copy of the register's internal one. Give the API its output contract: a lean list that reports only what an account actually set, a complete read that reports everything public including nulls, the right code on every outcome, and three internal values that never leave the service.
Sample Data
The register in app/store.py holds five accounts under the ids 1_, _2, 3_, _5 and 8_, so _4 and 99 belong to nobody, and the next account opened takes the id 9_. They are stored as _AccountRecord, which is an AccountSummary plus email, currency, opened_on, closed_on and the three internal values. Each supplied a different set of optional values: one supplied all of them, one supplied only id, name, email, opened_on and its settlement key, and the rest fall in between. One supplied a nickname of null and two supplied a value that happens to equal the default.
API Endpoints to Implement
AccountDetail
The public detail shape, in app/models/account_detail.py. Give it these ten fields, every one of them required so that a read reports all ten whatever the account supplied:
- id, a whole number.
- name, text.
- status, text.
- nickname, text or null.
- balance, a number.
- email, text.
- currency, text.
- opened_on, text.
- closed_on, text or null.
- tags, a list of text.
settlement_key, risk_score and internal_note are the internal three. They may not appear in any answer, and they may not appear anywhere in the published description either.
GET /accounts
Answers 200 with every account in register order, each reported through AccountSummary, which declares id and name as required and status, nickname, balance and tags with defaults.
- A field an account never supplied is left out, even when the field has a default.
- A field an account supplied is reported, including when the value equals the default, so a supplied balance of 0.0 and a supplied empty tags list both appear.
- A field supplied as null is left out rather than reported as null, so no entry carries a null anywhere.
GET /accounts/{account_id}
- account_id comes from the URL as a whole number.
- Answers 200 with that account through AccountDetail, looked up with find_account in app/services/accounts.py. All ten fields appear, so a value the account never supplied is reported at its default and a value that is null is reported as null. The same account is lean in the list and complete here.
- An account id the register does not hold is answered with 404 and the body {"detail": "Account 4 was not found"}, that sentence and nothing else.
POST /accounts
- Takes the body as an AccountCreate, the draft holding name, email, nickname and currency, and hands it to open_account, which gives the account its id, its opening date and its internal values.
- Answers 201, not the default success code, with the opened account through AccountDetail.
DELETE /accounts/{account_id}
- Removes that account with close_account and answers 204, not the default success code, with a body that is empty rather than null.
- An account id the register does not hold is answered with the same 404 as the read, so closing the same account twice reports the second attempt as not found.
Rejected requests
An account_id in the URL that is not a whole number, and a draft missing a required value or carrying one of the wrong kind, are each answered with 422 and one detail entry per broken rule, carrying loc of ["path", "account_id"] or ["body", "field name"], the input that was received, and the type and msg reported for the rule.
The shapes and the codes must be declared on the operations rather than assembled by hand, since the service publishes them at GET /openapi.json, where the list answers with a list of one named shape and the read and the creation with another, the summary shape requires only id and name while the detail shape requires all ten of its fields, the creation reports 201 and the removal 204 with neither reporting 200, the removal declares no response content, every operation that takes input declares 422, and no published shape names any of the internal three.
Sample Requests & Responses
GET /accounts
Response (200 OK):
[
{"id": 1, "name": "Northwind Trading", "status": "active", "nickname": "Ops Float", "balance": 15240.75, "tags": ["priority", "eu"]},
{"id": 2, "name": "Lakeside Bakery"},
{"id": 3, "name": "Cobalt Robotics", "balance": 0.0, "tags": ["beta"]},
{"id": 5, "name": "Harbor Logistics", "status": "closed", "nickname": "Winter Fleet", "balance": -120.5, "tags": []},
{"id": 8, "name": "Vertex Analytics", "status": "frozen", "balance": 902.4, "tags": ["priority"]}
]
GET /accounts/2
Response (200 OK):
{
"id": 2,
"name": "Lakeside Bakery",
"status": "active",
"nickname": null,
"balance": 0.0,
"email": "hello@lakeside.example",
"currency": "USD",
"opened_on": "2024-03-02",
"closed_on": null,
"tags": []
}
POST /accounts
Request:
{
"name": "Solstice Ceramics",
"email": "ap@solstice.example"
}
Response (201 Created):
{
"id": 9,
"name": "Solstice Ceramics",
"status": "active",
"nickname": null,
"balance": 0.0,
"email": "ap@solstice.example",
"currency": "USD",
"opened_on": "2026-03-01",
"closed_on": null,
"tags": []
}
GET /accounts/4
Response (404 Not Found):
{
"detail": "Account 4 was not found"
}
DELETE /accounts/3
Response (204 No Content), with no body at all.
