diff options
author | 2019-01-22 23:30:15 +0100 | |
---|---|---|
committer | 2019-01-22 23:30:15 +0100 | |
commit | 475b3bcd51d5e016dcc3830d49000dda852264a7 (patch) | |
tree | db1d6761af3e4939746a037c482c22b22e09dd15 /api/viewsets.py | |
parent | Chonk down horrible JOIN performance. (diff) |
Add an API endpoint for reminders.
Diffstat (limited to 'api/viewsets.py')
-rw-r--r-- | api/viewsets.py | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/api/viewsets.py b/api/viewsets.py index f8dd13e8..83945fe8 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -15,18 +15,19 @@ from rest_framework_bulk import BulkCreateModelMixin from .models import ( DocumentationLink, Infraction, MessageDeletionContext, OffTopicChannelName, - Role, SnakeFact, - SnakeIdiom, SnakeName, - SpecialSnake, Tag, - User + Reminder, Role, + SnakeFact, SnakeIdiom, + SnakeName, SpecialSnake, + Tag, User ) from .serializers import ( DocumentationLinkSerializer, ExpandedInfractionSerializer, InfractionSerializer, MessageDeletionContextSerializer, - OffTopicChannelNameSerializer, RoleSerializer, - SnakeFactSerializer, SnakeIdiomSerializer, - SnakeNameSerializer, SpecialSnakeSerializer, - TagSerializer, UserSerializer + OffTopicChannelNameSerializer, ReminderSerializer, + RoleSerializer, SnakeFactSerializer, + SnakeIdiomSerializer, SnakeNameSerializer, + SpecialSnakeSerializer, TagSerializer, + UserSerializer ) @@ -356,6 +357,61 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): return Response(serialized.data) +class ReminderViewSet(CreateModelMixin, ListModelMixin, DestroyModelMixin, GenericViewSet): + """ + View providing CRUD access to reminders. + + ## Routes + ### GET /bot/reminders + Returns all reminders in the database. + + #### Response format + >>> [ + ... { + ... 'active': True, + ... 'author': 1020103901030, + ... 'content': "Make dinner", + ... 'expiration': '5018-11-20T15:52:00Z' + ... 'id': 11 + ... }, + ... ... + ... ] + + #### Status codes + - 200: returned on success + + ### POST /bot/reminders + Create a new reminder. + + #### Request body + >>> { + ... 'author': int, + ... 'content': str, + ... 'expiration': str # ISO-formatted datetime + ... } + + #### Status codes + - 201: returned on success + - 400: if the body format is invalid + - 404: if no user with the given ID could be found + + ### DELETE /bot/reminders/<id:int> + Delete the reminder with the given `id`. + + #### Status codes + - 204: returned on success + - 404: if a reminder with the given `id` does not exist + + ## Authentication + Requires an API token. + """ + + serializer_class = ReminderSerializer + queryset = Reminder.objects.prefetch_related('author') + filter_backends = (DjangoFilterBackend, SearchFilter) + filter_fields = ('active', 'author__id') + + class RoleViewSet(ModelViewSet): """ View providing CRUD access to the roles on our server, used |