31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
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"
|
|
}
|
|
} |