aboutsummaryrefslogtreecommitdiffstats
path: root/api/viewsets.py
diff options
context:
space:
mode:
authorGravatar Mark <[email protected]>2018-11-19 13:17:36 -0800
committerGravatar Johannes Christ <[email protected]>2018-11-19 22:17:36 +0100
commitc58f5c749ae1f4a411dd4cc9a8395dedddf93027 (patch)
tree73d3b2e2756e4c93e49760c34e2d2771d39374c4 /api/viewsets.py
parentSet up markdown & Dockerfile lints. (diff)
Django - Add Support for Storing Users Not in Guild (#150)
* rename Member to User * add boolean field to distinguish users in our server * mark roles as not required * fix import order lint errors * fix order of model registration
Diffstat (limited to '')
-rw-r--r--api/viewsets.py69
1 files changed, 37 insertions, 32 deletions
diff --git a/api/viewsets.py b/api/viewsets.py
index 08660810..de5ddaf6 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,
+ DocumentationLink,
OffTopicChannelName,
SnakeFact, SnakeIdiom,
SnakeName, SpecialSnake,
- Tag
+ Tag, User
)
from .serializers import (
DocumentationLinkSerializer,
- MemberSerializer, OffTopicChannelNameSerializer,
+ OffTopicChannelNameSerializer,
SnakeFactSerializer, SnakeIdiomSerializer,
SnakeNameSerializer, SpecialSnakeSerializer,
- TagSerializer
+ TagSerializer, UserSerializer
)
@@ -413,13 +413,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
>>> [
@@ -433,15 +433,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
>>> {
@@ -454,16 +455,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
>>> {
@@ -471,18 +473,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
@@ -491,16 +494,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
@@ -509,21 +513,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()