Skip to content

Commit

Permalink
feat(api): add paging support
Browse files Browse the repository at this point in the history
  • Loading branch information
omame committed Dec 17, 2022
1 parent c8651f1 commit 4795c9a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cogs/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def auth_check_route():
| --------------- | --------- | ------------------------ |
| search | false | Search through questions |
| response_search | false | Search through responses |
| start | false | Skip X questions |
| count | false | Return X questions |
For use in dashboard, requires authentication.
"""
Expand All @@ -85,10 +87,16 @@ def question_list():
questions = {k: v for k, v in enumerate(questions_list)}
search = request.args.get('search')
response_search = request.args.get('response_search')
start = request.args.get('start')
count = request.args.get('count')
if search:
questions = {i: q for i, q in questions.items() if search in q["text"]}
if response_search:
questions = {i: q for i, q in questions.items() for r in q["responses"] if response_search in r["text"]}
start = int(start) if start else None
count = int(count) if count else None
end = start + count if start is not None and count is not None else None
questions = {i: q for i, q in list(questions.items())[start:end]}
return questions

"""
Expand Down

0 comments on commit 4795c9a

Please sign in to comment.