From 3a9ceaccb5326ff3b569e3f948b94107b7c26ee2 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sat, 21 Jul 2018 04:48:54 +0200 Subject: Completed the clean API and the clean frontend. --- pysite/views/api/bot/clean.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pysite/views/api/bot/clean.py (limited to 'pysite/views/api/bot/clean.py') diff --git a/pysite/views/api/bot/clean.py b/pysite/views/api/bot/clean.py new file mode 100644 index 00000000..216261ce --- /dev/null +++ b/pysite/views/api/bot/clean.py @@ -0,0 +1,44 @@ +from flask import jsonify +from schema import Schema + +from pysite.base_route import APIView +from pysite.constants import ValidationTypes +from pysite.decorators import api_key, api_params +from pysite.mixins import DBMixin + +POST_SCHEMA = Schema({ + 'log_data': [ + { + "author": str, + "content": str, + "timestamp": str + } + ] +}) + + +class CleanView(APIView, DBMixin): + path = '/bot/clean' + name = 'bot.clean' + table_name = 'clean_logs' + + @api_key + @api_params(schema=POST_SCHEMA, validation_type=ValidationTypes.json) + def post(self, data): + """ + Receive some log_data from a bulk deletion, + and store it in the database. + + Returns an ID which can be used to get the data + from the /bot/clean_logs/ endpoint. + """ + + # Insert and return the id to use for GET + insert = self.db.insert( + self.table_name, + { + "log_data": data["log_data"] + } + ) + + return jsonify({"log_id": insert['generated_keys'][0]}) -- cgit v1.2.3