Feature/bibliography export#178
Open
lpi-tn wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a bibliography export capability to the API by introducing a new /bibliography/export_bibliography endpoint that returns document metadata formatted as RIS.
Changes:
- Added a new bibliography API router + endpoint to export RIS for a list of document UUIDs.
- Implemented RIS formatting helpers (doctype mapping, author/date formatting, RIS serialization).
- Added query helper to load documents by IDs (with corpus eager loading) and introduced tests for both RIS formatting and the endpoint.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/app/api/api_v1/api.py |
Registers the new bibliography router and tag metadata. |
src/app/api/api_v1/endpoints/bibliography.py |
Implements the /export_bibliography endpoint returning PlainText RIS output. |
src/app/models/bibliography.py |
Adds request model for the list of document UUIDs. |
src/app/services/helpers.py |
Adds RIS formatting utilities and document-to-RIS serialization. |
src/app/services/sql_db/queries.py |
Adds get_documents_by_ids and reuses it in payload assembly. |
src/app/tests/api/api_v1/test_bibliography.py |
Adds endpoint tests (success/empty/invalid payload). |
src/app/tests/services/test_helpers.py |
Adds unit tests for RIS helper functions and RIS serialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+285
to
+289
| except Exception as e: | ||
| logger.warning( | ||
| "Exception occurs during publication formatting, field returned empty", e | ||
| ) | ||
| return "" |
Comment on lines
+292
to
+296
| def compute_authors_for_ris(authors: dict) -> list[str]: | ||
| ret = [] | ||
| for author in authors: | ||
| ret.append(ris_line("AU", author.get("name"))) | ||
| return ret |
Comment on lines
+326
to
+330
| license_url = details.get("license_url", None) | ||
| if license_url: | ||
| lines.append(ris_line("C1", license_url)) | ||
| lines.append("ER - ") | ||
| return "\n".join(lines) |
Comment on lines
+88
to
+92
| documents = ( | ||
| s.query(WeLearnDocument) | ||
| .where(WeLearnDocument.id.in_(documents_ids)) | ||
| .options(joinedload(WeLearnDocument.corpus)) | ||
| .all() |
Comment on lines
+1
to
+15
| from fastapi import APIRouter, BackgroundTasks, Request | ||
| from starlette.responses import PlainTextResponse | ||
|
|
||
| from src.app.models.bibliography import DocumentIDs | ||
| from src.app.services.helpers import welearn_document_to_ris | ||
| from src.app.services.sql_db.queries import get_documents_by_ids | ||
| from src.app.shared.utils.dependencies import get_settings | ||
| from src.app.utils.logger import logger as utils_logger | ||
|
|
||
| logger = utils_logger(__name__) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
| settings = get_settings() | ||
|
|
Comment on lines
+17
to
+32
| @router.post("/export_bibliography", response_class=PlainTextResponse) | ||
| async def export_bibliography( | ||
| request: Request, | ||
| background_tasks: BackgroundTasks, | ||
| body: DocumentIDs, | ||
| ): | ||
| documents_ids = [str(u) for u in body.documents_ids] | ||
|
|
||
| docs = get_documents_by_ids(documents_ids) | ||
|
|
||
| ret = "" | ||
| for doc in docs: | ||
| ret += welearn_document_to_ris(doc) | ||
| ret += "\n" | ||
|
|
||
| return ret |
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.
This pull request introduces a new bibliography export feature to the API, allowing users to export document metadata in RIS format. It adds a new
/bibliography/export_bibliographyendpoint, supporting backend logic for RIS formatting, document retrieval, and comprehensive tests for the new functionality. Several utility functions were added to handle RIS formatting and author/date conversions, and relevant API documentation was updated.New Bibliography Export Feature:
bibliographyAPI router and/bibliography/export_bibliographyendpoint to export bibliographic metadata in RIS format for a list of document IDs. (src/app/api/api_v1/api.py,src/app/api/api_v1/endpoints/bibliography.py,src/app/models/bibliography.py) [1] [2] [3] [4] [5]src/app/services/sql_db/queries.py) [1] [2]RIS Formatting Utilities:
welearn_document_to_risfunction. (src/app/services/helpers.py) [1] [2] [3]Testing:
src/app/tests/api/api_v1/test_bibliography.py,src/app/tests/services/test_helpers.py) [1] [2] [3]Other Improvements:
stringify_docs_contentby usinglogger.exceptionfor better error reporting. (src/app/services/helpers.py)These changes collectively provide a robust, tested API feature for exporting bibliographic information in a standard format.