Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Group17TVSeriesRecommendationMicroservice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Asif, Adiv (UG - Comp Sci & Elec Eng)
Group17TVSeriesRecommendationMicroservice
Commits
2e3568a2
Commit
2e3568a2
authored
2 years ago
by
MikelLiza
Browse files
Options
Downloads
Patches
Plain Diff
AddedPageFilter
parent
1f67964d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.py
+10
-7
10 additions, 7 deletions
app.py
with
10 additions
and
7 deletions
app.py
+
10
−
7
View file @
2e3568a2
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment