from typing import Any from fastapi import APIRouter, Depends, status from sqlalchemy.orm import Session from sqlalchemy import text from app.db.session import get_db router = APIRouter() @router.get("/", status_code=status.HTTP_200_OK) def health_check(db: Session = Depends(get_db)) -> dict[str, Any]: """ Health check endpoint to verify the application is running correctly and database connection is working. """ health_data = { "status": "ok", "api": "healthy", "database": "healthy" } # Check database connectivity try: # Execute a simple query db.execute(text("SELECT 1")) except Exception as e: health_data["database"] = "unhealthy" health_data["status"] = "error" health_data["database_error"] = str(e) return health_data