# ------------------------------------------------- # 3️⃣ Rate / Review (Auth required) # ------------------------------------------------- @app.post("/movies/movie_id/rating", response_model=schemas.RatingOut) def rate_movie( movie_id: int, payload: schemas.RatingIn, user: models.User = Depends(auth.get_current_user), db: Session = Depends(auth.get_db) ): return crud.upsert_rating(db, user.id, movie_id, payload)
CREATE TABLE movie_links ( id BIGSERIAL PRIMARY KEY, movie_id BIGINT REFERENCES movies(id) ON DELETE CASCADE, platform_id BIGINT REFERENCES platforms(id), url TEXT NOT NULL, price_usd NUMERIC(5,2), price_local NUMERIC(5,2), currency TEXT, is_free BOOLEAN DEFAULT FALSE, last_checked TIMESTAMP, UNIQUE(movie_id, platform_id) );
app = FastAPI(title="HindimoviesLink API", version="0.1.0") hindimovieslink
# ------------------------------------------------- # 4️⃣ Watch‑Later List # ------------------------------------------------- @app.post("/me/watchlist", response_model=schemas.WatchlistItemOut) def add_to_watchlist( payload: schemas.WatchlistIn, user: models.User = Depends(auth.get_current_user), db: Session = Depends(auth.get_db) ): return crud.add_to_watchlist(db, user.id, payload.movie_id)
# ------------------------------------------------- # 5️⃣ Notification subscription (price‑drop) # ------------------------------------------------- @app.post("/me/alerts", response_model=schemas.AlertOut) def create_price_alert( payload: schemas.AlertIn, user: models.User = Depends(auth.get_current_user), db: Session = Depends(auth.get_db) ): return crud.create_price_alert(db, user.id, payload) class MovieOut(BaseModel): id: int title: str year: Optional[int] poster_url: Optional[str] rating_imdb: Optional[float] user: models.User = Depends(auth.get_current_user)
-- Watch‑Later / Favorites CREATE TABLE user_lists ( id BIGSERIAL PRIMARY KEY, user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, movie_id BIGINT REFERENCES movies(id) ON DELETE CASCADE, list_type TEXT CHECK (list_type IN ('watch_later','favorites')), created_at TIMESTAMP DEFAULT now(), UNIQUE(user_id, movie_id, list_type) ); Add pg_trgm indexes for fuzzy title search:
def search_movies(db: Session, q: str, genre: str = None, year: int = None, limit: int = 20): stmt = db.query(models.Movie).filter( models.Movie.title.ilike(f"%q%") | func.similarity(models.Movie.title, q) > 0.3 ) if genre: stmt = stmt.filter(models.Movie.genre.contains([genre])) if year: stmt = stmt.filter(models.Movie.year == year) return stmt.limit(limit).all() platform_id BIGINT REFERENCES platforms(id)
class WatchlistItemOut(BaseModel): movie_id: int added_at: datetime.datetime