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
@@ -24,6 +24,7 @@ from app.models.movie import (
|
||||
)
|
||||
from app.models.person import Person
|
||||
from app.models.provider import IngestionJob, Provider, ProviderRecord
|
||||
from app.models.rating import Rating
|
||||
from app.models.trending import TrendingEntry
|
||||
from app.models.tv import (
|
||||
Episode,
|
||||
@@ -36,6 +37,7 @@ from app.models.tv import (
|
||||
from app.models.user import User
|
||||
from app.models.video import Video
|
||||
from app.models.watch_provider import WatchProvider, WatchProviderOffering
|
||||
from app.models.watchlist import WatchlistEntry
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
@@ -79,4 +81,6 @@ __all__ = [
|
||||
"WatchProviderOffering",
|
||||
"TrendingEntry",
|
||||
"User",
|
||||
"Rating",
|
||||
"WatchlistEntry",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"""User ratings -- section 17, additive (accounts/ratings/watchlist).
|
||||
|
||||
Polymorphic across movie/series, same shape as WatchProviderOffering and
|
||||
TrendingEntry: `entity_type` + `entity_id` rather than a separate ratings
|
||||
table per entity type."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import Float, ForeignKey, Index, String, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
||||
|
||||
|
||||
class Rating(Base, UUIDPrimaryKeyMixin, TimestampMixin):
|
||||
__tablename__ = "ratings"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "entity_type", "entity_id"),
|
||||
Index("ix_ratings_entity", "entity_type", "entity_id"),
|
||||
)
|
||||
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
entity_type: Mapped[str] = mapped_column(String(30), nullable=False)
|
||||
entity_id: Mapped[uuid.UUID] = mapped_column(nullable=False)
|
||||
# 0.5-10.0 in 0.5 steps, same scale as TMDb's own user ratings -- see
|
||||
# app/schemas/account.py:RatingIn for the enforced bounds.
|
||||
value: Mapped[float] = mapped_column(Float, nullable=False)
|
||||
|
||||
|
||||
__all__ = ["Rating"]
|
||||
@@ -0,0 +1,30 @@
|
||||
"""User watchlists -- section 17, additive (accounts/ratings/watchlist).
|
||||
|
||||
Polymorphic across movie/series, same shape as Rating -- no value beyond
|
||||
membership, so no extra columns beyond the timestamps."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from sqlalchemy import ForeignKey, Index, String, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin
|
||||
|
||||
|
||||
class WatchlistEntry(Base, UUIDPrimaryKeyMixin, TimestampMixin):
|
||||
__tablename__ = "watchlist_entries"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("user_id", "entity_type", "entity_id"),
|
||||
Index("ix_watchlist_entries_user", "user_id", "entity_type"),
|
||||
)
|
||||
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
entity_type: Mapped[str] = mapped_column(String(30), nullable=False)
|
||||
entity_id: Mapped[uuid.UUID] = mapped_column(nullable=False)
|
||||
|
||||
|
||||
__all__ = ["WatchlistEntry"]
|
||||
Reference in New Issue
Block a user