Files
Aurora-Core/app/services/genre_service.py
T
NixReaperandClaude Sonnet 5 340cadd99d
CI / lint (push) Canceled after 0s
CI / typecheck (push) Canceled after 0s
CI / unit-tests (push) Canceled after 0s
CI / integration-tests (push) Canceled after 0s
CI / container-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
Add GET /genres directory endpoint
GET /movies and GET /series accept a genre filter (an Aurora genre id),
but nothing exposed what those ids actually are -- genres otherwise
only ever appear embedded in a movie/series response's own genres
list. This is the resolve-by-name-first-then-filter step the frontend
needs to build real genre browsing.

No filter, no sort_by -- always alphabetical by name, same pattern as
collections/companies (genres have no categorical field or popularity/
date to sort by). page_size defaults to 50 (max 200) rather than the
20/50 used elsewhere, since genres are a small, fixed reference set
(TMDb has ~19-20 total) a client typically wants in full for a filter
dropdown, not paginated like a catalog of millions of movies.

Also fixed two stale "behind Traefik" mentions in app/main.py's module
docstring while touching this file, left over from the earlier
cPanel/host-webserver deployment change.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-06 00:05:10 -05:00

28 lines
1.1 KiB
Python

"""Assembles Genre API responses from repository data.
Genres have no detail page of their own -- they only ever appear embedded
in movie/series responses (see app/services/common.py) and as entries in
this directory listing, which exists so a client can resolve the Aurora
genre ids that GET /movies and GET /series accept as a filter without
having to have already seen a title in that genre first."""
from __future__ import annotations
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.ids import aurora_id
from app.repositories import genre_repository
from app.schemas.common import GenreListOut, GenreOut
async def list_genres(session: AsyncSession, *, page: int, page_size: int) -> GenreListOut:
genres, total = await genre_repository.list_genres(
session, limit=page_size, offset=(page - 1) * page_size
)
results = [GenreOut(id=aurora_id("genre", str(g.id)), name=g.name) for g in genres]
total_pages = (total + page_size - 1) // page_size if total else 0
return GenreListOut(
page=page, page_size=page_size, total_results=total, total_pages=total_pages, results=results
)