aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2022-03-16 21:47:57 +0000
committerGravatar Chris Lovering <[email protected]>2022-03-16 21:52:07 +0000
commita0180619e77d884aeedb1a89748c0115c8ec8c56 (patch)
tree10cd9f4c382f20267e10ef57d227a00c589e4257 /pydis_site
parentOnly return list of ints when retrieving all BumpedThreads (diff)
Don't return the BumpedThread object when retrieving single
We only need to check for existence, so sending the full object isn't needed.
Diffstat (limited to 'pydis_site')
-rw-r--r--pydis_site/apps/api/viewsets/bot/bumped_thread.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/bumped_thread.py b/pydis_site/apps/api/viewsets/bot/bumped_thread.py
index 0972379b..9d77bb6b 100644
--- a/pydis_site/apps/api/viewsets/bot/bumped_thread.py
+++ b/pydis_site/apps/api/viewsets/bot/bumped_thread.py
@@ -1,6 +1,8 @@
from rest_framework.mixins import (
- CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
+ 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
@@ -8,7 +10,7 @@ from pydis_site.apps.api.serializers import BumpedThreadSerializer
class BumpedThreadViewSet(
- GenericViewSet, CreateModelMixin, DestroyModelMixin, RetrieveModelMixin, ListModelMixin
+ GenericViewSet, CreateModelMixin, DestroyModelMixin, ListModelMixin
):
"""
View providing CRUD (Minus the U) operations on threads to be bumped.
@@ -25,15 +27,10 @@ class BumpedThreadViewSet(
- 401: returned if unauthenticated
### GET /bot/bumped-threads/<thread_id:int>
- Returns a specific BumpedThread item from the database.
-
- #### Response format
- >>> {
- ... 'thread_id': "941705627405811793",
- ... }
+ Returns whether a specific BumpedThread exists in the database.
#### Status codes
- - 200: returned on success
+ - 204: returned on success
- 404: returned if a BumpedThread with the given thread_id was not found.
### POST /bot/bumped-threads
@@ -58,3 +55,12 @@ class BumpedThreadViewSet(
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)