32 lines
777 B
Python
32 lines
777 B
Python
from typing import Dict, Any
|
|
from fastapi import APIRouter
|
|
|
|
from app.db.session import engine
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", response_model=Dict[str, Any])
|
|
def health_check() -> Dict[str, Any]:
|
|
"""
|
|
Health check endpoint to verify the API is running correctly.
|
|
"""
|
|
health_status = {
|
|
"status": "ok",
|
|
"api_version": "0.1.0",
|
|
"db_connection": check_db_connection(),
|
|
}
|
|
return health_status
|
|
|
|
|
|
def check_db_connection() -> bool:
|
|
"""
|
|
Check if the database connection is working.
|
|
"""
|
|
try:
|
|
# Try to connect to the database
|
|
with engine.connect() as conn:
|
|
result = conn.execute("SELECT 1").fetchone()
|
|
return result is not None
|
|
except Exception:
|
|
return False |