Add movie/series ratings and watchlist
Builds on the accounts foundation: PUT/DELETE a rating (0.5-10.0) or a
watchlist entry on any movie or series, all scoped to the bearer token's
own user, plus GET /account/ratings|watchlist/{movies,series} to list
them back. Both are polymorphic entity_type/entity_id tables, same shape
as watch_provider_offerings and trending_entries, so movie and series
share one repository/router each rather than duplicating per type.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
a38c2074a6
commit
0ab31a314c
@@ -0,0 +1,62 @@
|
||||
"""The authenticated user's own ratings and watchlist (section 17,
|
||||
additive) -- everything here requires a bearer token and is scoped to the
|
||||
caller, unlike every other read endpoint in Aurora Core."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.deps import get_current_user
|
||||
from app.core.database import get_db
|
||||
from app.core.security import enforce_rate_limit
|
||||
from app.models.user import User
|
||||
from app.schemas.movie import MovieListOut, RatedMovieListOut
|
||||
from app.schemas.tv import RatedSeriesListOut, SeriesListOut
|
||||
from app.services import movie_service, tv_service
|
||||
|
||||
router = APIRouter(prefix="/account", tags=["account"], dependencies=[Depends(enforce_rate_limit)])
|
||||
|
||||
|
||||
@router.get("/ratings/movies", response_model=RatedMovieListOut)
|
||||
async def list_rated_movies(
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=50),
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> RatedMovieListOut:
|
||||
return await movie_service.list_rated_movies(session, user_id=user.id, page=page, page_size=page_size)
|
||||
|
||||
|
||||
@router.get("/ratings/series", response_model=RatedSeriesListOut)
|
||||
async def list_rated_series(
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=50),
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> RatedSeriesListOut:
|
||||
return await tv_service.list_rated_series(session, user_id=user.id, page=page, page_size=page_size)
|
||||
|
||||
|
||||
@router.get("/watchlist/movies", response_model=MovieListOut)
|
||||
async def list_watchlist_movies(
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=50),
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> MovieListOut:
|
||||
return await movie_service.list_watchlist_movies(
|
||||
session, user_id=user.id, page=page, page_size=page_size
|
||||
)
|
||||
|
||||
|
||||
@router.get("/watchlist/series", response_model=SeriesListOut)
|
||||
async def list_watchlist_series(
|
||||
page: int = Query(1, ge=1),
|
||||
page_size: int = Query(20, ge=1, le=50),
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> SeriesListOut:
|
||||
return await tv_service.list_watchlist_series(
|
||||
session, user_id=user.id, page=page, page_size=page_size
|
||||
)
|
||||
+52
-1
@@ -8,10 +8,12 @@ from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from redis.asyncio import Redis
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.deps import cached_response, not_found
|
||||
from app.api.deps import cached_response, get_current_user, not_found
|
||||
from app.core.database import get_db
|
||||
from app.core.redis import get_redis
|
||||
from app.core.security import enforce_rate_limit
|
||||
from app.models.user import User
|
||||
from app.schemas.account import RatingIn, RatingOut
|
||||
from app.schemas.movie import (
|
||||
MovieCreditsOut,
|
||||
MovieDetailOut,
|
||||
@@ -155,3 +157,52 @@ async def get_movie_watch_providers(
|
||||
return await movie_service.get_movie_watch_providers(session, aurora_id)
|
||||
except movie_service.MovieNotFoundError as exc:
|
||||
raise not_found("movie", aurora_id) from exc
|
||||
|
||||
|
||||
@router.put("/{aurora_id}/rating", response_model=RatingOut)
|
||||
async def rate_movie(
|
||||
aurora_id: str,
|
||||
body: RatingIn,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> RatingOut:
|
||||
try:
|
||||
return await movie_service.rate_movie(session, aurora_id, user_id=user.id, value=body.value)
|
||||
except movie_service.MovieNotFoundError as exc:
|
||||
raise not_found("movie", aurora_id) from exc
|
||||
|
||||
|
||||
@router.delete("/{aurora_id}/rating", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def unrate_movie(
|
||||
aurora_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> None:
|
||||
try:
|
||||
await movie_service.unrate_movie(session, aurora_id, user_id=user.id)
|
||||
except movie_service.MovieNotFoundError as exc:
|
||||
raise not_found("movie", aurora_id) from exc
|
||||
|
||||
|
||||
@router.post("/{aurora_id}/watchlist", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def add_movie_to_watchlist(
|
||||
aurora_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> None:
|
||||
try:
|
||||
await movie_service.add_movie_to_watchlist(session, aurora_id, user_id=user.id)
|
||||
except movie_service.MovieNotFoundError as exc:
|
||||
raise not_found("movie", aurora_id) from exc
|
||||
|
||||
|
||||
@router.delete("/{aurora_id}/watchlist", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def remove_movie_from_watchlist(
|
||||
aurora_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> None:
|
||||
try:
|
||||
await movie_service.remove_movie_from_watchlist(session, aurora_id, user_id=user.id)
|
||||
except movie_service.MovieNotFoundError as exc:
|
||||
raise not_found("movie", aurora_id) from exc
|
||||
|
||||
+52
-1
@@ -8,10 +8,12 @@ from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from redis.asyncio import Redis
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.deps import cached_response, not_found
|
||||
from app.api.deps import cached_response, get_current_user, not_found
|
||||
from app.core.database import get_db
|
||||
from app.core.redis import get_redis
|
||||
from app.core.security import enforce_rate_limit
|
||||
from app.models.user import User
|
||||
from app.schemas.account import RatingIn, RatingOut
|
||||
from app.schemas.tv import (
|
||||
SeriesCreditsOut,
|
||||
SeriesDetailOut,
|
||||
@@ -135,3 +137,52 @@ async def get_series_watch_providers(
|
||||
return await tv_service.get_series_watch_providers(session, aurora_id)
|
||||
except tv_service.SeriesNotFoundError as exc:
|
||||
raise not_found("series", aurora_id) from exc
|
||||
|
||||
|
||||
@router.put("/{aurora_id}/rating", response_model=RatingOut)
|
||||
async def rate_series(
|
||||
aurora_id: str,
|
||||
body: RatingIn,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> RatingOut:
|
||||
try:
|
||||
return await tv_service.rate_series(session, aurora_id, user_id=user.id, value=body.value)
|
||||
except tv_service.SeriesNotFoundError as exc:
|
||||
raise not_found("series", aurora_id) from exc
|
||||
|
||||
|
||||
@router.delete("/{aurora_id}/rating", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def unrate_series(
|
||||
aurora_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> None:
|
||||
try:
|
||||
await tv_service.unrate_series(session, aurora_id, user_id=user.id)
|
||||
except tv_service.SeriesNotFoundError as exc:
|
||||
raise not_found("series", aurora_id) from exc
|
||||
|
||||
|
||||
@router.post("/{aurora_id}/watchlist", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def add_series_to_watchlist(
|
||||
aurora_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> None:
|
||||
try:
|
||||
await tv_service.add_series_to_watchlist(session, aurora_id, user_id=user.id)
|
||||
except tv_service.SeriesNotFoundError as exc:
|
||||
raise not_found("series", aurora_id) from exc
|
||||
|
||||
|
||||
@router.delete("/{aurora_id}/watchlist", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def remove_series_from_watchlist(
|
||||
aurora_id: str,
|
||||
user: User = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db),
|
||||
) -> None:
|
||||
try:
|
||||
await tv_service.remove_series_from_watchlist(session, aurora_id, user_id=user.id)
|
||||
except tv_service.SeriesNotFoundError as exc:
|
||||
raise not_found("series", aurora_id) from exc
|
||||
|
||||
Reference in New Issue
Block a user