31 lines
809 B
Python
31 lines
809 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from datetime import datetime
|
|
from pydantic import BaseModel
|
|
|
|
from app.database import get_db
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
timestamp: datetime
|
|
db_status: str
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
async def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint to verify the API is running and can connect to the database
|
|
"""
|
|
db_status = "ok"
|
|
try:
|
|
# Try to execute a simple query to check database connection
|
|
db.execute("SELECT 1")
|
|
except Exception:
|
|
db_status = "error"
|
|
|
|
return {
|
|
"status": "ok",
|
|
"timestamp": datetime.utcnow(),
|
|
"db_status": db_status
|
|
} |