Skip to content

Commit

Permalink
add filter to get item by type
Browse files Browse the repository at this point in the history
  • Loading branch information
kenmoh committed Dec 5, 2023
1 parent 67b1e65 commit 173fd66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/routes/movie_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions app/services/movie_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 173fd66

Please sign in to comment.