aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-12 08:55:40 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-12 08:55:40 +0100
commit599108b21979039117ffe1de1817e71644a20fb4 (patch)
tree3a123627478a5280aeaf65910cbbe6b767f2987f /api
parentb34662346733ded378b31d8b1ba1e8b2953ec49a (diff)
cleaner endpoint names
Diffstat (limited to 'api')
-rw-r--r--api/dynamic_import.py1
-rw-r--r--api/status.py2
-rw-r--r--api/user/preferences.py27
-rw-r--r--api/user/status.py (renamed from api/user/updateStatus.py)6
-rw-r--r--api/user/updatePreferences.py32
5 files changed, 30 insertions, 38 deletions
diff --git a/api/dynamic_import.py b/api/dynamic_import.py
index eb8f0c2..3b05764 100644
--- a/api/dynamic_import.py
+++ b/api/dynamic_import.py
@@ -1,4 +1,5 @@
from app import app
+from flask import url_for
import importlib
import os
import log
diff --git a/api/status.py b/api/status.py
index 6404a7f..19a01a1 100644
--- a/api/status.py
+++ b/api/status.py
@@ -1,7 +1,7 @@
from flask import Blueprint
from db import cursor
-status = Blueprint('status', __name__)
+status = Blueprint('server_status', __name__)
@status.route('/status')
def index():
diff --git a/api/user/preferences.py b/api/user/preferences.py
index 5d46f5f..bfbfe66 100644
--- a/api/user/preferences.py
+++ b/api/user/preferences.py
@@ -3,10 +3,13 @@ from db import cursor
from auth.login_token import token_login
import json
+def format_preferences(preferences): #TODO: remove excess properties (create preferences class?)
+ return json.dumps(preferences) or ""
+
preferences = Blueprint('preferences', __name__)
-@preferences.route('/preferences')
-def index():
+@preferences.route('/preferences', methods = ["GET"])
+def get_preferences():
data = request.get_json()
token = request.cookies.get("token") or ""
@@ -19,5 +22,25 @@ def index():
user_prefs = cursor.execute("select preferences from users where user_id = ?", [login]).fetchone()
return { "preferences": json.loads(user_prefs[0]) }, 200
+@preferences.route('/preferences', methods = ["POST"])
+def index():
+ data = request.get_json()
+
+ new_preferences = data.get("newPreferences") or ""
+ token = request.cookies.get("token") or ""
+
+ if not token: return "", 401
+ login = token_login(token) or ""
+
+ if not login: return "", 403
+
+ formatted_json = format_preferences(new_preferences)
+ if not formatted_json: return "", 400
+
+ cursor.execute("update users set preferences = ? where user_id = ?", [formatted_json, login])
+ connection.commit()
+
+ return "", 200
+
dynamic_route = ["/user", preferences]
diff --git a/api/user/updateStatus.py b/api/user/status.py
index de32e95..e2895d5 100644
--- a/api/user/updateStatus.py
+++ b/api/user/status.py
@@ -3,9 +3,9 @@ from db import cursor, connection
from auth.login_token import token_login
import json
-updateStatus = Blueprint('updateStatus', __name__)
+status = Blueprint('user_status', __name__)
-@updateStatus.route('/updateStatus', methods = ['POST'])
+@status.route('/status', methods = ['POST'])
def index():
data = request.get_json()
@@ -23,5 +23,5 @@ def index():
return "", 200
-dynamic_route = ["/user", updateStatus]
+dynamic_route = ["/user", status]
diff --git a/api/user/updatePreferences.py b/api/user/updatePreferences.py
deleted file mode 100644
index 2eb6512..0000000
--- a/api/user/updatePreferences.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from flask import Blueprint, request
-from db import cursor, connection
-from auth.login_token import token_login
-import json
-
-def format_preferences(preferences): #TODO: remove excess properties (create preferences class?)
- return json.dumps(preferences) or ""
-
-updatePreferences = Blueprint('updatePreferences', __name__)
-
-@updatePreferences.route('/updatePreferences', methods = ['POST'])
-def index():
- data = request.get_json()
-
- new_preferences = data.get("newPreferences") or ""
- token = request.cookies.get("token") or ""
-
- if not token: return "", 401
- login = token_login(token) or ""
-
- if not login: return "", 403
-
- formatted_json = format_preferences(new_preferences)
- if not formatted_json: return "", 400
-
- cursor.execute("update users set preferences = ? where user_id = ?", [formatted_json, login])
- connection.commit()
-
- return "", 200
-
-dynamic_route = ["/user", updatePreferences]
-