-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
78 lines (61 loc) · 2.37 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
from flask import Flask, request
from fifa_app.data_service import MongoAPI
from flask import jsonify
app = Flask(__name__)
mongo_api = MongoAPI()
@app.route("/")
def hello():
return "hello world"
# TODO: Create additional routing for other pages on app
# TODO: Create api routing for get requests, make calls to DB for associated data
@app.route("/api/v1/player/", methods=["GET"])
def get_player():
name = request.args["name"]
year = request.args["year"]
player = mongo_api.get_player(player=name, year=year)
return jsonify(player)
@app.route("/api/v1/players/", methods=["GET"])
def get_players():
query_params = request.args
players = mongo_api.get_players(query_params)
return jsonify(players)
@app.route("/api/v1/team/", methods=["GET"])
def get_team():
username = request.args["username"]
team_name = request.args["team_name"]
response = mongo_api.get_team(user=username, team_name=team_name)
return jsonify(response)
@app.route("/api/v1/team/", methods=["POST"])
def create_team():
if request.headers["content-type"] == "application/json":
data = request.json
data = jsonify(data).json
username = data["user"]
team_name = data["team_name"]
players = data["players"]
year = data["year"]
resp = mongo_api.create_team(user=username, team_name=team_name, players=players, year=year)
return jsonify(resp)
@app.route("/api/v1/team/edit/", methods=["PUT"])
def edit_team():
if request.headers["content-type"] == "application/json":
data = request.json
data = jsonify(data).json
username = data["user"]
team_name = data["team_name"]
year = data["year"]
p1_name = data["original_player_name"]
p2_name = data["replacing_player_name"]
resp = mongo_api.edit_team(user=username, team_name=team_name, year=year, original_player_name=p1_name, replacing_player_name=p2_name)
return jsonify(resp)
@app.route("/api/v1/team/replace/", methods=["GET"])
def get_player_recommendation():
print(request.args)
year = request.args["year"]
position = request.args["position"]
wage = request.args["wage"]
stat = request.args["stat_to_optimize"]
response = mongo_api.get_player_recommendation(year=year, position=position, wage=int(wage), stat_to_optimize=stat)
return jsonify(response)
if __name__ == '__main__':
app.run()