Update code in endpoints/open.post.py
This commit is contained in:
parent
5c62b887ad
commit
552af07825
@ -1,27 +1,31 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
towns = [
|
||||
{"name": "Yaoundé", "region": "Centre"},
|
||||
{"name": "Douala", "region": "Littoral"},
|
||||
{"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()
|
||||
|
||||
towns_in_arizona = [
|
||||
"Phoenix",
|
||||
"Tucson",
|
||||
"Mesa",
|
||||
"Chandler",
|
||||
"Glendale",
|
||||
"Scottsdale",
|
||||
"Gilbert",
|
||||
"Tempe",
|
||||
"Peoria",
|
||||
"Surprise"
|
||||
]
|
||||
|
||||
@router.post("/open", response_model=dict)
|
||||
async def get_towns_in_arizona(request: dict):
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
@router.post("/open")
|
||||
async def get_towns():
|
||||
"""Returns list of towns in Cameroon"""
|
||||
if not towns:
|
||||
raise HTTPException(status_code=404, detail="No towns found")
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
"towns": towns_in_arizona
|
||||
"data": 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.
|
Loading…
x
Reference in New Issue
Block a user