From ede6906d8ed74a5e47e6f1433de46751c5eb9118 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 09:13:29 +0100 Subject: [PATCH] Update code in endpoints/turkey.post.py --- endpoints/turkey.post.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 endpoints/turkey.post.py diff --git a/endpoints/turkey.post.py b/endpoints/turkey.post.py new file mode 100644 index 0000000..9e46dd9 --- /dev/null +++ b/endpoints/turkey.post.py @@ -0,0 +1,31 @@ +from fastapi import APIRouter, HTTPException + +router = APIRouter() + +states = [ + "Adana", "Adıyaman", "Afyonkarahisar", "Ağrı", "Amasya", "Ankara", "Antalya", + "Artvin", "Aydın", "Balıkesir", "Bilecik", "Bingöl", "Bitlis", "Bolu", "Burdur", + "Bursa", "Çanakkale", "Çankırı", "Çorum", "Denizli", "Diyarbakır", "Edirne", + "Elazığ", "Erzincan", "Erzurum", "Eskişehir", "Gaziantep", "Giresun", "Gümüşhane", + "Hakkâri", "Hatay", "Isparta", "Mersin", "İstanbul", "İzmir", "Kars", "Kastamonu", + "Kayseri", "Kırklareli", "Kırşehir", "Kocaeli", "Konya", "Kütahya", "Malatya", + "Manisa", "Kahramanmaraş", "Mardin", "Muğla", "Muş", "Nevşehir", "Niğde", "Ordu", + "Rize", "Sakarya", "Samsun", "Siirt", "Sinop", "Sivas", "Tekirdağ", "Tokat", + "Trabzon", "Tunceli", "Şanlıurfa", "Uşak", "Van", "Yozgat", "Zonguldak", "Aksaray", + "Bayburt", "Karaman", "Kırıkkale", "Batman", "Şırnak", "Bartın", "Ardahan", "Iğdır", + "Yalova", "Karabük", "Kilis", "Osmaniye", "Düzce" +] + +@router.post("/turkey") +async def get_states(request): + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + return { + "method": "POST", + "_verb": "post", + "states": states + } +``` + +This endpoint follows the provided requirements and returns a list of states in Turkey when a POST request is made to the "/turkey" path. The states are stored in a list at the top of the file. The endpoint checks if the request method is POST, and if not, it raises an HTTPException with a 405 Method Not Allowed status code. If the method is POST, it returns a dictionary containing the method, a "_verb" key with the value "post", and the list of states. \ No newline at end of file