-
Notifications
You must be signed in to change notification settings - Fork 0
/
p.py
110 lines (72 loc) · 2.82 KB
/
p.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
data = {
"key": "value",
"new": "new_val"
}
k, v = data.popitem()
new_data = v
data["id"] = "cid"
print(data, new_data)
# cursor = mysql.connection.cursor()
# cursor.execute(f"SELECT contact_contactid FROM folder_has_contact WHERE folder_folderid = {folder_id}")
# contacts_in_folder = cursor.fetchall()
# cursor.close()
# values = tuple(chain.from_iterable(contacts_in_folder))
# cursor = mysql.connection.cursor()
# if len(values) == 1:
# value = values[0]
# cursor.execute(f"SELECT * FROM contacts WHERE contactid = {value}")
# elif len(values) == 0:
# abort(404)
# else:
# cursor.execute(f"SELECT * FROM contacts WHERE contactid IN {values}")
# results = cursor.fetchall()
# cursor.close()
# end_results = []
# for i in range(len(results)):
# result = results[i]
# result_formatted = contact_formatting(result)
# end_results.append(result_formatted)
# if result is None:
# abort(404)
# return jsonify(end_results)
# EDIT existing contact
# @app.route('/contacts/<contact_id>', methods=['PUT'])
# def update_contact(contact_id):
# cursor = mysql.connection.cursor()
# cursor.execute(f"SELECT contactid FROM contacts WHERE contactid = {contact_id}")
# result = cursor.fetchone()
# if result is None:
# abort(404)
# data = request.get_json()
# k, v = data.popitem()
# folder_assignment = v
# data["contact_id"] = contact_id
# query = (f"SELECT * FROM folder_has_contact WHERE contact_contactid = {contact_id}")
# sql = ("UPDATE contacts SET surname = %(surname)s, name = %(name)s, number = %(number)s, email = %(email)s WHERE contactid = %(contact_id)s")
# new_assignment = (f"INSERT INTO folder_has_contact VALUES ({folder_assignment}, {contact_id})")
# assignment = (f"UPDATE folder_has_contact SET folder_folderid = {folder_assignment} WHERE contact_contactid = {contact_id}")
# cursor.execute(query)
# query_result = cursor.fetchall()
# if len(query_result) == 0:
# cursor.execute(new_assignment)
# else:
# cursor.execute(assignment)
# cursor.execute(sql, data)
# mysql.connection.commit()
# cursor.close()
# return jsonify("")
# EDIT existing folder
# @app.route('/folders/<folder_id>', methods=['PUT'])
# def update_folder(folder_id):
# cursor = mysql.connection.cursor()
# cursor.execute(f"SELECT folderid FROM folders WHERE folderid = {folder_id}")
# result = cursor.fetchone()
# if result is None:
# abort(404)
# data = request.get_json()
# data["folder_id"] = folder_id
# sql = ("UPDATE folders SET name = %(name)s WHERE folderid = %(folder_id)s")
# cursor.execute(sql, data)
# mysql.connection.commit()
# cursor.close()
# return jsonify("")