
This commit implements a simple movie database backend inspired by IMDb. It includes: - API endpoints for movies, actors, directors and genres - SQLAlchemy models with relationships - Alembic migrations - Pydantic schemas for request/response validation - Search and filtering functionality - Health check endpoint - Complete documentation
32 lines
881 B
Python
32 lines
881 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.schemas.health import HealthCheck
|
|
from app.db.session import get_db
|
|
from app.core.config import settings
|
|
|
|
router = APIRouter(prefix="/health")
|
|
|
|
|
|
@router.get("", response_model=HealthCheck, tags=["health"])
|
|
async def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Checks the health of the application.
|
|
"""
|
|
health_data = {
|
|
"status": "ok",
|
|
"version": settings.VERSION,
|
|
"db_status": "ok",
|
|
"details": {}
|
|
}
|
|
|
|
# Check database connection
|
|
try:
|
|
# Execute a simple query to check if the database is responding
|
|
db.execute("SELECT 1")
|
|
except Exception as e:
|
|
health_data["status"] = "error"
|
|
health_data["db_status"] = "error"
|
|
health_data["details"]["db_error"] = str(e)
|
|
|
|
return health_data |