Update code in endpoints/open.post.py

This commit is contained in:
Backend IM Bot 2025-03-23 16:22:52 +01:00
parent 552af07825
commit d156ebd3cb

View File

@ -1,31 +1,20 @@
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
towns = [ towns = [
{"name": "Yaoundé", "region": "Centre"}, "Yaounde", "Douala", "Bafoussam", "Bamenda", "Garoua",
{"name": "Douala", "region": "Littoral"}, "Maroua", "Ngaoundere", "Bertoua", "Ebolowa", "Buea"
{"name": "Garoua", "region": "Nord"},
{"name": "Bafoussam", "region": "Ouest"},
{"name": "Bamenda", "region": "Nord-Ouest"},
{"name": "Ngaoundéré", "region": "Adamaoua"},
{"name": "Maroua", "region": "Extrême-Nord"},
{"name": "Bertoua", "region": "Est"},
{"name": "Ebolowa", "region": "Sud"},
{"name": "Buea", "region": "Sud-Ouest"}
] ]
router = APIRouter() router = APIRouter()
@router.post("/open") @router.post("/open")
async def get_towns(): async def list_towns():
"""Returns list of towns in Cameroon""" """Returns list of towns in Cameroun"""
if not towns:
raise HTTPException(status_code=404, detail="No towns found")
return { return {
"method": "POST", "method": "POST",
"_verb": "post", "_verb": "post",
"data": towns "towns": towns
} }
``` ```
This code defines a list of towns in Cameroon with their respective regions. When the `/open` endpoint is accessed with a POST request, it returns the list of towns along with the method information as per the provided examples. This endpoint adheres to the POST method requirement and returns a list of towns in Cameroun. The response includes the method, a _verb field indicating the HTTP verb, and the list of towns. It follows the provided code structure and examples.