diff options
author | 2018-11-18 22:28:02 +0100 | |
---|---|---|
committer | 2018-11-18 22:28:02 +0100 | |
commit | 714ec7ffc63dc1b930d1ae80cabd964b8e48f55d (patch) | |
tree | a9dda25e5f0e5bd4e8ad237bfe16f1036cf5e599 | |
parent | Add `MessageDeletionContext` and `DeletedMessage` to the admin. (diff) |
Add viewsets and serializers.
-rw-r--r-- | api/serializers.py | 23 | ||||
-rw-r--r-- | api/viewsets.py | 41 |
2 files changed, 56 insertions, 8 deletions
diff --git a/api/serializers.py b/api/serializers.py index f8d15bbf..e39cd4a3 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -2,14 +2,27 @@ from rest_framework.serializers import ModelSerializer, PrimaryKeyRelatedField from rest_framework_bulk import BulkSerializerMixin from .models import ( - DocumentationLink, - Member, OffTopicChannelName, - Role, SnakeFact, - SnakeIdiom, SnakeName, - SpecialSnake, Tag + DeletedMessage, DocumentationLink, + Member, MessageDeletionContext, + OffTopicChannelName, Role, + SnakeFact, SnakeIdiom, + SnakeName, SpecialSnake, + Tag ) +class MessageDeletionContextSerializer(BulkSerializerMixin, ModelSerializer): + deleted_messages = PrimaryKeyRelatedField( + many=True, + queryset=DeletedMessage.objects.all() + ) + + class Meta: + model = MessageDeletionContext + fields = ('actor', 'creation', 'messages') + depth = 1 + + class DocumentationLinkSerializer(ModelSerializer): class Meta: model = DocumentationLink diff --git a/api/viewsets.py b/api/viewsets.py index 08660810..bc34de1d 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -11,20 +11,55 @@ from rest_framework_bulk import BulkCreateModelMixin from .models import ( DocumentationLink, Member, - OffTopicChannelName, + MessageDeletionContext, OffTopicChannelName, SnakeFact, SnakeIdiom, SnakeName, SpecialSnake, Tag ) from .serializers import ( - DocumentationLinkSerializer, - MemberSerializer, OffTopicChannelNameSerializer, + DocumentationLinkSerializer, MemberSerializer, + MessageDeletionContextSerializer, OffTopicChannelNameSerializer, SnakeFactSerializer, SnakeIdiomSerializer, SnakeNameSerializer, SpecialSnakeSerializer, TagSerializer ) +class DeletedMessageViewSet(GenericViewSet): + """ + View providing support for posting bulk deletion logs generated by the bot. + + ## Routes + ### POST /bot/deleted-messages + Post messages from bulk deletion logs. + + #### Body schema + >>> { + ... # The member ID of the original actor, if applicable. + ... # If a member ID is given, it must be present on the site. + ... 'actor': Optional[int] + ... 'creation': datetime, + ... 'messages': [ + ... { + ... 'id': int, + ... 'author': int, + ... 'channel_id': int, + ... 'content': str, + ... 'embeds': [ + ... # Discord embed objects + ... ] + ... } + ... ] + ... } + + #### Status codes + - 204: returned on success + """ + + queryset = MessageDeletionContext.objects.all() + serializer = MessageDeletionContextSerializer + + class DocumentationLinkViewSet( CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin, GenericViewSet ): |