diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-03-28 12:19:28 +0200 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-03-28 12:19:28 +0200 |
commit | 2f4536d6b08b69168ebf3e718cbd8e3002b9af5a (patch) | |
tree | 5307692fb341d7f924ee9b73f3751e7e56cfb192 /api/social | |
parent | 1f897d3f5ad11178cf4776ae4070c9d3e832f5f3 (diff) |
added comments
Diffstat (limited to 'api/social')
-rw-r--r-- | api/social/create_relation.py | 4 | ||||
-rw-r--r-- | api/social/request_list.py | 2 | ||||
-rw-r--r-- | api/social/search.py | 3 |
3 files changed, 8 insertions, 1 deletions
diff --git a/api/social/create_relation.py b/api/social/create_relation.py index eb38978..7e7c466 100644 --- a/api/social/create_relation.py +++ b/api/social/create_relation.py @@ -4,6 +4,8 @@ from hierarchy import auth_required from socket_io import io import time +# @two_person_endpoint decorator +# defines (user_1_id, user_2_id) in endpoint handler function arguments def two_person_endpoint(func): @auth_required("user") def wrapper(user_1_id): @@ -26,6 +28,7 @@ def create_relation(user_1_id, user_2_id, relation_type): [user_1_id, user_2_id, relation_type, timestamp]) connection.commit() +# remove relation between user_1_id and user_2_id (one-way) def remove_relation(user_1_id, user_2_id): cursor.execute("delete from social where user_1_id = ? and user_2_id = ?", [user_1_id, user_2_id]) @@ -42,7 +45,6 @@ def create_relation_route(relation_type): return "", 200 return route - friend_request = Blueprint('friend_request', __name__) friend_request.add_url_rule('/request', 'route', create_relation_route("outgoing"), methods = ["POST"]) diff --git a/api/social/request_list.py b/api/social/request_list.py index a2b23d5..624b3b4 100644 --- a/api/social/request_list.py +++ b/api/social/request_list.py @@ -9,9 +9,11 @@ requests = Blueprint('requests', __name__) @requests.route("/requests") @auth_required("user") def route(user_2_id): + # get a list of friend requests request_list = cursor.execute("select user_1_id from social where user_2_id = ? and type = \"outgoing\"", [user_2_id]).fetchall() + # get user_id for each result to prevent repeat user/info requests formatted_request_list = [] for user_1_id in [q[0] for q in request_list]: formatted_request_list.append(format_user(user_1_id)) diff --git a/api/social/search.py b/api/social/search.py index ccc62e5..1159c67 100644 --- a/api/social/search.py +++ b/api/social/search.py @@ -13,10 +13,13 @@ def index(): if not query: return "", 400 if len(query) < 3: return "", 403 + # use levenshtein with max distance 3 to search for users + #TODO: use mysql and sort by best match results = cursor.execute("select user_id from users where levenshtein(lower(username), lower(?), 3)", [query]).fetchmany(20); formatted = { "results": [] } + # get user_id for each result to prevent repeat user/info requests for user in results: formatted["results"].append(format_user(user[0])) |