Update code in endpoints/d.post.py
This commit is contained in:
parent
29bc4f598d
commit
070d2c29df
@ -1,31 +1,38 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from core.database import fake_users_db
|
from core.database import fake_users_db
|
||||||
from typing import List
|
import uuid
|
||||||
|
|
||||||
router = APIRouter()
|
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")
|
@router.post("/d")
|
||||||
async def get_d_countries():
|
async def create_db_handler():
|
||||||
"""Get all countries that start with the letter D"""
|
"""Create a new demo database"""
|
||||||
d_countries = {k: v for k, v in countries_db.items() if k.startswith('d')}
|
db_id = str(uuid.uuid4())
|
||||||
|
|
||||||
if not d_countries:
|
if "databases" not in fake_users_db:
|
||||||
raise HTTPException(status_code=404, detail="No countries found starting with 'D'")
|
fake_users_db["databases"] = {}
|
||||||
|
|
||||||
|
fake_users_db["databases"][db_id] = {
|
||||||
|
"id": db_id,
|
||||||
|
"created_at": "2024-01-01T00:00:00Z",
|
||||||
|
"status": "active",
|
||||||
|
"tables": [],
|
||||||
|
"settings": {
|
||||||
|
"max_connections": 100,
|
||||||
|
"timeout": 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"message": "Countries retrieved successfully",
|
"message": "Database created successfully",
|
||||||
"data": d_countries,
|
"db_id": db_id,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"count": len(d_countries),
|
"created_at": "2024-01-01T00:00:00Z",
|
||||||
"starting_letter": "D",
|
"region": "demo-region"
|
||||||
"source": "demo_countries_db"
|
},
|
||||||
}
|
"next_steps": [
|
||||||
|
"Configure database settings",
|
||||||
|
"Create tables",
|
||||||
|
"Set up backup schedule"
|
||||||
|
]
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user