From b6a27fe99a54c4352930df34b22d2b0ad83bb0b5 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 26 Nov 2019 23:44:51 +0100 Subject: [PATCH] [DEV] update to sonic with a generic swagger --- Dockerfile | 4 +- src/__pycache__/data_interface.cpython-38.pyc | Bin 2628 -> 2628 bytes src/app_video.py | 498 ++++++++++++------ 3 files changed, 351 insertions(+), 151 deletions(-) diff --git a/Dockerfile b/Dockerfile index ee3a1b9..f53645d 100755 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,9 @@ FROM python:alpine RUN pip install --upgrade pip -RUN pip install flask +RUN pip install sanic -RUN pip install flask_restful +RUN pip install sanic-simple-swagger RUN pip install python-dateutil diff --git a/src/__pycache__/data_interface.cpython-38.pyc b/src/__pycache__/data_interface.cpython-38.pyc index 506395f33604fe4dafcc4fea278c8fd395c00a25..8420454d2f89e1e1575b2bd21d339fd8db374013 100644 GIT binary patch delta 20 acmX>iazunXl$V!_0SI2szq^s!k_!MiNd=hz delta 20 acmX>iazunXl$V!_0SHoJ?rh|?', strict_slashes=True) +app.blueprint(theme_blueprint) +""" + +def add_theme(_app, _name_api): + elem_blueprint = Blueprint(_name_api) + + class DataModel: + name = str + description = str + + @elem_blueprint.get('/' + _name_api, strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def list(request): + return response.json(data_global_elements.get_interface(_name_api).gets()) + + @elem_blueprint.post('/' + _name_api, strict_slashes=True) + @doc.summary("Create new resource") + @doc.description("Store a newly created resource in storage.") + @doc.consumes(DataModel, location='body')#, required=True) + @doc.response_success(status=201, description='If successful created') + async def create(request): + return response.json(data_global_elements.get_interface(_name_api).post(request.json)) + + @elem_blueprint.get('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def retrive(request, id): + value = data_global_elements.get_interface(_name_api).get(id) + if value != None: + return response.json(value) + raise ServerError("No data found", status_code=404) + + @elem_blueprint.put('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Update resource") + @doc.description("Update the specified resource in storage.") + @doc.response_success(status=201, description='If successful updated') + async def update(request, id): + ret = data_global_elements.get_interface(_name_api).put(id) + return response.json({}) + + @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Remove resource") + @doc.description("Remove the specified resource from storage.") + @doc.response_success(status=201, description='If successful deleted') + async def delete(request, id): + ret = data_global_elements.get_interface(_name_api).delete(id) + if ret == True: + return response.json({}) + raise ServerError("No data found", status_code=404) + + _app.blueprint(elem_blueprint) + +add_theme(app, API_THEME) + +def add_group(_app, _name_api): + elem_blueprint = Blueprint(_name_api) + + class DataModel: + name = str + + @elem_blueprint.get('/' + _name_api, strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def list(request): + return response.json(data_global_elements.get_interface(_name_api).gets()) + + @elem_blueprint.post('/' + _name_api, strict_slashes=True) + @doc.summary("Create new resource") + @doc.description("Store a newly created resource in storage.") + @doc.consumes(DataModel, location='body')#, required=True) + @doc.response_success(status=201, description='If successful created') + async def create(request): + return response.json(data_global_elements.get_interface(_name_api).post(request.json)) + + @elem_blueprint.get('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def retrive(request, id): + value = data_global_elements.get_interface(_name_api).get(id) + if value != None: + return response.json(value) + raise ServerError("No data found", status_code=404) + + @elem_blueprint.put('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Update resource") + @doc.description("Update the specified resource in storage.") + @doc.response_success(status=201, description='If successful updated') + async def update(request, id): + ret = data_global_elements.get_interface(_name_api).put(id) + return response.json({}) + + @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Remove resource") + @doc.description("Remove the specified resource from storage.") + @doc.response_success(status=201, description='If successful deleted') + async def delete(request, id): + ret = data_global_elements.get_interface(_name_api).delete(id) + if ret == True: + return response.json({}) + raise ServerError("No data found", status_code=404) + + _app.blueprint(elem_blueprint) + +add_group(app, API_GROUP) + +def add_saison(_app, _name_api): + elem_blueprint = Blueprint(_name_api) + + class DataModel: + number = int + group_id = int + + @elem_blueprint.get('/' + _name_api, strict_slashes=True) + @doc.summary("Show saisons") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def list(request): + return response.json(data_global_elements.get_interface(_name_api).gets()) + + @elem_blueprint.post('/' + _name_api, strict_slashes=True) + @doc.summary("Create new saison") + @doc.description("Create a new saison for a aspecific group id.") + @doc.consumes(DataModel, location='body')#, required=True) + @doc.response_success(status=201, description='If successful created') + async def create(request): + return response.json(data_global_elements.get_interface(_name_api).post(request.json)) + + @elem_blueprint.get('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def retrive(request, id): + value = data_global_elements.get_interface(_name_api).get(id) + if value != None: + return response.json(value) + raise ServerError("No data found", status_code=404) + + @elem_blueprint.put('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Update resource") + @doc.description("Update the specified resource in storage.") + @doc.response_success(status=201, description='If successful updated') + async def update(request, id): + ret = data_global_elements.get_interface(_name_api).put(id) + return response.json({}) + + @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Remove resource") + @doc.description("Remove the specified resource from storage.") + @doc.response_success(status=201, description='If successful deleted') + async def delete(request, id): + ret = data_global_elements.get_interface(_name_api).delete(id) + if ret == True: + return response.json({}) + raise ServerError("No data found", status_code=404) + + _app.blueprint(elem_blueprint) + +add_saison(app, API_SAISON) + +def add_video(_app, _name_api): + elem_blueprint = Blueprint(_name_api) + + class DataModel: + saison_id = int + group_id = int + name = str + description = str + # creating time + date = str + # number of second + time = int + + @elem_blueprint.get('/' + _name_api, strict_slashes=True) + @doc.summary("Show saisons") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def list(request): + return response.json(data_global_elements.get_interface(_name_api).gets()) + + @elem_blueprint.post('/' + _name_api, strict_slashes=True) + @doc.summary("Create new saison") + @doc.description("Create a new saison for a aspecific group id.") + @doc.consumes(DataModel, location='body')#, required=True) + @doc.response_success(status=201, description='If successful created') + async def create(request): + return response.json(data_global_elements.get_interface(_name_api).post(request.json)) + + @elem_blueprint.get('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.produces(content_type='application/json') + async def retrive(request, id): + value = data_global_elements.get_interface(_name_api).get(id) + if value != None: + return response.json(value) + raise ServerError("No data found", status_code=404) + + @elem_blueprint.put('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Update resource") + @doc.description("Update the specified resource in storage.") + @doc.response_success(status=201, description='If successful updated') + async def update(request, id): + ret = data_global_elements.get_interface(_name_api).put(id) + return response.json({}) + + @elem_blueprint.delete('/' + _name_api + '/', strict_slashes=True) + @doc.summary("Remove resource") + @doc.description("Remove the specified resource from storage.") + @doc.response_success(status=201, description='If successful deleted') + async def delete(request, id): + ret = data_global_elements.get_interface(_name_api).delete(id) + if ret == True: + return response.json({}) + raise ServerError("No data found", status_code=404) + + _app.blueprint(elem_blueprint) + +add_video(app, API_VIDEO) + +""" +def add_group(_group_name): + @app.route("/qsdqd") + @doc.description("Get all the Theme " + _group_name) + @doc.consumes({'name': str}, location='query', description='Student name', example={'name': 'john'}) + async def test(request): + return response.json({"hello": "world"}) + + +add_group("sqdfqsdfqsfgqsdf") +""" +def add_student(_app): + student_blueprint = Blueprint("student") + + class Student: + name = str + address = str + + @student_blueprint.get('/student', strict_slashes=True) + @doc.summary("Show resources") + @doc.description("Display a listing of the resource.") + @doc.deprecated(True) #if the api is deprecated + @doc.produces(content_type='application/json') + @doc.consumes({'name': str}, location='query', description='Student name', example={'name': 'john'}) + async def index(request): + pass + + @student_blueprint.post('/student', strict_slashes=True) + @doc.summary("Create new resource") + @doc.description("Store a newly created resource in storage.") + @doc.consumes(Student, location='body', required=True) + @doc.response_success(status=201, description='If successful created') + async def store(request): + pass + + @student_blueprint.put('/student/', strict_slashes=True) + @doc.summary("Update resource") + @doc.description("Update the specified resource in storage.") + @doc.response_success(status=201, description='If successful updated') + async def update(request, id): + pass + + @student_blueprint.delete('/student/', strict_slashes=True) + @doc.summary("Remove resource") + @doc.description("Remove the specified resource from storage.") + @doc.response_success(status=201, description='If successful deleted') + async def delete(request, id): + pass + + _app.blueprint(student_blueprint) + +add_student(app) + """ LIST_themes = [ { @@ -94,7 +425,7 @@ class Theme(Resource): return elem, 200 return "No data found in list of element: " + str(len(LIST_themes)), 404 """ - +""" class ThemeList(Resource): def __init__(self): self.name = API_THEME @@ -103,14 +434,14 @@ class ThemeList(Resource): def get(self): return data_global_elements.get_interface(self.name).gets(), 200 - """ + " "" def post(self): args = parser.parse_args() todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1 todo_id = 'todo%i' % todo_id TODOS[todo_id] = {'task': args['task']} return TODOS[todo_id], 201 - """ + "" " class Theme(Resource): def __init__(self): @@ -128,153 +459,22 @@ class Theme(Resource): if ret == True: return '', 204 return "No data found", 404 - """ + "" " def put(self, id): ret = data_global_elements.get_interface(self.name).put(id) return task, 201 - """ + " "" api.add_resource(ThemeList, "/api/v1/" + API_THEME) api.add_resource(Theme, "/api/v1/" + API_THEME + "/") +""" -#--------------------------------------------------------------------------------------- -class GroupList(Resource): - def __init__(self): - self.name = API_GROUP + +if __name__ == "__main__": + rest_config = config.get_rest_config() + debug.info("Start REST application: " + str(rest_config["host"]) + ":" + str(rest_config["port"])) + app.run(host=rest_config["host"], port=int(rest_config["port"])) + debug.info("END program"); - # example use: curl http://127.0.0.1:15080/api/v1/Group - def get(self): - return data_global_elements.get_interface(self.name).gets(), 200 - - """ - def post(self): - args = parser.parse_args() - todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1 - todo_id = 'todo%i' % todo_id - TODOS[todo_id] = {'task': args['task']} - return TODOS[todo_id], 201 - """ - -class Group(Resource): - def __init__(self): - self.name = API_GROUP - - # example use: curl http://127.0.0.1:15080/api/v1/Group/xxx - def get(self, id): - value = data_global_elements.get_interface(self.name).get(id) - if value != None: - return value, 200 - return "No data found", 404 - - def delete(self, id): - ret = data_global_elements.get_interface(self.name).delete(id) - if ret == True: - return '', 204 - return "No data found", 404 - """ - def put(self, id): - ret = data_global_elements.get_interface(self.name).put(id) - return task, 201 - """ - -api.add_resource(GroupList, "/api/v1/" + API_GROUP) -api.add_resource(Group, "/api/v1/" + API_GROUP + "/") - -#--------------------------------------------------------------------------------------- - -class SaisonList(Resource): - def __init__(self): - self.name = API_SAISON - - # example use: curl http://127.0.0.1:15080/api/v1/Saison - def get(self): - return data_global_elements.get_interface(self.name).gets(), 200 - - """ - def post(self): - args = parser.parse_args() - todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1 - todo_id = 'todo%i' % todo_id - TODOS[todo_id] = {'task': args['task']} - return TODOS[todo_id], 201 - """ - -class Saison(Resource): - def __init__(self): - self.name = API_SAISON - - # example use: curl http://127.0.0.1:15080/api/v1/Saison/xxx - def get(self, id): - value = data_global_elements.get_interface(self.name).get(id) - if value != None: - return value, 200 - return "No data found", 404 - - def delete(self, id): - ret = data_global_elements.get_interface(self.name).delete(id) - if ret == True: - return '', 204 - return "No data found", 404 - """ - def put(self, id): - ret = data_global_elements.get_interface(self.name).put(id) - return task, 201 - """ - -api.add_resource(SaisonList, "/api/v1/" + API_SAISON) -api.add_resource(Saison, "/api/v1/" + API_SAISON + "/") - -#--------------------------------------------------------------------------------------- - -class VideoList(Resource): - def __init__(self): - self.name = API_VIDEO - - # example use: curl http://127.0.0.1:15080/api/v1/Video - def get(self): - return data_global_elements.get_interface(self.name).gets(), 200 - - """ - def post(self): - args = parser.parse_args() - todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1 - todo_id = 'todo%i' % todo_id - TODOS[todo_id] = {'task': args['task']} - return TODOS[todo_id], 201 - """ - -class Video(Resource): - def __init__(self): - self.name = API_VIDEO - - # example use: curl http://127.0.0.1:15080/api/v1/Video/xxx - def get(self, id): - value = data_global_elements.get_interface(self.name).get(id) - if value != None: - return value, 200 - return "No data found", 404 - - def delete(self, id): - ret = data_global_elements.get_interface(self.name).delete(id) - if ret == True: - return '', 204 - return "No data found", 404 - """ - def put(self, id): - ret = data_global_elements.get_interface(self.name).put(id) - return task, 201 - """ - -api.add_resource(VideoList, "/api/v1/" + API_VIDEO) -api.add_resource(Video, "/api/v1/" + API_VIDEO + "/") - - -rest_config = config.get_rest_config() - -debug.info("Start REST application: " + str(rest_config["host"]) + ":" + str(rest_config["port"])) - -app.run(debug=False, host=rest_config["host"], port=str(rest_config["port"])) - -debug.info("END program"); -sys.exit(0) + \ No newline at end of file