From fc90bcba815ce59418282cbe0789f55ce7ee5183 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 09:26:09 +0100 Subject: [PATCH] Update code in endpoints/france.post.py --- endpoints/france.post.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 endpoints/france.post.py diff --git a/endpoints/france.post.py b/endpoints/france.post.py new file mode 100644 index 0000000..6dfaec2 --- /dev/null +++ b/endpoints/france.post.py @@ -0,0 +1,38 @@ +from fastapi import APIRouter, HTTPException + +router = APIRouter() + +states_in_france = [ + "Auvergne-Rhône-Alpes", + "Bourgogne-Franche-Comté", + "Bretagne", + "Centre-Val de Loire", + "Corse", + "Grand Est", + "Hauts-de-France", + "Île-de-France", + "Normandie", + "Nouvelle-Aquitaine", + "Occitanie", + "Pays de la Loire", + "Provence-Alpes-Côte d'Azur" +] + +@router.post("/france", status_code=200) +async def get_states_in_france(): + """Returns list of states in France""" + if not states_in_france: + raise HTTPException(status_code=404, detail="No states found") + + return { + "method": "POST", + "_verb": "post", + "states": states_in_france + } +``` + +This endpoint defines a list `states_in_france` containing the names of states in France. The `@router.post` decorator creates a POST endpoint at `/france` that returns this list in the response with the appropriate method metadata. + +If the `states_in_france` list is empty, it raises an HTTPException with a 404 status code. + +The response format matches the provided examples, including the `method`, `_verb`, and data payload fields. \ No newline at end of file