28 lines
711 B
Python
28 lines
711 B
Python
from fastapi import APIRouter, Depends, status
|
|
from sqlalchemy.orm import Session
|
|
from app.db.session import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", status_code=status.HTTP_200_OK)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint.
|
|
Returns status of the API and database connection.
|
|
"""
|
|
health_status = {
|
|
"status": "healthy",
|
|
"api": "up",
|
|
"database": "up",
|
|
}
|
|
|
|
# Test database connection
|
|
try:
|
|
# Execute a simple query
|
|
db.execute("SELECT 1")
|
|
except Exception as e:
|
|
health_status["status"] = "unhealthy"
|
|
health_status["database"] = f"down: {str(e)}"
|
|
|
|
return health_status |