Skip to content

Commit a018061

Browse files
committed
Don't return the BumpedThread object when retrieving single
We only need to check for existence, so sending the full object isn't needed.
1 parent 3e95570 commit a018061

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pydis_site/apps/api/viewsets/bot/bumped_thread.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from rest_framework.mixins import (
2-
CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
2+
CreateModelMixin, DestroyModelMixin, ListModelMixin
33
)
4+
from rest_framework.request import Request
5+
from rest_framework.response import Response
46
from rest_framework.viewsets import GenericViewSet
57

68
from pydis_site.apps.api.models.bot import BumpedThread
79
from pydis_site.apps.api.serializers import BumpedThreadSerializer
810

911

1012
class BumpedThreadViewSet(
11-
GenericViewSet, CreateModelMixin, DestroyModelMixin, RetrieveModelMixin, ListModelMixin
13+
GenericViewSet, CreateModelMixin, DestroyModelMixin, ListModelMixin
1214
):
1315
"""
1416
View providing CRUD (Minus the U) operations on threads to be bumped.
@@ -25,15 +27,10 @@ class BumpedThreadViewSet(
2527
- 401: returned if unauthenticated
2628
2729
### GET /bot/bumped-threads/<thread_id:int>
28-
Returns a specific BumpedThread item from the database.
29-
30-
#### Response format
31-
>>> {
32-
... 'thread_id': "941705627405811793",
33-
... }
30+
Returns whether a specific BumpedThread exists in the database.
3431
3532
#### Status codes
36-
- 200: returned on success
33+
- 204: returned on success
3734
- 404: returned if a BumpedThread with the given thread_id was not found.
3835
3936
### POST /bot/bumped-threads
@@ -58,3 +55,12 @@ class BumpedThreadViewSet(
5855

5956
serializer_class = BumpedThreadSerializer
6057
queryset = BumpedThread.objects.all()
58+
59+
def retrieve(self, request: Request, *args, **kwargs) -> Response:
60+
"""
61+
DRF method for checking if the given BumpedThread exists.
62+
63+
Called by the Django Rest Framework in response to the corresponding HTTP request.
64+
"""
65+
self.get_object()
66+
return Response(status=204)

0 commit comments

Comments
 (0)