-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
106 lines (74 loc) · 2.81 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
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
from flask import Flask
from flask import request
from database_ops import DatabaseOperation
from business_logic import BusinessLogic
from flask import Response
app = Flask(__name__)
@app.route('/ping')
def ping():
return 'pong'
@app.route('/create_challenge', methods=['POST'])
def create_challenge():
json_body = request.get_json()
business_logic = BusinessLogic()
business_logic.create_challenge(json_body)
return "", 201
@app.route('/delete_challenges/<int:id>', methods=['DELETE'])
def delete_challenge(id):
business_logic = BusinessLogic()
status, message = business_logic.delete_challenge(id)
response = {}
if not status:
response["error"] = message
return response, 500
else:
response["success"] = message
return response, 200
@app.route("/update_challenge/<int:id>", methods=['PUT'])
def update_challenge(id):
json_body = request.get_json()
business_logic = BusinessLogic()
status, message = business_logic.update_challenge(id, json_body)
response = {}
if not status:
response["error"] = message
return response, 500
else:
response["success"] = message
return response, 201
@app.route('/accept_challenge', methods=['POST'])
def accept_challenge():
json_body = request.get_json()
business_logic = BusinessLogic()
business_logic.accept_challenge(json_body)
return "", 201
@app.route('/get_challenges', methods=['GET'])
def get_challenges():
business_logic = BusinessLogic()
return Response(business_logic.get_active_challenges(), 200, mimetype='application/json')
@app.route('/get_challenge_by_id/<int:id>', methods=['GET'])
def get_challenge_by_id(id):
business_logic = BusinessLogic()
return Response(business_logic.get_challenge_by_id(id), 200, mimetype='application/json')
@app.route('/get_users', methods=['GET'])
def get_users():
business_logic = BusinessLogic()
return Response(business_logic.get_users(), 200, mimetype='application/json')
@app.route('/get_accepted_challenges', methods=['GET'])
def get_accepted_challenges():
business_logic = BusinessLogic()
return Response(business_logic.get_accepted_challenges(), 200, mimetype='application/json')
@app.route('/get_badges', methods=['GET'])
def get_badges():
business_logic = BusinessLogic()
return Response(business_logic.get_badges(), 200, mimetype='application/json')
@app.route('/get_leaderboard', methods=['GET'])
def get_leaderboard():
business_logic = BusinessLogic()
return Response(business_logic.get_leaderboard(), 200, mimetype='application/json')
@app.route('/upload_challenge', methods=['PUT'])
def upload_challenge():
json_body = request.get_json()
business_logic = BusinessLogic()
business_logic.upload_challenge(json_body)
return "", 201