Drew Short
6 years ago
8 changed files with 198 additions and 17 deletions
-
5.gitignore
-
55server/atheneum/api/model.py
-
23server/atheneum/api/user_api.py
-
14server/atheneum/service/user_service.py
-
4server/atheneum/utility/json_utility.py
-
20server/atheneum/utility/pagination_utility.py
-
55server/documentation/api/user.rst
-
39server/tests/api/test_user_api.py
@ -0,0 +1,20 @@ |
|||
"""Pagination utility functions.""" |
|||
from typing import Tuple |
|||
|
|||
from werkzeug.datastructures import MultiDict |
|||
|
|||
from atheneum import errors |
|||
|
|||
|
|||
def get_pagination_params(request_args: MultiDict) -> Tuple[int, int]: |
|||
"""Get page and perPage request parameters.""" |
|||
page = request_args.get('page', 1) |
|||
per_page = request_args.get('perPage', 20) |
|||
try: |
|||
return int(page), int(per_page) |
|||
except ValueError: |
|||
raise errors.ClientError( |
|||
' '.join([ |
|||
'Invalid pagination parameters:', |
|||
'page={}', |
|||
'perPage={}']).format(page, per_page)) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue