-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (63 loc) · 1.94 KB
/
main.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
from src import cup_matches
from flask import Flask
from flask_restx import Resource, Api, fields
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
app.config.SWAGGER_SUPPORTED_SUBMIT_METHODS = ["get"]
api = Api(app, version='1.0', title='World Cup Matches - NLW',
description='World Cup Matches API')
ns = api.namespace('cupmatches', description='Calendar operations')
# Responses Model
date = api.model("Date", {
"week": fields.String,
"month": fields.String,
"day": fields.Integer
})
team = api.model("Team", {
"name": fields.String,
"flag": fields.String,
})
teams = api.model("Teams", {
"team1": fields.Nested(team),
"team2": fields.Nested(team),
})
match = api.model("Match", {
"teams": fields.Nested(teams),
"time": fields.String,
})
matches = api.model("Matches", {
"matches": fields.List(fields.Nested(match)),
})
match_num = api.model("MatchesNumberByDate", {
"date": fields.Nested(date),
"match": fields.List(fields.Nested(match)),
})
all_matches = api.model("AllMatches", {
"match_num": fields.Nested(match_num),
})
class CupCalendarAPI(object):
def get_match(self, match_num):
match = cup_matches.get_matches_by_num(match_num)
if match:
return (match, 200)
api.abort(404, "Match {} doesn't exist".format(match_num))
def get_all_matches(self):
all_match = cup_matches.get_all_matches()
if all_match:
return (all_match, 200)
api.abort(404, "Error the searching all matches")
calendar = CupCalendarAPI()
@ns.route('/<int:match_num>')
@api.doc(params={'match_num': 'The match number'})
class MatchByNumber(Resource):
@ns.doc(model=match_num)
def get(self, match_num):
return calendar.get_match(match_num)
@ns.route("/all_matches")
class AllMatches(Resource):
@ns.doc(model=all_matches)
def get(self):
return calendar.get_all_matches()
if __name__ == "__main__":
app.run()