diff options
Diffstat (limited to 'pydis_site/apps/api/viewsets')
| -rw-r--r-- | pydis_site/apps/api/viewsets/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/__init__.py | 2 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/aoc_completionist_block.py | 73 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/aoc_link.py | 71 | 
4 files changed, 148 insertions, 0 deletions
diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py index f133e77f..5fc1d64f 100644 --- a/pydis_site/apps/api/viewsets/__init__.py +++ b/pydis_site/apps/api/viewsets/__init__.py @@ -7,6 +7,8 @@ from .bot import (      InfractionViewSet,      NominationViewSet,      OffensiveMessageViewSet, +    AocAccountLinkViewSet, +    AocCompletionistBlockViewSet,      OffTopicChannelNameViewSet,      ReminderViewSet,      RoleViewSet, diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py index 84b87eab..f1d84729 100644 --- a/pydis_site/apps/api/viewsets/bot/__init__.py +++ b/pydis_site/apps/api/viewsets/bot/__init__.py @@ -7,6 +7,8 @@ from .infraction import InfractionViewSet  from .nomination import NominationViewSet  from .off_topic_channel_name import OffTopicChannelNameViewSet  from .offensive_message import OffensiveMessageViewSet +from .aoc_link import AocAccountLinkViewSet +from .aoc_completionist_block import AocCompletionistBlockViewSet  from .reminder import ReminderViewSet  from .role import RoleViewSet  from .user import UserViewSet diff --git a/pydis_site/apps/api/viewsets/bot/aoc_completionist_block.py b/pydis_site/apps/api/viewsets/bot/aoc_completionist_block.py new file mode 100644 index 00000000..3a4cec60 --- /dev/null +++ b/pydis_site/apps/api/viewsets/bot/aoc_completionist_block.py @@ -0,0 +1,73 @@ +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework.mixins import ( +    CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin +) +from rest_framework.viewsets import GenericViewSet + +from pydis_site.apps.api.models.bot import AocCompletionistBlock +from pydis_site.apps.api.serializers import AocCompletionistBlockSerializer + + +class AocCompletionistBlockViewSet( +    GenericViewSet, CreateModelMixin, DestroyModelMixin, RetrieveModelMixin, ListModelMixin +): +    """ +    View providing management for Users blocked from gettign the AoC completionist Role. + +    ## Routes + +    ### GET /bot/aoc-completionist-blocks/ +    Returns all the AoC completionist blocks + +    #### Response format +    >>> [ +    ...     { +    ...         "user": 2, +    ...         "is_blocked": False, +    ...         "reason": "Too good to be true" +    ...     } +    ... ] + + +    ### GET /bot/aoc-completionist-blocks/<user__id:int> +    Retrieve a single Block by User ID + +    #### Response format +    >>> +    ...     { +    ...         "user": 2, +    ...         "is_blocked": False, +    ...         "reason": "Too good to be true" +    ...     } + +    #### Status codes +    - 200: returned on success +    - 404: returned if an AoC completionist block with the given `user__id` was not found. + +    ### POST /bot/aoc-completionist-blocks +    Adds a single AoC completionist block + +    #### Request body +    >>> { +    ...     "user": int, +    ...     "is_blocked": bool, +    ...     "reason": string +    ... } + +    #### Status codes +    - 204: returned on success +    - 400: if one of the given fields is invalid + +    ### DELETE /bot/aoc-completionist-blocks/<user__id:int> +    Deletes the AoC Completionist block item with the given `user__id`. + +    #### Status codes +    - 204: returned on success +    - 404: returned if the AoC Completionist block with the given `user__id` was not found + +    """ + +    serializer_class = AocCompletionistBlockSerializer +    queryset = AocCompletionistBlock.objects.all() +    filter_backends = (DjangoFilterBackend,) +    filter_fields = ("user__id", "is_blocked") diff --git a/pydis_site/apps/api/viewsets/bot/aoc_link.py b/pydis_site/apps/api/viewsets/bot/aoc_link.py new file mode 100644 index 00000000..9f22c1a1 --- /dev/null +++ b/pydis_site/apps/api/viewsets/bot/aoc_link.py @@ -0,0 +1,71 @@ +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework.mixins import ( +    CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin +) +from rest_framework.viewsets import GenericViewSet + +from pydis_site.apps.api.models.bot import AocAccountLink +from pydis_site.apps.api.serializers import AocAccountLinkSerializer + + +class AocAccountLinkViewSet( +    GenericViewSet, CreateModelMixin, DestroyModelMixin, RetrieveModelMixin, ListModelMixin +): +    """ +    View providing management for Users who linked their AoC accounts to their Discord Account. + +    ## Routes + +    ### GET /bot/aoc-account-links +    Returns all the AoC account links + +    #### Response format +    >>> [ +    ...     { +    ...         "user": 2, +    ...         "aoc_username": "AoCUser1" +    ...     }, +    ...     ... +    ... ] + + +    ### GET /bot/aoc-account-links/<user__id:int> +    Retrieve a AoC account link by User ID + +    #### Response format +    >>> +    ... { +    ...     "user": 2, +    ...     "aoc_username": "AoCUser1" +    ... } + +    #### Status codes +    - 200: returned on success +    - 404: returned if an AoC account link with the given `user__id` was not found. + +    ### POST /bot/aoc-account-links +    Adds a single AoC account link block + +    #### Request body +    >>> { +    ...     'user': int, +    ...     'aoc_username': str +    ... } + +    #### Status codes +    - 204: returned on success +    - 400: if one of the given fields was invalid + +    ### DELETE /bot/aoc-account-links/<user__id:int> +    Deletes the AoC account link item with the given `user__id`. + +    #### Status codes +    - 204: returned on success +    - 404: returned if the AoC account link with the given `user__id` was not found + +    """ + +    serializer_class = AocAccountLinkSerializer +    queryset = AocAccountLink.objects.all() +    filter_backends = (DjangoFilterBackend,) +    filter_fields = ("user__id",)  |