Skip to content

feat(api): add paginated document list and detail endpoints - #22

Merged
johnnyhuy merged 1 commit into
mainfrom
agent/issue-21-document-endpoints
Nov 9, 2026
Merged

johnnyhuy merged 1 commit into
mainfrom
agent/issue-21-document-endpoints

Conversation

@johnnyhuy

Copy link
Copy Markdown
Contributor

What changed

GET /api/documents now returns a paginated envelope (items, total, limit, offset) ordered most recently created first, with an optional source filter and a truncated content_preview per item, matching the conversation endpoints. A new GET /api/documents/{document_id} returns one document with its full content or 404, and the frontend client in frontend/lib/api.ts now matches the new shape with a getDocument helper.

Part of #5
Closes #21

How it was verified

  • mise run install - frontend installed cleanly. The backend needed the worktree venv recreated with the mise-pinned Python 3.13, because the default Python 3.14 cannot build a chromadb dependency. The uv.lock churn from that sync was reverted, so no lockfile change is in this PR.
  • mise run test-backend - 67 passed, including the 8 new tests in backend/tests/test_documents.py (ordering, preview truncation, pagination, source filter, empty list, detail, missing-document 404, invalid pagination). The new file swaps its database override per test so it cannot clobber the conversation tests when the files run together.
  • mise run test-frontend - passed (the repo task currently reports no frontend tests yet).
  • mise run test-runtime - 7 passed. Unchanged by this slice, run as a sanity check.
  • Frontend build - bun run build in frontend/ compiled and type-checked cleanly, which covers the lib/api.ts changes.
  • Backend startup - the backend came up offline with Slack auth stubbed using the repo test pattern and a local sqlite database. The log showed "Starting Wingman backend..." and "Database initialized", and GET /health returned 200.

Proof

Capture method (a) succeeded offline. Nothing connected to a live Slack workspace, and no Socket Mode was run.

$ curl -s http://127.0.0.1:8000/health
{"status":"healthy"}
$ curl -s "http://127.0.0.1:8000/api/documents?limit=1&offset=0"
{"items":[{"id":2,"title":"Office hours","source":"docs","created_at":"2026-11-09T14:23:03.791109","content_preview":"Nine to five."}],"total":2,"limit":1,"offset":0}
$ curl -s "http://127.0.0.1:8000/api/documents?source=docs"
{"items":[{"id":2,"title":"Office hours","source":"docs","created_at":"2026-11-09T14:23:03.791109","content_preview":"Nine to five."}],"total":1,"limit":50,"offset":0}
$ curl -s http://127.0.0.1:8000/api/documents/1
{"id":1,"title":"VPN guide","content":"Use the IT portal to reset VPN.","source":"api","created_at":"2026-11-09T14:23:03.791103","updated_at":"2026-11-09T14:23:03.791108"}
$ curl -s http://127.0.0.1:8000/api/documents/999999
{"detail":"Document not found"} [404]
$ curl -s "http://127.0.0.1:8000/api/documents?limit=0"
{"detail":[{"type":"greater_than_equal","loc":["query","limit"],"msg":"Input should be greater than or equal to 1","input":"0","ctx":{"ge":1}}]} [422]

Reviewer notes

  • Nothing user-facing in the frontend changed in this slice beyond the API client types and helpers, so there is no screenshot. Frontend capture (b) was not applicable beyond the production build above.
  • The response shape of GET /api/documents changed from a bare list to the paginated envelope. The only in-repo caller is listDocuments in frontend/lib/api.ts, updated here. Anything outside this repo reading that endpoint needs the same update.
  • Parent Build conversation and document management dashboard MVP #5 stays open. Wiring the dashboard Documents tab to these endpoints, document delete or re-indexing, and the conversation browser UI are still outstanding.
  • No live Slack verification is needed for this slice. The endpoints read the document table only.

@johnnyhuy
johnnyhuy merged commit 8b76f58 into main Nov 9, 2026
10 checks passed
@johnnyhuy
johnnyhuy deleted the agent/issue-21-document-endpoints branch November 9, 2026 14:26
@github-actions github-actions Bot mentioned this pull request Nov 9, 2026
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.

Add paginated document list and document detail endpoints

1 participant