aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/views
diff options
context:
space:
mode:
Diffstat (limited to 'pysite/views')
-rw-r--r--pysite/views/api/bot/tag.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/pysite/views/api/bot/tag.py b/pysite/views/api/bot/tag.py
index 84fd8977..ef17e8fa 100644
--- a/pysite/views/api/bot/tag.py
+++ b/pysite/views/api/bot/tag.py
@@ -4,6 +4,7 @@ from flask import jsonify, request
from pysite.base_route import APIView, DBViewMixin
from pysite.constants import ErrorCodes
+from pysite.decorators import valid_api_key
class TagView(APIView, DBViewMixin):
@@ -12,45 +13,44 @@ class TagView(APIView, DBViewMixin):
table_name = "tag"
table_primary_key = "tag_name"
+ @valid_api_key
def get(self):
"""
Data must be provided as params,
API key must be provided as header
"""
- api_key = request.headers.get("X-API-Key")
+
tag_name = request.args.get("tag_name")
- if self.validate_key(api_key):
- if tag_name:
- data = self.db.get(self.table_name, tag_name)
- else:
- data = self.db.pluck(self.table_name, "tag_name")
+ if tag_name:
+ data = self.db.get(self.table_name, tag_name)
else:
- return self.error(ErrorCodes.invalid_api_key)
+ data = self.db.pluck(self.table_name, "tag_name")
return jsonify(data or {})
+ @valid_api_key
def post(self):
- """ Data must be provided as JSON. """
- indata = request.get_json()
- tag_name = indata.get("tag_name")
- tag_content = indata.get("tag_content")
- tag_category = indata.get("tag_category")
- api_key = request.headers.get("X-API-Key")
-
- if self.validate_key(api_key):
- if tag_name and tag_content:
- self.db.insert(
- self.table_name,
- {
- "tag_name": tag_name,
- "tag_content": tag_content,
- "tag_category": tag_category
- }
- )
- else:
- return self.error(ErrorCodes.missing_parameters)
+ """
+ Data must be provided as JSON.
+ """
+
+ data = request.get_json()
+
+ tag_name = data.get("tag_name")
+ tag_content = data.get("tag_content")
+ tag_category = data.get("tag_category")
+
+ if tag_name and tag_content:
+ self.db.insert(
+ self.table_name,
+ {
+ "tag_name": tag_name,
+ "tag_content": tag_content,
+ "tag_category": tag_category
+ }
+ )
else:
- return self.error(ErrorCodes.invalid_api_key)
+ return self.error(ErrorCodes.missing_parameters)
return jsonify({"success": True})