aboutsummaryrefslogtreecommitdiffstats
path: root/api/viewsets.py
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2018-11-25 11:16:57 +0100
committerGravatar Johannes Christ <[email protected]>2018-11-25 11:16:57 +0100
commit87a48cad5197234a6ccff616fec17a027b2adcb8 (patch)
tree0ea7bebddf9ce216e94602ddeca300184729fb00 /api/viewsets.py
parentUse proper attribute name. (diff)
parentSet up image pushing and building on Azure. (#152) (diff)
Merge branch 'django' into django+add-logs-api.
Diffstat (limited to 'api/viewsets.py')
-rw-r--r--api/viewsets.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/api/viewsets.py b/api/viewsets.py
index 8dca5b2a..e406e8c3 100644
--- a/api/viewsets.py
+++ b/api/viewsets.py
@@ -10,18 +10,18 @@ from rest_framework.viewsets import GenericViewSet, ModelViewSet, ViewSet
from rest_framework_bulk import BulkCreateModelMixin
from .models import (
- DocumentationLink, Member,
- MessageDeletionContext, OffTopicChannelName,
- Role, SnakeFact,
- SnakeIdiom, SnakeName,
- SpecialSnake, Tag
+ DocumentationLink, MessageDeletionContext,
+ OffTopicChannelName, Role,
+ SnakeFact, SnakeIdiom,
+ SnakeName, SpecialSnake,
+ Tag, User
)
from .serializers import (
- DocumentationLinkSerializer, MemberSerializer,
- MessageDeletionContextSerializer, OffTopicChannelNameSerializer,
- RoleSerializer, SnakeFactSerializer,
- SnakeIdiomSerializer, SnakeNameSerializer,
- SpecialSnakeSerializer, TagSerializer
+ DocumentationLinkSerializer, MessageDeletionContextSerializer,
+ OffTopicChannelNameSerializer, RoleSerializer,
+ SnakeFactSerializer, SnakeIdiomSerializer,
+ SnakeNameSerializer, SpecialSnakeSerializer,
+ TagSerializer, UserSerializer
)
@@ -539,13 +539,13 @@ class TagViewSet(ModelViewSet):
queryset = Tag.objects.all()
-class MemberViewSet(BulkCreateModelMixin, ModelViewSet):
+class UserViewSet(BulkCreateModelMixin, ModelViewSet):
"""
- View providing CRUD operations on our Discord server's members through the bot.
+ View providing CRUD operations on Discord users through the bot.
## Routes
- ### GET /bot/members
- Returns all members currently known.
+ ### GET /bot/users
+ Returns all users currently known.
#### Response format
>>> [
@@ -559,15 +559,16 @@ class MemberViewSet(BulkCreateModelMixin, ModelViewSet):
... 270988689419665409,
... 277546923144249364,
... 458226699344019457
- ... ]
+ ... ],
+ ... 'in_guild': True
... }
... ]
#### Status codes
- 200: returned on success
- ### GET /bot/members/<snowflake:int>
- Gets a single member by ID.
+ ### GET /bot/users/<snowflake:int>
+ Gets a single user by ID.
#### Response format
>>> {
@@ -580,16 +581,17 @@ class MemberViewSet(BulkCreateModelMixin, ModelViewSet):
... 270988689419665409,
... 277546923144249364,
... 458226699344019457
- ... ]
+ ... ],
+ ... 'in_guild': True
... }
#### Status codes
- 200: returned on success
- - 404: if a member with the given `snowflake` could not be found
+ - 404: if a user with the given `snowflake` could not be found
- ### POST /bot/members
- Adds a single or multiple new members.
- The roles attached to the member(s) must be roles known by the site.
+ ### POST /bot/users
+ Adds a single or multiple new users.
+ The roles attached to the user(s) must be roles known by the site.
#### Request body
>>> {
@@ -597,18 +599,19 @@ class MemberViewSet(BulkCreateModelMixin, ModelViewSet):
... 'avatar': str,
... 'name': str,
... 'discriminator': int,
- ... 'roles': List[int]
+ ... 'roles': List[int],
+ ... 'in_guild': bool
... }
- Alternatively, request members can be POSTed as a list of above objects,
- in which case multiple members will be created at once.
+ Alternatively, request users can be POSTed as a list of above objects,
+ in which case multiple users will be created at once.
#### Status codes
- 201: returned on success
- 400: if one of the given roles does not exist, or one of the given fields is invalid
- ### PUT /bot/members/<snowflake:int>
- Update the member with the given `snowflake`.
+ ### PUT /bot/users/<snowflake:int>
+ Update the user with the given `snowflake`.
All fields in the request body are required.
#### Request body
@@ -617,16 +620,17 @@ class MemberViewSet(BulkCreateModelMixin, ModelViewSet):
... 'avatar': str,
... 'name': str,
... 'discriminator': int,
- ... 'roles': List[int]
+ ... 'roles': List[int],
+ ... 'in_guild': bool
... }
#### Status codes
- 200: returned on success
- 400: if the request body was invalid, see response body for details
- - 404: if the member with the given `snowflake` could not be found
+ - 404: if the user with the given `snowflake` could not be found
- ### PATCH /bot/members/<snowflake:int>
- Update the member with the given `snowflake`.
+ ### PATCH /bot/users/<snowflake:int>
+ Update the user with the given `snowflake`.
All fields in the request body are optional.
#### Request body
@@ -635,21 +639,22 @@ class MemberViewSet(BulkCreateModelMixin, ModelViewSet):
... 'avatar': str,
... 'name': str,
... 'discriminator': int,
- ... 'roles': List[int]
+ ... 'roles': List[int],
+ ... 'in_guild': bool
... }
#### Status codes
- 200: returned on success
- 400: if the request body was invalid, see response body for details
- - 404: if the member with the given `snowflake` could not be found
+ - 404: if the user with the given `snowflake` could not be found
- ### DELETE /bot/members/<snowflake:int>
- Deletes the member with the given `snowflake`.
+ ### DELETE /bot/users/<snowflake:int>
+ Deletes the user with the given `snowflake`.
#### Status codes
- 204: returned on success
- - 404: if a member with the given `snowflake` does not exist
+ - 404: if a user with the given `snowflake` does not exist
"""
- serializer_class = MemberSerializer
- queryset = Member.objects.all()
+ serializer_class = UserSerializer
+ queryset = User.objects.all()