diff options
Diffstat (limited to 'api/viewsets.py')
-rw-r--r-- | api/viewsets.py | 69 |
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() |