- upload.py: request_upload_url, upload_document, confirm_upload (3 routes) - crud.py: list_documents, get_document, patch_document, delete_document, classify_document (5 routes) - content.py: stream_document_content + _parse_range (1 route) - shared.py: _CLOUD_PROVIDERS, UploadUrlRequest, DocumentPatch (single definitions) - __init__.py: router aggregator prefix=/api/documents, 9 routes total - documents.py monolith deleted; all URL paths unchanged - list_documents registered on parent router to avoid FastAPI empty-path/prefix check - get_storage_backend_for_document re-exported for test monkeypatching compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
1.4 KiB
Python
29 lines
1.4 KiB
Python
"""Document API package — router aggregator.
|
|
|
|
Aggregates upload_router, crud_router, and content_router under a single
|
|
APIRouter with prefix="/api/documents". This is the ONLY file in the package
|
|
that sets the prefix — sub-routers declare no prefix (D-04).
|
|
|
|
main.py import unchanged after decomposition:
|
|
from api.documents import router as documents_router
|
|
app.include_router(documents_router)
|
|
"""
|
|
from fastapi import APIRouter
|
|
|
|
from api.documents.upload import router as upload_router
|
|
from api.documents.crud import router as crud_router, list_documents
|
|
from api.documents.content import router as content_router
|
|
# Re-export for test monkeypatching: tests patch api.documents.extract_and_classify.delay
|
|
# (same Celery task object as upload.py uses — patching .delay affects all callers)
|
|
from tasks.document_tasks import extract_and_classify # noqa: F401
|
|
from storage import get_storage_backend_for_document # noqa: F401
|
|
|
|
router = APIRouter(prefix="/api/documents", tags=["documents"])
|
|
router.include_router(upload_router)
|
|
# list_documents registered directly on parent: FastAPI 0.100+ disallows include_router
|
|
# when the include prefix AND route path are both empty strings (our sub-router pattern
|
|
# uses no prefix per D-04, and the list endpoint has path="").
|
|
router.add_api_route("", list_documents, methods=["GET"])
|
|
router.include_router(crud_router)
|
|
router.include_router(content_router)
|