-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
44 lines (33 loc) · 1.09 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
import os
from flasgger import Swagger
from flask import Flask, redirect
from flask_restful import Api
from webargs.flaskparser import parser, abort
from common.config import template
from resources.lists import AllGroups, AllTeachers
from resources.schedule import Group, Teacher
from resources.validate import GroupValidate, TeacherValidate
app = Flask(__name__)
app.config['RESTFUL_JSON'] = {
'ensure_ascii': False
}
app.config['SWAGGER'] = {
'title': 'Schedule API',
'uiversion': 3,
}
api = Api(app)
swagger = Swagger(app, template=template)
@app.route('/')
def redirect_to_docs():
return redirect('/apidocs')
@parser.error_handler
def handle_request_parsing_error(err, *args):
abort(422, errors=err.messages)
api.add_resource(Group, '/groups/schedule')
api.add_resource(Teacher, '/teachers/schedule')
api.add_resource(AllGroups, '/groups')
api.add_resource(AllTeachers, '/teachers')
api.add_resource(GroupValidate, '/groups/exists')
api.add_resource(TeacherValidate, '/teachers/exists')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=os.environ.get('PORT', 5000))