Skip to content

feat: list namespaces endpoint - #232

Open
gdccyuen wants to merge 1 commit into
Ontos-AI:mainfrom
gdccyuen:feat/gdccyuen/list-namespaces-endpoint
Open

feat: list namespaces endpoint#232
gdccyuen wants to merge 1 commit into
Ontos-AI:mainfrom
gdccyuen:feat/gdccyuen/list-namespaces-endpoint

Conversation

@gdccyuen

Copy link
Copy Markdown

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_status already covers the grouping query, so the cost is a single indexed scan.

Changes

  • apps/api/app/repositories/document_repository.py — new list_namespace_counts_for_user (GROUP BY namespace over non-archived docs, covered by idx_documents_user_namespace_status).
  • apps/api/app/services/documents/lifecycle_service.py — new list_namespaces service method.
  • apps/api/app/api/v1/routes/documents.py — new GET /namespaces route, declared before /{document_id} so FastAPI matches the literal path first.
  • apps/api/tests/contract/test_documents_contract.py — 2 contract tests:
    • per-user isolation: another user's namespaces are not visible; archived docs are excluded from counts.
    • empty case: returns {"namespaces": []} when the user has no documents.

Conventions matched

  • Filter is status != "archived" (matches existing list_by_user_namespace), not status = "active".
  • Auth via Depends(with_current_user); user-scoped at the repository layer.
  • Response shape parallels list_documents: top-level dict with a list field.

Verification

uv run pytest apps/api/tests/contract/test_documents_contract.py -q
19 passed in 14.96s

(includes 17 existing tests — no regressions.)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant