diff --git a/app/routes/movie_routes.py b/app/routes/movie_routes.py index 71b1508..4fd6139 100644 --- a/app/routes/movie_routes.py +++ b/app/routes/movie_routes.py @@ -15,13 +15,14 @@ @movie_router.get("", status_code=status.HTTP_200_OK) -def get_movies(db: Session = Depends(get_db)) -> list[MovieResponseSchema]: +def get_movies(item_type: TypeEnum, db: Session = Depends(get_db)) -> list[MovieResponseSchema]: """ Get all movies from the database :param db: + :param item_type: :return: All Movies """ - return movie_services.get_all_movies(db) + return movie_services.get_all_movies(db=db, item_type=item_type) @movie_router.get("/limited-movies", status_code=status.HTTP_200_OK) diff --git a/app/services/movie_services.py b/app/services/movie_services.py index 6f48686..26b52ba 100644 --- a/app/services/movie_services.py +++ b/app/services/movie_services.py @@ -31,14 +31,15 @@ def get_limited_movies_by_type(db: session, item_type: TypeEnum, limit: int): return movies -def get_all_movies(db: session): +def get_all_movies(db: session, item_type: TypeEnum): """ This function gets all movies from the database :param db: + :param item_type: :return: All movies in the database """ - movies = db.query(Movie).all() + movies = db.query(Movie).order_by(desc(Movie.created_at)).filter(Movie.item_type == item_type).all() for movie in movies: reviews = get_all_reviews_by_movie(movie.id, db)