diff --git a/endpoints/tenants.post.py b/endpoints/tenants.post.py index 9e26c41..b8374aa 100644 --- a/endpoints/tenants.post.py +++ b/endpoints/tenants.post.py @@ -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. \ No newline at end of file +The response will be: + +```json +{ + "method": "POST", + "_verb": "post", + "towns": [ + "Nashville", + "Memphis", + "Knoxville", + "Chattanooga", + "Clarksville", + "Murfreesboro", + "Franklin", + "Jackson", + "Johnson City", + "Bartlett" + ] +} \ No newline at end of file