feat: list namespaces endpoint - #232
Open
gdccyuen wants to merge 1 commit into
Open
Conversation
Add GET /api/v1/documents/namespaces returning the authenticated user's namespaces with active document counts. Per-user isolation and archived doc exclusion follow the existing list_documents conventions; query is covered by idx_documents_user_namespace_status. Previously users had no way to discover namespaces they had uploaded to since namespace is a free-form string label on document creation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
GET /api/v1/documents/namespaces— returns the authenticated user's namespaces with active document counts.{ "namespaces": [ {"namespace": "alpha", "document_count": 2}, {"namespace": "beta", "document_count": 1} ] }Why
Currently a user has no way to discover which namespaces they have uploaded documents to. Namespace is a free-form string label set at job creation; without a list endpoint, callers must track namespaces themselves (issue raised during self-hosted deployment review). The composite index
idx_documents_user_namespace_statusalready covers the grouping query, so the cost is a single indexed scan.Changes
apps/api/app/repositories/document_repository.py— newlist_namespace_counts_for_user(GROUP BY namespaceover non-archived docs, covered byidx_documents_user_namespace_status).apps/api/app/services/documents/lifecycle_service.py— newlist_namespacesservice method.apps/api/app/api/v1/routes/documents.py— newGET /namespacesroute, declared before/{document_id}so FastAPI matches the literal path first.apps/api/tests/contract/test_documents_contract.py— 2 contract tests:{"namespaces": []}when the user has no documents.Conventions matched
status != "archived"(matches existinglist_by_user_namespace), notstatus = "active".Depends(with_current_user); user-scoped at the repository layer.list_documents: top-level dict with a list field.Verification
(includes 17 existing tests — no regressions.)