
- Set up project structure with FastAPI and SQLite - Created Todo model and database schemas - Implemented CRUD operations for Todo items - Added Alembic for database migrations - Added health check endpoint - Used Ruff for code linting and formatting - Updated README with project documentation
28 lines
610 B
Python
28 lines
610 B
Python
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.session import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class HealthResponse(BaseModel):
|
|
status: str
|
|
db_status: str
|
|
|
|
|
|
@router.get("/health", response_model=HealthResponse)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Check the health of the application.
|
|
"""
|
|
# Check DB connection
|
|
try:
|
|
db.execute("SELECT 1")
|
|
db_status = "healthy"
|
|
except Exception:
|
|
db_status = "unhealthy"
|
|
|
|
return HealthResponse(status="healthy", db_status=db_status)
|