34 lines
767 B
Python
34 lines
767 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from pydantic import BaseModel
|
|
|
|
from app.db.base import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
"""Health check response schema."""
|
|
|
|
status: str
|
|
database: bool
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
def health_check(db: Session = Depends(get_db)) -> HealthResponse:
|
|
"""
|
|
Health check endpoint.
|
|
|
|
Returns the health status of the API and its dependencies.
|
|
"""
|
|
# Check database connection
|
|
try:
|
|
db.execute("SELECT 1")
|
|
db_status = True
|
|
except Exception:
|
|
db_status = False
|
|
|
|
return HealthResponse(
|
|
status="ok" if db_status else "degraded",
|
|
database=db_status
|
|
) |