28 lines
1.1 KiB
Python
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
|
||
|
|
)
|