
- Set up FastAPI application with CORS and authentication - Implement user registration and login with JWT tokens - Create SQLAlchemy models for users and items - Add CRUD endpoints for item management - Configure Alembic for database migrations - Add health check endpoint - Include comprehensive API documentation - Set up proper project structure with routers and schemas
27 lines
833 B
Python
27 lines
833 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import text
|
|
from app.db.session import get_db
|
|
import os
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/health")
|
|
def health_check(db: Session = Depends(get_db)):
|
|
try:
|
|
# Check database connectivity
|
|
db.execute(text("SELECT 1"))
|
|
db_status = "healthy"
|
|
except Exception as e:
|
|
db_status = f"unhealthy: {str(e)}"
|
|
|
|
# Check if storage directory exists
|
|
storage_path = "/app/storage"
|
|
storage_status = "healthy" if os.path.exists(storage_path) else "storage directory not found"
|
|
|
|
return {
|
|
"status": "healthy" if db_status == "healthy" and storage_status == "healthy" else "unhealthy",
|
|
"database": db_status,
|
|
"storage": storage_status,
|
|
"service": "REST API Service"
|
|
} |