-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-prod.py
More file actions
55 lines (40 loc) · 1.58 KB
/
Copy pathapi-prod.py
File metadata and controls
55 lines (40 loc) · 1.58 KB
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
import json
from flask import Flask, request
from src.endpoints import Endpoints
from src.utils import obtain_logger
# Init
app = Flask(__name__)
endpoints = Endpoints()
logger = obtain_logger("API")
@app.route('/community')
def community():
"""Returns the averages of the community"""
return endpoints.community_endpoint()
@app.route('/user_data', methods=["POST"])
def user_data():
"""Save user data from the app"""
request_data = request.json
logger.info('A request has been received')
return endpoints.user_data_endpoint(request_data)
@app.route('/daily_questionnaires', methods=["POST"])
def daily_questionnaires():
"""Save user daily questionnaires data from the app"""
request_data = request.json
logger.info('A request has been received')
return endpoints.daily_questionnaires_endpoint(request_data)
@app.route('/one_off_questionnaires', methods=["POST"])
def one_off_questionnaires():
"""Save user one_off questionnaires data from the app"""
request_data = request.json
logger.info('A request has been received')
return endpoints.one_off_questionnaires_endpoint(request_data)
@app.route('/bg_data', methods=["POST"])
def user_databg():
"""Save user background data from the app"""
request_databg0 = request.json
request_databg = json.loads(request_databg0)
logger.info(f'A request has been received with the following data: {request_databg}')
return endpoints.user_databg_endpoint(request_databg)
# If this script is being executed and not imported, deploy the API
if __name__ == '__main__':
app.run(host="0.0.0.0")