Skip to content
Snippets Groups Projects
Commit 2e3568a2 authored by MikelLiza's avatar MikelLiza
Browse files

AddedPageFilter

parent 1f67964d
No related branches found
No related tags found
No related merge requests found
......@@ -273,12 +273,12 @@ class SeriesInfoById(Resource):
return result
@api.route('/api/tv_shows')
@api.route('/api/tv_shows/<int:page>')
@api.doc(responses={200: 'application/json'})
class TvShows(Resource):
def get(self):
def get(self, page):
# Get the page number from the request arguments, defaulting to 1 if not provided
page = int(request.args.get('page', 1))
#page = int(request.args.get('page', 1))
# Define the number of shows to display per page
shows_per_page = 20
......@@ -288,12 +288,15 @@ class TvShows(Resource):
end_idx = start_idx + shows_per_page
# Get the shows for the requested page
shows = collection[start_idx:end_idx]
collection_li = list(collection.find({}, {"_id": 0, "backdrop": 1, "cast": 1, "feature": 1, "genre": 1, "id": 1,
"keywords": 1, "name": 1, "overview": 1, "poster": 1, "rating": 1,
"year_aired": 1}))
shows = collection_li[start_idx:end_idx]
# Create a list of dictionaries containing the relevant information for each show
response_data = []
for show in shows:
show_data = {
'id': show['id'],
'backdrop': show['backdrop'],
'cast': show['cast'],
'feature': show['feature'],
......@@ -311,8 +314,8 @@ class TvShows(Resource):
# Create a response object with the page of shows and the relevant metadata
response = {
'page': page,
'total_pages': (len(collection) + shows_per_page - 1) // shows_per_page,
'total_shows': len(collection),
'total_pages': (len(collection_li) + shows_per_page - 1) // shows_per_page,
'total_shows': len(collection_li),
'shows': response_data
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment