diff options
author | 2020-08-26 20:51:05 +0530 | |
---|---|---|
committer | 2020-08-26 21:04:37 +0530 | |
commit | 464408462cdb737b1eb78777c356253f9d5f0a4a (patch) | |
tree | 6e88e741270a9f47391d614f83bc9c18304708c2 /pydis_site | |
parent | Merge pull request #374 from Numerlor/reminder-direct-retrieve (diff) |
add pagination for GET request on /bot/users endpoint
Pagination is done via PageNumberPagination, i.e, each page contains a specific number of `user` objects.
Diffstat (limited to 'pydis_site')
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/user.py | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/user.py b/pydis_site/apps/api/viewsets/bot/user.py index 9571b3d7..b016bb66 100644 --- a/pydis_site/apps/api/viewsets/bot/user.py +++ b/pydis_site/apps/api/viewsets/bot/user.py @@ -1,3 +1,4 @@ +from rest_framework.pagination import PageNumberPagination from rest_framework.viewsets import ModelViewSet from rest_framework_bulk import BulkCreateModelMixin @@ -5,17 +6,28 @@ from pydis_site.apps.api.models.bot.user import User from pydis_site.apps.api.serializers import UserSerializer +class UserListPagination(PageNumberPagination): + """Custom pagination class for the User Model.""" + + page_size = 10000 + page_size_query_param = "page_size" + + class UserViewSet(BulkCreateModelMixin, ModelViewSet): """ View providing CRUD operations on Discord users through the bot. ## Routes ### GET /bot/users - Returns all users currently known. + Returns all users currently known with pagination. #### Response format - >>> [ - ... { + >>> { + ... 'count': 95000, + ... 'next': "http://api.pythondiscord.com/bot/users?page=2", + ... 'previous': None, + ... 'results': [ + ... { ... 'id': 409107086526644234, ... 'name': "Python", ... 'discriminator': 4329, @@ -26,8 +38,13 @@ class UserViewSet(BulkCreateModelMixin, ModelViewSet): ... 458226699344019457 ... ], ... 'in_guild': True - ... } - ... ] + ... }, + ... ] + ... } + + #### Query Parameters + - page_size: Number of Users in one page. + - page: Page number #### Status codes - 200: returned on success @@ -118,4 +135,5 @@ class UserViewSet(BulkCreateModelMixin, ModelViewSet): """ serializer_class = UserSerializer - queryset = User.objects + queryset = User.objects.all() + pagination_class = UserListPagination |