diff options
author | 2019-01-01 20:52:45 +0100 | |
---|---|---|
committer | 2019-01-01 20:52:45 +0100 | |
commit | 8caf2e65fb084abbcede29cc977bdd6c5a6d0d9f (patch) | |
tree | 3e86cfbd6699cd5f0eec5a039a82c41d178e2ff7 /api | |
parent | Set up markdown & Dockerfile lints. (diff) |
apply stash
Diffstat (limited to 'api')
-rw-r--r-- | api/urls.py | 14 | ||||
-rw-r--r-- | api/viewsets.py | 107 |
2 files changed, 108 insertions, 13 deletions
diff --git a/api/urls.py b/api/urls.py index 8229b08c..203b6b00 100644 --- a/api/urls.py +++ b/api/urls.py @@ -3,11 +3,11 @@ from rest_framework.routers import DefaultRouter from .views import HealthcheckView from .viewsets import ( - DocumentationLinkViewSet, MemberViewSet, - OffTopicChannelNameViewSet, - SnakeFactViewSet, SnakeIdiomViewSet, - SnakeNameViewSet, SpecialSnakeViewSet, - TagViewSet + DeletedMessageViewSet, DocumentationLinkViewSet, + MemberViewSet, OffTopicChannelNameViewSet, + RoleViewSet, SnakeFactViewSet, + SnakeIdiomViewSet, SnakeNameViewSet, + SpecialSnakeViewSet, TagViewSet ) @@ -27,6 +27,10 @@ bot_router.register( MemberViewSet ) bot_router.register( + 'roles', + RoleViewSet +) +bot_router.register( 'snake-facts', SnakeFactViewSet ) 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. |