Skip to content

[FIX] DocumentAPI to query by params and return multiple documents & fix PDF file fetching#123

Merged
JonnyTran merged 8 commits into
developfrom
feat/files-presigned-url-for-pdfs
Aug 12, 2025
Merged

[FIX] DocumentAPI to query by params and return multiple documents & fix PDF file fetching#123
JonnyTran merged 8 commits into
developfrom
feat/files-presigned-url-for-pdfs

Conversation

@JonnyTran
Copy link
Copy Markdown
Member

This pull request introduces significant improvements to the document retrieval system across both the frontend and backend, unifying and simplifying how documents are fetched by various identifiers (ID, PMID, DOI, reference) and workspace. It removes legacy endpoints and methods, centralizes document fetching logic, and updates the data models and API contracts accordingly. The changes also include type and signature improvements for better type safety and maintainability.

Backend API and Logic Unification:

  • Replaced separate /documents/by-id/{id} and /documents/by-pmid/{pmid} endpoints with a single /documents endpoint that accepts workspace_id and one or more identifiers (id, pmid, doi, reference), returning a list of matching documents and providing better error handling for missing or ambiguous queries.
  • Updated backend document fetching logic to use the new unified endpoint, including improved input validation and error messages.

Frontend Document Fetching Refactor:

  • Refactored the frontend to use a single fetchDocument method that queries documents by any identifier and workspace, replacing the previous fetchDocumentByID and fetchDocumentByPubmedID methods. The view model and use case now expect and handle the new API response format. [1] [2] [3] [4]

Repository and Domain Model Updates:

  • Changed the frontend repository’s getDocumentById and getDocumentByPubmedID to a single getDocuments method that matches the new backend API, returning an array of documents. Updated the domain model to include doi as a possible identifier. [1] [2]

Type and Signature Improvements:

  • Added and improved type annotations throughout the codebase, including Vue components (lang="ts"), API handler signatures, and Minio/file handling code to improve code safety and clarity. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Minor Fixes and Cleanups:

  • Fixed small issues and improved error messages, default values, and parameter handling in various locations for robustness and maintainability. [1] [2] [3]

These changes together make document retrieval more robust, flexible, and maintainable across the application.

- Updated type hints in `files.py` for better clarity and consistency.
- Enhanced error handling in `put_file` and `list_objects` functions.
- Improved metadata handling in `ObjectMetadata` and `ListObjectsResponse` classes.
- Cleaned up optional parameters and added type ignores where necessary for compatibility.
- Updated the `get` method to accept a dictionary of parameters for searching documents by workspace ID, ID, PMID, DOI, or reference.
- Enhanced error handling for cases with no documents found or multiple documents returned.
- Refactored related document model and repository methods to align with the new API structure.
- Updated frontend components to utilize the new document fetching logic, ensuring compatibility with the revised API.
@JonnyTran JonnyTran requested review from a team as code owners August 12, 2025 21:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 26.47059% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
extralit/src/extralit/documents/_resource.py 0.00% 18 Missing ⚠️
...ralit-server/src/extralit_server/contexts/files.py 16.66% 10 Missing ⚠️
...r/src/extralit_server/api/handlers/v1/documents.py 52.63% 9 Missing ⚠️
extralit/src/extralit/_api/_documents.py 11.11% 8 Missing ⚠️
...tend/components/base/base-pdf-viewer/PDFViewer.vue 0.00% 2 Missing ⚠️
...server/src/extralit_server/api/schemas/v1/files.py 66.66% 2 Missing ⚠️
extralit/src/extralit/_models/_documents.py 50.00% 1 Missing ⚠️
Flag Coverage Δ
extralit 66.37% <6.89%> (+1.44%) ⬆️
extralit-server 81.11% <43.24%> (-0.02%) ⬇️
frontend 10.59% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...erver/src/extralit_server/api/handlers/v1/files.py 64.81% <ø> (ø)
extralit/src/extralit/_models/_documents.py 75.00% <50.00%> (ø)
...tend/components/base/base-pdf-viewer/PDFViewer.vue 0.00% <0.00%> (ø)
...server/src/extralit_server/api/schemas/v1/files.py 68.75% <66.66%> (ø)
extralit/src/extralit/_api/_documents.py 59.37% <11.11%> (-0.33%) ⬇️
...r/src/extralit_server/api/handlers/v1/documents.py 48.14% <52.63%> (-0.96%) ⬇️
...ralit-server/src/extralit_server/contexts/files.py 22.53% <16.66%> (+0.11%) ⬆️
extralit/src/extralit/documents/_resource.py 56.30% <0.00%> (-7.10%) ⬇️

... and 10 files with indirect coverage changes

Components Coverage Δ
extralit 66.37% <6.89%> (+1.44%) ⬆️
extralit-server 81.11% <43.24%> (-0.02%) ⬇️
extralit-frontend 10.59% <0.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JonnyTran JonnyTran requested a review from a team as a code owner August 12, 2025 21:37
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 12, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 26.47059% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
extralit/src/extralit/documents/_resource.py 0.00% 18 Missing ⚠️
...ralit-server/src/extralit_server/contexts/files.py 16.66% 10 Missing ⚠️
...r/src/extralit_server/api/handlers/v1/documents.py 52.63% 9 Missing ⚠️
extralit/src/extralit/_api/_documents.py 11.11% 8 Missing ⚠️
...tend/components/base/base-pdf-viewer/PDFViewer.vue 0.00% 2 Missing ⚠️
...server/src/extralit_server/api/schemas/v1/files.py 66.66% 2 Missing ⚠️
extralit/src/extralit/_models/_documents.py 50.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Flag Coverage Δ
extralit 66.38% <6.89%> (+1.45%) ⬆️
extralit-server 81.11% <43.24%> (-0.02%) ⬇️
frontend 10.59% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...erver/src/extralit_server/api/handlers/v1/files.py 64.81% <ø> (ø)
extralit/src/extralit/_models/_documents.py 75.00% <50.00%> (ø)
...tend/components/base/base-pdf-viewer/PDFViewer.vue 0.00% <0.00%> (ø)
...server/src/extralit_server/api/schemas/v1/files.py 68.75% <66.66%> (ø)
extralit/src/extralit/_api/_documents.py 59.37% <11.11%> (-0.33%) ⬇️
...r/src/extralit_server/api/handlers/v1/documents.py 48.14% <52.63%> (-0.96%) ⬇️
...ralit-server/src/extralit_server/contexts/files.py 22.53% <16.66%> (+0.11%) ⬆️
extralit/src/extralit/documents/_resource.py 56.30% <0.00%> (-7.10%) ⬇️

... and 9 files with indirect coverage changes

Components Coverage Δ
extralit 66.38% <6.89%> (+1.45%) ⬆️
extralit-server 81.11% <43.24%> (-0.02%) ⬇️
extralit-frontend 10.59% <0.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JonnyTran JonnyTran merged commit cee5b3c into develop Aug 12, 2025
9 checks passed
@JonnyTran JonnyTran deleted the feat/files-presigned-url-for-pdfs branch August 12, 2025 22:13
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.

2 participants