diff options
Diffstat (limited to 'api/social')
-rw-r--r-- | api/social/create_relation.py | 2 | ||||
-rw-r--r-- | api/social/destroy_relation.py | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/api/social/create_relation.py b/api/social/create_relation.py index 7451b6d..eded25d 100644 --- a/api/social/create_relation.py +++ b/api/social/create_relation.py @@ -14,7 +14,7 @@ def create_relation(user_1_id, user_2_id, relation_type): 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]) - connection.commit + connection.commit() def create_relation_route(relation_type): def route(): diff --git a/api/social/destroy_relation.py b/api/social/destroy_relation.py new file mode 100644 index 0000000..1107024 --- /dev/null +++ b/api/social/destroy_relation.py @@ -0,0 +1,31 @@ +from flask import Blueprint, request +from db import cursor +from auth.login_token import token_login +from social.create_relation import remove_relation +from user.info import get_relation_to +import time + +remove = Blueprint('remove', __name__) + +@remove.route('/remove', methods = ['POST']) +def index(): + data = request.get_json() + + user_2_id = data.get("id") or "" + token = request.cookies.get("token") or "" + + if not token: return "", 401 + user_1_id = token_login(token) or "" + + if not user_1_id or \ + not user_2_id: + return "", 403 + + relation = get_relation_to(user_1_id, user_2_id) + if relation == "none": return 403 + + remove_relation(user_1_id, user_2_id) + return "", 200 + +dynamic_route = ["/social", remove] + |