aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets/bot/role.py
blob: 1f82208d6785ef47cac50f772ff01c2c5094f51c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from rest_framework.viewsets import ModelViewSet

from pydis_site.apps.api.models.bot.role import Role
from pydis_site.apps.api.serializers import RoleSerializer


class RoleViewSet(ModelViewSet):
    """
    View providing CRUD access to the roles on our server.

    This is 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,
    ...         'position': 1
    ...     }
    ... ]

    #### 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,
    ...     'position': 1
    ... }

    #### 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,
    ...     'position': 1,
    ... }

    #### 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,
    ...     'position': 1,
    ... }

    #### Status codes
    - 200: returned on success
    - 400: if the request body was invalid
    - 404: if a role with the given `snowflake` does not exist

    ### PATCH /bot/roles/<snowflake:int>
    Update the role with the given `snowflake`.

    #### Request body
    >>> {
    ...     'id': int,
    ...     'name': str,
    ...     'colour': int,
    ...     'permissions': int,
    ...     'position': 1,
    ... }

    #### Status codes
    - 200: returned on success
    - 400: if the request body was invalid
    - 404: if a role with the given `snowflake` does not exist

    ### 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_class = RoleSerializer