Skip to content

Feature/bibliography export#178

Open
lpi-tn wants to merge 4 commits into
mainfrom
Feature/bibliography-export
Open

Feature/bibliography export#178
lpi-tn wants to merge 4 commits into
mainfrom
Feature/bibliography-export

Conversation

@lpi-tn

@lpi-tn lpi-tn commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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_bibliography endpoint, 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:

  • Added a new bibliography API router and /bibliography/export_bibliography endpoint 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]
  • Implemented document retrieval by IDs with joined corpus loading for bibliography export. (src/app/services/sql_db/queries.py) [1] [2]

RIS Formatting Utilities:

  • Added helper functions for RIS line formatting, document type mapping, publication date formatting, and author list formatting, as well as the main welearn_document_to_ris function. (src/app/services/helpers.py) [1] [2] [3]

Testing:

  • Added unit and integration tests for the bibliography export endpoint and RIS formatting logic, covering success, empty, and invalid payload cases. (src/app/tests/api/api_v1/test_bibliography.py, src/app/tests/services/test_helpers.py) [1] [2] [3]

Other Improvements:

  • Improved logging in stringify_docs_content by using logger.exception for 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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