feat: M4 (part 1) — feed API, watch state, user preferences
- GET /api/feed: filter by tags (and/or), channel, duration, age, search; sort
newest/oldest/views/duration/shuffle; default hides Shorts, live/upcoming and
watched (was_live VODs stay visible); offset paging with has_more
- POST /api/videos/{id}/state for watched/saved/hidden/new
- User.preferences JSON + GET /api/me and PUT /api/me/preferences
- Migration 0004 (preferences column + video_states table)
This commit is contained in:
parent
96f9c5a797
commit
9a377b7e7e
5 changed files with 285 additions and 1 deletions
52
backend/alembic/versions/0004_feed_state_prefs.py
Normal file
52
backend/alembic/versions/0004_feed_state_prefs.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"""user preferences + per-user video watch state
|
||||
|
||||
Revision ID: 0004_feed_state_prefs
|
||||
Revises: 0003_tags
|
||||
Create Date: 2026-06-11
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = "0004_feed_state_prefs"
|
||||
down_revision: Union[str, None] = "0003_tags"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("users", sa.Column("preferences", sa.JSON(), nullable=True))
|
||||
|
||||
op.create_table(
|
||||
"video_states",
|
||||
sa.Column("id", sa.Integer(), primary_key=True),
|
||||
sa.Column(
|
||||
"user_id",
|
||||
sa.Integer(),
|
||||
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"video_id",
|
||||
sa.String(length=16),
|
||||
sa.ForeignKey("videos.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("status", sa.String(length=12), nullable=False, server_default="new"),
|
||||
sa.Column("watched_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column(
|
||||
"updated_at",
|
||||
sa.DateTime(timezone=True),
|
||||
server_default=sa.func.now(),
|
||||
nullable=False,
|
||||
),
|
||||
sa.UniqueConstraint("user_id", "video_id", name="uq_user_video"),
|
||||
)
|
||||
op.create_index("ix_video_states_user_id", "video_states", ["user_id"])
|
||||
op.create_index("ix_video_states_video_id", "video_states", ["video_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("video_states")
|
||||
op.drop_column("users", "preferences")
|
||||
Loading…
Add table
Add a link
Reference in a new issue