Add GET /genres directory endpoint
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
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
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]>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
71388e254e
commit
340cadd99d
@@ -0,0 +1,34 @@
|
||||
"""Data access for Genre."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.genre import Genre
|
||||
|
||||
|
||||
async def get_genre_by_id(session: AsyncSession, genre_id: uuid.UUID) -> Genre | None:
|
||||
result = await session.execute(select(Genre).where(Genre.id == genre_id))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def list_genres(session: AsyncSession, *, limit: int, offset: int) -> tuple[list[Genre], int]:
|
||||
"""Browse genres -- see movie_repository.list_movies for the
|
||||
window-function total-count approach this mirrors. Genres have no
|
||||
categorical field to filter by and no popularity/date to sort by, so
|
||||
this always orders alphabetically by name (with an id tiebreak for
|
||||
stable pagination)."""
|
||||
|
||||
stmt = (
|
||||
select(Genre, func.count().over().label("total_count"))
|
||||
.order_by(Genre.name.asc(), Genre.id.asc())
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
)
|
||||
rows = (await session.execute(stmt)).all()
|
||||
if not rows:
|
||||
return [], 0
|
||||
return [row[0] for row in rows], rows[0].total_count
|
||||
Reference in New Issue
Block a user