27 lines
577 B
Python
27 lines
577 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.db.session import get_db
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
db_connection: bool
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
# Check database connection
|
|
try:
|
|
db.execute("SELECT 1")
|
|
db_status = True
|
|
except Exception:
|
|
db_status = False
|
|
|
|
return HealthResponse(
|
|
status="ok",
|
|
db_connection=db_status
|
|
) |