Files
PaskaJoululeffa2024-backend/src/routes/movie.py
T

36 lines
882 B
Python

from fastapi import APIRouter, Response
from lib.database.movie import get_all_movies, get_next_movie
from models.movie import Movie
from models import Message
router = APIRouter(
prefix="/movie",
tags=["movie"],
responses={404: {"description": "Not found"}},
)
@router.get("/", response_model=list[Movie])
async def get_movies():
return get_all_movies()
@router.get("/next", response_model=Movie)
async def get_next_movie_endpoint():
"""Get the next movie to watch
Returns:
Movie: The next movie to watch
"""
next_movie = get_next_movie()
if next_movie is None:
return Response(
status_code=200,
media_type="application/json",
content=Message(
message="No more movies to watch", message_type="info"
).model_dump_json(),
)
return get_next_movie()