aboutsummaryrefslogtreecommitdiff
path: root/api/social
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-09 15:04:42 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-09 15:04:42 +0100
commitda56acd469aa3dc07f9316f8543f7b32fe29deda (patch)
tree0413d61f01795e91d168070cfcd1cbd6b0cc4a0d /api/social
parenta024764a6b889d8a07119e71d91cc8a9440c8c20 (diff)
search function working :tada:
Diffstat (limited to 'api/social')
-rw-r--r--api/social/search.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/api/social/search.py b/api/social/search.py
new file mode 100644
index 0000000..712d0b8
--- /dev/null
+++ b/api/social/search.py
@@ -0,0 +1,26 @@
+from flask import Blueprint, request
+from db import cursor
+from user.info import format_user
+import json
+
+search = Blueprint('search', __name__)
+
+@search.route('/search', methods = ['GET', 'POST'])
+def index():
+ data_string = request.data or "{}"
+ data = json.loads(data_string)
+ query = data.get("query") or ""
+ if not query: return "", 400
+ if len(query) < 3: return "", 403
+
+ results = cursor.execute("select user_id from users where levenshtein(username, ?, 3)", [query]).fetchmany(20);
+
+ formatted = { "results": [] }
+
+ for user in results:
+ formatted["results"].append(format_user(user[0]))
+
+ return formatted, 200
+
+dynamic_route = ["/social", search]
+