Skip to content

Commit

Permalink
docs: adding some FastAPI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dfulmer authored and niquerio committed Oct 16, 2024
1 parent 8b97db7 commit 0c013ca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff"
},
}
26 changes: 23 additions & 3 deletions aim/digifeeds/database/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ def get_items(
return db_items


@app.get("/items/{barcode}", response_model_by_alias=False, tags=["Digifeeds Database"])
@app.get(
"/items/{barcode}",
response_model_by_alias=False,
responses={
404: {
"description": "Bad request</br></br>The item doesn't exist",
"model": schemas.Response404,
}
},
tags=["Digifeeds Database"],
)
def get_item(
barcode: str = Path(..., description="The barcode of the item"),
db: Session = Depends(get_db),
Expand All @@ -78,7 +88,7 @@ def get_item(
"model": schemas.Response400,
}
},
tags=["Digifeeds Database"]
tags=["Digifeeds Database"],
)
def create_item(
barcode: str = Path(..., description="The barcode of the item"),
Expand All @@ -98,7 +108,17 @@ def create_item(
return db_item


@app.put("/items/{barcode}/status/{status_name}", response_model_by_alias=False, tags=["Digifeeds Database"])
@app.put(
"/items/{barcode}/status/{status_name}",
response_model_by_alias=False,
responses={
404: {
"description": "Bad request</br></br>The item or status doesn't exist",
"model": schemas.Response404,
}
},
tags=["Digifeeds Database"],
)
def update_item(
barcode: str, status_name: str, db: Session = Depends(get_db)
) -> schemas.Item:
Expand Down
11 changes: 11 additions & 0 deletions aim/digifeeds/database/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ class Response400(Response):
]
}
)

class Response404(Response):
model_config = ConfigDict(
json_schema_extra={
"examples": [
{
"detail": "Item not found.",
}
]
}
)

0 comments on commit 0c013ca

Please sign in to comment.