aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets/bot/bumped_thread.py
blob: 9d77bb6bdbabc1946c9ac4517393747625eb1711 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)