From 29bc4f598deca887074cd74e4b0f45ade9595ae1 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Thu, 20 Mar 2025 21:58:45 +0000 Subject: [PATCH] Update code in endpoints/d.post.py --- endpoints/d.post.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/endpoints/d.post.py b/endpoints/d.post.py index e69de29..07885d8 100644 --- a/endpoints/d.post.py +++ b/endpoints/d.post.py @@ -0,0 +1,31 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +from typing import List + +router = APIRouter() + +# Demo database of countries +countries_db = { + "denmark": {"name": "Denmark", "capital": "Copenhagen", "population": 5831000}, + "djibouti": {"name": "Djibouti", "capital": "Djibouti", "population": 988000}, + "dominica": {"name": "Dominica", "capital": "Roseau", "population": 71986}, + "dominican_republic": {"name": "Dominican Republic", "capital": "Santo Domingo", "population": 10847910} +} + +@router.post("/d") +async def get_d_countries(): + """Get all countries that start with the letter D""" + d_countries = {k: v for k, v in countries_db.items() if k.startswith('d')} + + if not d_countries: + raise HTTPException(status_code=404, detail="No countries found starting with 'D'") + + return { + "message": "Countries retrieved successfully", + "data": d_countries, + "metadata": { + "count": len(d_countries), + "starting_letter": "D", + "source": "demo_countries_db" + } + } \ No newline at end of file