-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
204 lines (146 loc) · 4.89 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
from flask import Flask
from flask import jsonify
from flask import request
from flask_cors import CORS
import json
from waitress import serve
app = Flask(__name__)
cors = CORS(app)
# Controllers
from controllers.matchController import MatchController
from controllers.candidateController import CandidateController
from controllers.citizenController import CitizenController
from controllers.resultController import ResultController
from controllers.tableController import TableController
matchC = MatchController()
candidateC = CandidateController()
citizenC = CitizenController()
resultC = ResultController()
tableC = TableController()
@app.route("/", methods=['GET'])
def test():
json = {"message": "Server is running......."}
return jsonify(json)
# -------------------------------- > Candidate
@app.route("/candidate", methods=['GET'])
def getAllCandidate():
json = candidateC.index()
return jsonify(json)
@app.route("/candidate", methods=['POST'])
def createCandidate():
data = request.get_json()
json = candidateC.create(data)
return jsonify(json[0]), json[1]
@app.route("/candidate/<string:id>", methods=['GET'])
def getCandidate(id):
json = candidateC.show(id)
return jsonify(json[0]), json[1]
@app.route("/candidate/<string:id>", methods=['PUT'])
def updateCandidate(id):
data = request.get_json()
json = candidateC.update(id, data)
return jsonify(json[0]), json[1]
@app.route("/candidate/<string:id>", methods=['DELETE'])
def deleteCandidate(id):
json = candidateC.delete(id)
return jsonify(json[0]), json[1]
# -------------------------------- > Citizen
@app.route("/citizen", methods=['GET'])
def getAllCitizen():
json = citizenC.index()
return jsonify(json)
@app.route("/citizen", methods=['POST'])
def createCitizen():
data = request.get_json()
json = citizenC.create(data)
return jsonify(json[0]), json[1]
@app.route("/citizen/<string:id>", methods=['GET'])
def getCitizen(id):
json = citizenC.show(id)
return jsonify(json[0]), json[1]
@app.route("/citizen/<string:id>", methods=['PUT'])
def updateCitizen(id):
data = request.get_json()
json = citizenC.update(id, data)
return jsonify(json[0]), json[1]
@app.route("/citizen/<string:id>", methods=['DELETE'])
def deleteCitizen(id):
json = citizenC.delete(id)
return jsonify(json[0]), json[1]
# -------------------------------- > Match
@app.route("/match", methods=['GET'])
def getAllMatch():
json = matchC.index()
return jsonify(json)
@app.route("/match", methods=['POST'])
def createMatch():
data = request.get_json()
json = matchC.create(data)
return jsonify(json)
@app.route("/match/<string:id>", methods=['GET'])
def getMatch(id):
json = matchC.show(id)
return jsonify(json[0]), json[1]
@app.route("/match/<string:id>", methods=['PUT'])
def updateMatch(id):
data = request.get_json()
json = matchC.update(id, data)
return jsonify(json[0]), json[1]
@app.route("/match/<string:id>", methods=['DELETE'])
def deleteMatch(id):
json = matchC.delete(id)
return jsonify(json[0]), json[1]
# -------------------------------- > Result
@app.route("/result", methods=['GET'])
def getAllResult():
json = resultC.index()
return jsonify(json)
@app.route("/result", methods=['POST'])
def createResult():
data = request.get_json()
json = resultC.create(data)
return jsonify(json[0]), json[1]
@app.route("/result/<string:id>", methods=['GET'])
def getResult(id):
json = resultC.show(id)
return jsonify(json[0]), json[1]
@app.route("/result/<string:id>", methods=['PUT'])
def updateResult(id):
data = request.get_json()
json = resultC.update(id, data)
return jsonify(json[0]), json[1]
@app.route("/result/<string:id>", methods=['DELETE'])
def deleteResult(id):
json = resultC.delete(id)
return jsonify(json[0]), json[1]
# -------------------------------- > Table
@app.route("/table", methods=['GET'])
def getAllTable():
json = tableC.index()
return jsonify(json)
@app.route("/table", methods=['POST'])
def createTable():
data = request.get_json()
json = tableC.create(data)
return jsonify(json)
@app.route("/table/<string:id>", methods=['GET'])
def getTable(id):
json = tableC.show(id)
return jsonify(json[0]), json[1]
@app.route("/table/<string:id>", methods=['PUT'])
def updateTable(id):
data = request.get_json()
json = tableC.update(id, data)
return jsonify(json[0]), json[1]
@app.route("/table/<string:id>", methods=['DELETE'])
def deleteTable(id):
json = tableC.delete(id)
return jsonify(json[0]), json[1]
def loadFileConfig():
with open('config.json') as f:
data = json.load(f)
return data
if __name__ == '__main__':
dataConfig = loadFileConfig()
print("Sever is running : " + "http://" + dataConfig["url-backend"] + ":" + str(dataConfig["port"]))
serve(app, host=dataConfig["url-backend"], port=dataConfig["port"])