
- Created project structure with FastAPI setup - Added SQLite database connection with SQLAlchemy ORM - Implemented Todo model and schemas - Added CRUD operations for Todo items - Created API endpoints for Todo management - Added health check endpoint - Configured Alembic for database migrations - Updated project documentation in README.md
28 lines
701 B
Python
28 lines
701 B
Python
from fastapi import APIRouter, Depends, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.session import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/", status_code=status.HTTP_200_OK)
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Check the health of the API.
|
|
"""
|
|
try:
|
|
# Validate database connection
|
|
db.execute("SELECT 1")
|
|
return {
|
|
"status": "ok",
|
|
"message": "API is healthy",
|
|
"database": "connected"
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
"status": "error",
|
|
"message": "API health check failed",
|
|
"database": "disconnected",
|
|
"error": str(e)
|
|
} |