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()
|
||||
|
||||
towns = [
|
||||
"Memphis",
|
||||
"Nashville",
|
||||
"Knoxville",
|
||||
"Chattanooga",
|
||||
"Clarksville",
|
||||
"Murfreesboro",
|
||||
"Franklin",
|
||||
"Jackson",
|
||||
"Johnson City",
|
||||
"Bartlett"
|
||||
towns_in_tennessee = [
|
||||
"Nashville", "Memphis", "Knoxville", "Chattanooga", "Clarksville",
|
||||
"Murfreesboro", "Franklin", "Jackson", "Johnson City", "Bartlett"
|
||||
]
|
||||
|
||||
@router.post("/tenants", response_model=dict)
|
||||
async def list_towns():
|
||||
async def get_towns_in_tennessee():
|
||||
"""Returns list of towns in Tennessee"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
@ -24,15 +16,36 @@ async def list_towns():
|
||||
return {
|
||||
"method": "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
|
||||
- Validates the request method is POST, raising 405 error if not
|
||||
- Returns a dictionary response containing the list of towns
|
||||
- Includes the "method" and "_verb" metadata in the response
|
||||
- Uses `@router.post` decorator for the `/tenants` path
|
||||
- Checks `request.method` and raises 405 error for non-POST requests
|
||||
- Returns a dictionary response with required fields:
|
||||
- `"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