diff options
| -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  |