Update code in endpoints/d.post.py
This commit is contained in:
parent
16689a0e64
commit
29bc4f598d
@ -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"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user