From 836063835690df1cf721b6cfbe9ce0abd90ad4fc Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 17 Mar 2019 17:39:59 -0300 Subject: [PATCH] webhooks: add webhook delete impl --- litecord/blueprints/webhooks.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/litecord/blueprints/webhooks.py b/litecord/blueprints/webhooks.py index ead8eb2..3e7f99d 100644 --- a/litecord/blueprints/webhooks.py +++ b/litecord/blueprints/webhooks.py @@ -232,14 +232,31 @@ async def modify_webhook_tokened(webhook_id, webhook_token): return jsonify(await get_webhook(webhook_id, secure=False)) +async def delete_webhook(webhook_id: int): + """Delete a webhook.""" + res = await app.db.execute(""" + DELETE FROM webhooks + WHERE id = $1 + """, webhook_id) + + if res.lower() == 'delete 0': + raise WebhookNotFound() + + @bp.route('/webhooks/', methods=['DELETE']) async def del_webhook(webhook_id): - pass + """Delete a webhook.""" + await _webhook_check_fw(webhook_id) + await delete_webhook(webhook_id) + return '', 204 @bp.route('/webhooks//', methods=['DELETE']) async def del_webhook_tokened(webhook_id, webhook_token): - pass + """Delete a webhook, with its token.""" + await webhook_token_check(webhook_id, webhook_token) + await delete_webhook(webhook_id) + return '', 204 @bp.route('/webhooks//', methods=['POST'])