aboutsummaryrefslogtreecommitdiff
path: root/api/social/destroy_relation.py
blob: 09b42f03c9ccbe74d14e084b36337ee3f4fa9e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)
    remove_relation(user_2_id, user_1_id)
    return "", 200

unblock = Blueprint('unblock', __name__)

@unblock.route('/unblock', 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

    if get_relation_to(user_1_id, user_2_id) != "blocked": return "", 403

    remove_relation(user_1_id, user_2_id)
    return "", 200

dynamic_routes = [
        ["/social", remove],
        ["/social", unblock]
        ]