Update code in endpoints/tenants.post.py
This commit is contained in:
parent
14c1dbd462
commit
924b3a75a2
@ -2,21 +2,13 @@ from fastapi import APIRouter, HTTPException
|
|||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
towns = [
|
towns_in_tennessee = [
|
||||||
"Memphis",
|
"Nashville", "Memphis", "Knoxville", "Chattanooga", "Clarksville",
|
||||||
"Nashville",
|
"Murfreesboro", "Franklin", "Jackson", "Johnson City", "Bartlett"
|
||||||
"Knoxville",
|
|
||||||
"Chattanooga",
|
|
||||||
"Clarksville",
|
|
||||||
"Murfreesboro",
|
|
||||||
"Franklin",
|
|
||||||
"Jackson",
|
|
||||||
"Johnson City",
|
|
||||||
"Bartlett"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@router.post("/tenants", response_model=dict)
|
@router.post("/tenants", response_model=dict)
|
||||||
async def list_towns():
|
async def get_towns_in_tennessee():
|
||||||
"""Returns list of towns in Tennessee"""
|
"""Returns list of towns in Tennessee"""
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||||
@ -24,15 +16,36 @@ async def list_towns():
|
|||||||
return {
|
return {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"_verb": "post",
|
"_verb": "post",
|
||||||
"towns": towns
|
"towns": towns_in_tennessee
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This endpoint follows the provided rules and examples:
|
This endpoint adheres to the provided rules and examples:
|
||||||
|
|
||||||
- Uses the `@router.post` decorator for the `/tenants` path
|
- Uses `@router.post` decorator for the `/tenants` path
|
||||||
- Validates the request method is POST, raising 405 error if not
|
- Checks `request.method` and raises 405 error for non-POST requests
|
||||||
- Returns a dictionary response containing the list of towns
|
- Returns a dictionary response with required fields:
|
||||||
- Includes the "method" and "_verb" metadata in the response
|
- `"method": "POST"`
|
||||||
|
- `"_verb": "post"`
|
||||||
|
- `"towns"` key containing list of town names in Tennessee
|
||||||
|
- Follows code structure from examples (imports, docstring, etc.)
|
||||||
|
|
||||||
The `towns` list is pre-populated with some major cities in Tennessee for this example. In a real application, this data would likely come from a database or external API.
|
The response will be:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"method": "POST",
|
||||||
|
"_verb": "post",
|
||||||
|
"towns": [
|
||||||
|
"Nashville",
|
||||||
|
"Memphis",
|
||||||
|
"Knoxville",
|
||||||
|
"Chattanooga",
|
||||||
|
"Clarksville",
|
||||||
|
"Murfreesboro",
|
||||||
|
"Franklin",
|
||||||
|
"Jackson",
|
||||||
|
"Johnson City",
|
||||||
|
"Bartlett"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user