-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (54 loc) · 1.83 KB
/
app.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
from flask import Flask, request
import db_interactions
import json
app = Flask(__name__)
db_interactions.initdb()
@app.route('/api/kids')
def get_kids():
kids = json.dumps(db_interactions.get_kids())
return kids
@app.route('/api/kids/<int:id>')
def get_kid(id):
return json.dumps(db_interactions.get_kid(id))
@app.route('/api/kids/<int:id>', methods=['PUT'])
def update_kid(id):
if not db_interactions.get_kid(id):
return 'False input'
user_data = json.loads(request.data)
return json.dumps(db_interactions.update_item('kids', user_data))
@app.route('/api/kids/<int:id>', methods=['DELETE'])
def delete_kid(id):
if not db_interactions.get_kid(id):
return 'False input'
return db_interactions.delete_item('kids', id)
@app.route('/api/kids', methods=['POST'])
def create_kid():
user_data = json.loads(request.data)
print(user_data)
return json.dumps(db_interactions.create_item(user_data))
@app.route('/api/logs')
def get_logs():
logs = json.dumps(db_interactions.get_logs())
return logs
@app.route('/api/logs', methods=['POST'])
def create_log_entry():
user_data = json.loads(request.data)
return json.dumps(db_interactions.create_log_entry(user_data))
@app.route('/api/logs/<int:id>')
def get_log(id):
log = json.dumps(db_interactions.get_log(id))
return log
@app.route('/api/logs/<int:id>', methods=['PUT'])
def update_log(id):
if not db_interactions.get_log(id):
return {'False input': 'False input'}
user_data = json.loads(request.data)
return json.dumps(db_interactions.update_log(user_data, id))
@app.route('/api/logs/<int:id>', methods=['DELETE'])
def delete_log(id):
if not db_interactions.get_log(id):
return 'False input'
return db_interactions.delete_item('logs', id)
if __name__ == '__main__':
app.debug = True
app.run()