diff options
| author | 2022-03-21 14:13:42 -0500 | |
|---|---|---|
| committer | 2022-03-21 14:13:42 -0500 | |
| commit | c926ddb4d6c2d1313f51dd24d7c6e122e46f557d (patch) | |
| tree | a58b40ef3767e008d1f9a5a518f9c33a148efa8b /pydis_site/apps/api/viewsets | |
| parent | Fix end of file (diff) | |
| parent | Merge #663 - bumped threads endpoint (diff) | |
Merge branch 'python-discord:main' into vps-services
Diffstat (limited to 'pydis_site/apps/api/viewsets')
| -rw-r--r-- | pydis_site/apps/api/viewsets/__init__.py | 3 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/__init__.py | 1 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/bumped_thread.py | 66 | 
3 files changed, 69 insertions, 1 deletions
| diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py index 5fc1d64f..ec52416a 100644 --- a/pydis_site/apps/api/viewsets/__init__.py +++ b/pydis_site/apps/api/viewsets/__init__.py @@ -1,9 +1,10 @@  # flake8: noqa  from .bot import ( -    FilterListViewSet,      BotSettingViewSet, +    BumpedThreadViewSet,      DeletedMessageViewSet,      DocumentationLinkViewSet, +    FilterListViewSet,      InfractionViewSet,      NominationViewSet,      OffensiveMessageViewSet, diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py index f1d84729..262aa59f 100644 --- a/pydis_site/apps/api/viewsets/bot/__init__.py +++ b/pydis_site/apps/api/viewsets/bot/__init__.py @@ -1,6 +1,7 @@  # flake8: noqa  from .filter_list import FilterListViewSet  from .bot_setting import BotSettingViewSet +from .bumped_thread import BumpedThreadViewSet  from .deleted_message import DeletedMessageViewSet  from .documentation_link import DocumentationLinkViewSet  from .infraction import InfractionViewSet diff --git a/pydis_site/apps/api/viewsets/bot/bumped_thread.py b/pydis_site/apps/api/viewsets/bot/bumped_thread.py new file mode 100644 index 00000000..9d77bb6b --- /dev/null +++ b/pydis_site/apps/api/viewsets/bot/bumped_thread.py @@ -0,0 +1,66 @@ +from rest_framework.mixins import ( +    CreateModelMixin, DestroyModelMixin, ListModelMixin +) +from rest_framework.request import Request +from rest_framework.response import Response +from rest_framework.viewsets import GenericViewSet + +from pydis_site.apps.api.models.bot import BumpedThread +from pydis_site.apps.api.serializers import BumpedThreadSerializer + + +class BumpedThreadViewSet( +    GenericViewSet, CreateModelMixin, DestroyModelMixin, ListModelMixin +): +    """ +    View providing CRUD (Minus the U) operations on threads to be bumped. + +    ## Routes +    ### GET /bot/bumped-threads +    Returns all BumpedThread items in the database. + +    #### Response format +    >>> list[int] + +    #### Status codes +    - 200: returned on success +    - 401: returned if unauthenticated + +    ### GET /bot/bumped-threads/<thread_id:int> +    Returns whether a specific BumpedThread exists in the database. + +    #### Status codes +    - 204: returned on success +    - 404: returned if a BumpedThread with the given thread_id was not found. + +    ### POST /bot/bumped-threads +    Adds a single BumpedThread item to the database. + +    #### Request body +    >>> { +    ...    'thread_id': int, +    ... } + +    #### Status codes +    - 201: returned on success +    - 400: if one of the given fields is invalid + +    ### DELETE /bot/bumped-threads/<thread_id:int> +    Deletes the BumpedThread item with the given `thread_id`. + +    #### Status codes +    - 204: returned on success +    - 404: if a BumpedThread with the given `thread_id` does not exist +    """ + +    serializer_class = BumpedThreadSerializer +    queryset = BumpedThread.objects.all() + +    def retrieve(self, request: Request, *args, **kwargs) -> Response: +        """ +        DRF method for checking if the given BumpedThread exists. + +        Called by the Django Rest Framework in response to the corresponding HTTP request. +        """ +        self.get_object() +        return Response(status=204) | 
