Skip to content

Add books languages endpoint#222

Open
aviralgarg05 wants to merge 1 commit intoopenzim:mainfrom
aviralgarg05:issue-102-book-language-codes
Open

Add books languages endpoint#222
aviralgarg05 wants to merge 1 commit intoopenzim:mainfrom
aviralgarg05:issue-102-book-language-codes

Conversation

@aviralgarg05
Copy link
Copy Markdown

Summary

This PR adds a new public endpoint to expose the list of ISO639-3 language codes currently used by books managed in the CMS.

The new endpoint is:

GET /v1/books/languages

It returns a sorted list of distinct language codes collected from production books only.

Example response:

{
  "languages": ["deu", "eng", "fra", "spa"]
}

What changed

  • added GET /v1/books/languages under the existing books API
  • added a backend helper to collect language codes from Book.zim_metadata["Language"]
  • restricted the result set to books with location_kind = "prod"
  • split comma-separated language values
  • trimmed surrounding whitespace
  • ignored empty values
  • removed duplicates
  • returned the final list in sorted order
  • added API and DB-level tests for the new behavior

Why

The Language metadata can contain multiple comma-separated ISO639-3 codes. Exposing the normalized set of codes used by production books makes it easier for downstream consumers to know which values they may encounter and validate their support accordingly.

Notes

  • only production books are considered
  • the endpoint is public, in line with the intended use of this metadata
  • the route is placed under /v1/books because the source of truth is Book.zim_metadata

Testing

I verified the change with:

  • hatch run lint:black
  • hatch run lint:ruff
  • hatch run check:pyright
  • targeted DB test for language extraction
  • targeted API test for the new endpoint
  • full backend test suite with CI-equivalent environment settings
  • backend Docker image builds for API, mill, and shuttle
  • container smoke checks for mill and shuttle entrypoints
  • API container healthcheck after applying Alembic migrations

Full backend result:

  • 267 passed

Related

Closes #102

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.

Publish a list of used ISO639-3 code in Language metadata

1 participant