aboutsummaryrefslogtreecommitdiffstats
path: root/pysite
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-07-29 10:01:51 +0000
committerGravatar Leon Sandøy <[email protected]>2018-07-29 10:01:51 +0000
commit2d7b8cca4516d29785244bc774d3acc7eb2c02de (patch)
treea99b4acad28ffc04de3faa92553417abbb1d6343 /pysite
parentMerge branch 'clean_command' into 'master' (diff)
parentAdd `DELETE` route to `off-topic-names` endpoint. (diff)
Merge branch 'enhancement/delete-otname-route' into 'master'
Add `DELETE` route to `off-topic-names` endpoint. See merge request python-discord/projects/site!28
Diffstat (limited to 'pysite')
-rw-r--r--pysite/views/api/bot/off_topic_names.py47
1 files changed, 36 insertions, 11 deletions
diff --git a/pysite/views/api/bot/off_topic_names.py b/pysite/views/api/bot/off_topic_names.py
index f353ab02..1c75428e 100644
--- a/pysite/views/api/bot/off_topic_names.py
+++ b/pysite/views/api/bot/off_topic_names.py
@@ -9,18 +9,24 @@ from pysite.decorators import api_key, api_params
from pysite.mixins import DBMixin
-POST_SCHEMA = Schema({
- 'name': And(
- str,
- len,
- lambda name: all(c.isalnum() or c == '-' for c in name),
- str.islower,
- lambda name: len(name) <= 96,
- error=(
- "The channel name must be a non-blank string consisting only of"
- " lowercase regular characters and '-' with a maximum length of 96"
- )
+OFF_TOPIC_NAME = And(
+ str,
+ len,
+ lambda name: all(c.isalnum() or c == '-' for c in name),
+ str.islower,
+ lambda name: len(name) <= 96,
+ error=(
+ "The channel name must be a non-blank string consisting only of"
+ " lowercase regular characters and '-' with a maximum length of 96"
)
+)
+
+DELETE_SCHEMA = Schema({
+ 'name': OFF_TOPIC_NAME
+})
+
+POST_SCHEMA = Schema({
+ 'name': OFF_TOPIC_NAME
})
@@ -30,6 +36,25 @@ class OffTopicNamesView(APIView, DBMixin):
table_name = "off_topic_names"
@api_key
+ @api_params(schema=DELETE_SCHEMA, validation_type=ValidationTypes.params)
+ def delete(self, params):
+ """
+ Removes a single off-topic name from the database.
+ Returns the result of the deletion call.
+
+ API key must be provided as header.
+ Name to delete must be provided as the `name` query argument.
+ """
+
+ result = self.db.delete(
+ self.table_name,
+ params['name'],
+ return_changes=True
+ )
+
+ return jsonify(result)
+
+ @api_key
def get(self):
"""
Fetch all known off-topic channel names from the database.