Skip to content

Commit 4795c9a

Browse files
author
omame
committed
feat(api): add paging support
1 parent c8651f1 commit 4795c9a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cogs/webapi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def auth_check_route():
7474
| --------------- | --------- | ------------------------ |
7575
| search | false | Search through questions |
7676
| response_search | false | Search through responses |
77+
| start | false | Skip X questions |
78+
| count | false | Return X questions |
7779
7880
For use in dashboard, requires authentication.
7981
"""
@@ -85,10 +87,16 @@ def question_list():
8587
questions = {k: v for k, v in enumerate(questions_list)}
8688
search = request.args.get('search')
8789
response_search = request.args.get('response_search')
90+
start = request.args.get('start')
91+
count = request.args.get('count')
8892
if search:
8993
questions = {i: q for i, q in questions.items() if search in q["text"]}
9094
if response_search:
9195
questions = {i: q for i, q in questions.items() for r in q["responses"] if response_search in r["text"]}
96+
start = int(start) if start else None
97+
count = int(count) if count else None
98+
end = start + count if start is not None and count is not None else None
99+
questions = {i: q for i, q in list(questions.items())[start:end]}
92100
return questions
93101

94102
"""

0 commit comments

Comments
 (0)