aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets/bot
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-04-24 17:02:28 +0200
committerGravatar GitHub <[email protected]>2021-04-24 17:02:28 +0200
commit478dfb2dd0f00ecbecadffebd1600ca9ca53017a (patch)
tree098b7572e2b380b7f57ae7eedb180fa0b70edc8e /pydis_site/apps/api/viewsets/bot
parentMerge pull request #481 from dawnofmidnight/patch-1 (diff)
parentMerge branch 'main' into limit-infraction-result (diff)
Merge pull request #443 from kunal097/limit-infraction-result
Apply LimitOffsetPagination in GET Infraction with default Page Size 100
Diffstat (limited to 'pydis_site/apps/api/viewsets/bot')
-rw-r--r--pydis_site/apps/api/viewsets/bot/infraction.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py
index 423e806e..bd512ddd 100644
--- a/pydis_site/apps/api/viewsets/bot/infraction.py
+++ b/pydis_site/apps/api/viewsets/bot/infraction.py
@@ -13,6 +13,7 @@ from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from pydis_site.apps.api.models.bot.infraction import Infraction
+from pydis_site.apps.api.pagination import LimitOffsetPaginationExtended
from pydis_site.apps.api.serializers import (
ExpandedInfractionSerializer,
InfractionSerializer
@@ -38,6 +39,8 @@ class InfractionViewSet(
- **active** `bool`: whether the infraction is still active
- **actor__id** `int`: snowflake of the user which applied the infraction
- **hidden** `bool`: whether the infraction is a shadow infraction
+ - **limit** `int`: number of results return per page (default 100)
+ - **offset** `int`: the initial index from which to return the results (default 0)
- **search** `str`: regular expression applied to the infraction's reason
- **type** `str`: the type of the infraction
- **user__id** `int`: snowflake of the user to which the infraction was applied
@@ -46,6 +49,7 @@ class InfractionViewSet(
Invalid query parameters are ignored.
#### Response format
+ Response is paginated but the result is returned without any pagination metadata.
>>> [
... {
... 'id': 5,
@@ -133,6 +137,7 @@ class InfractionViewSet(
serializer_class = InfractionSerializer
queryset = Infraction.objects.all()
+ pagination_class = LimitOffsetPaginationExtended
filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
filter_fields = ('user__id', 'actor__id', 'active', 'hidden', 'type')
search_fields = ('$reason',)