aboutsummaryrefslogtreecommitdiffstats
path: root/api/viewsets.py
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2019-01-01 20:52:45 +0100
committerGravatar Johannes Christ <[email protected]>2019-01-01 20:52:45 +0100
commit8caf2e65fb084abbcede29cc977bdd6c5a6d0d9f (patch)
tree3e86cfbd6699cd5f0eec5a039a82c41d178e2ff7 /api/viewsets.py
parentSet up markdown & Dockerfile lints. (diff)
apply stash
Diffstat (limited to 'api/viewsets.py')
-rw-r--r--api/viewsets.py107
1 files changed, 99 insertions, 8 deletions
diff --git a/api/viewsets.py b/api/viewsets.py
index 08660810..67e89ea6 100644
--- a/api/viewsets.py
+++ b/api/viewsets.py
@@ -12,16 +12,16 @@ from rest_framework_bulk import BulkCreateModelMixin
from .models import (
DocumentationLink, Member,
OffTopicChannelName,
- SnakeFact, SnakeIdiom,
- SnakeName, SpecialSnake,
- Tag
+ Role, SnakeFact,
+ SnakeIdiom, SnakeName,
+ SpecialSnake, Tag
)
from .serializers import (
- DocumentationLinkSerializer,
- MemberSerializer, OffTopicChannelNameSerializer,
- SnakeFactSerializer, SnakeIdiomSerializer,
- SnakeNameSerializer, SpecialSnakeSerializer,
- TagSerializer
+ DocumentationLinkSerializer, MemberSerializer,
+ OffTopicChannelNameSerializer,
+ RoleSerializer, SnakeFactSerializer,
+ SnakeIdiomSerializer, SnakeNameSerializer,
+ SpecialSnakeSerializer, TagSerializer
)
@@ -178,6 +178,97 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
return Response(serialized.data)
+class RoleViewSet(ModelViewSet):
+ """
+ View providing CRUD access to the roles on our server, used
+ by the bot to keep a mirror of our server's roles on the site.
+
+ ## Routes
+ ### GET /bot/roles
+ Returns all roles in the database.
+
+ #### Response format
+ >>> [
+ ... {
+ ... 'id': 267628507062992896,
+ ... 'name': "Admins",
+ ... 'colour': 1337,
+ ... 'permissions': 8
+ ... }
+ ... ]
+
+ #### Status codes
+ - 200: returned on success
+
+ ### GET /bot/roles/<snowflake:int>
+ Gets a single role by ID.
+
+ #### Response format
+ >>> {
+ ... 'id': 267628507062992896,
+ ... 'name': "Admins",
+ ... 'colour': 1337,
+ ... 'permissions': 8
+ ... }
+
+ #### Status codes
+ - 200: returned on success
+ - 404: if a role with the given `snowflake` could not be found
+
+ ### POST /bot/roles
+ Adds a single new role.
+
+ #### Request body
+ >>> {
+ ... 'id': int,
+ ... 'name': str,
+ ... 'colour': int,
+ ... 'permissions': int,
+ ... }
+
+ #### Status codes
+ - 201: returned on success
+ - 400: if the body format is invalid
+
+ ### PUT /bot/roles/<snowflake:int>
+ Update the role with the given `snowflake`.
+ All fields in the request body are required.
+
+ #### Request body
+ >>> {
+ ... 'id': int,
+ ... 'name': str,
+ ... 'colour': int,
+ ... 'permissions': int
+ ... }
+
+ #### Status codes
+ - 200: returned on success
+ - 400: if the request body was invalid
+
+ ### PATCH /bot/roles/<snowflake:int>
+ Update the role with the given `snowflake`.
+ All fields in the request body are required.
+
+ >>> {
+ ... 'id': int,
+ ... 'name': str,
+ ... 'colour': int,
+ ... 'permissions': int
+ ... }
+
+ ### DELETE /bot/roles/<snowflake:int>
+ Deletes the role with the given `snowflake`.
+
+ #### Status codes
+ - 204: returned on success
+ - 404: if a role with the given `snowflake` does not exist
+ """
+
+ queryset = Role.objects.all()
+ serializer = RoleSerializer
+
+
class SnakeFactViewSet(ListModelMixin, GenericViewSet):
"""
View providing snake facts created by the Pydis community in the first code jam.