[DEV] add api for cover ... not tested ...

This commit is contained in:
Edouard DUPIN 2020-01-11 21:25:05 +01:00
parent 132d683489
commit 5565a2ddfb
6 changed files with 121 additions and 0 deletions

View File

@ -35,6 +35,7 @@ def add(_app, _name_api):
class DataModelBdd:
id = int
name = str
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
@ -126,4 +127,27 @@ def add(_app, _name_api):
return response.json({})
raise ServerError("No data found", status_code=404)
@elem_blueprint.post('/' + _name_api + "/<id:int>/add_cover", strict_slashes=True)
@doc.summary("Add cover on video")
@doc.description("Add a cover data ID to the video.")
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful added')
async def create(request, id):
for type_key in ["data_id"]:
if type_key not in request.json.keys():
raise ServerError("Bad Request: Missing Key '" + type_key + "'", status_code=400)
# TODO: check if it is a number...
value = data_global_elements.get_interface(_name_api).get(id)
if value == None:
raise ServerError("No data found", status_code=404)
if "covers" not in value.keys():
value["covers"] = [];
for elem in value["covers"]:
if request.json["data_id"] == elem:
return response.json(elem)
value["covers"].append(request.json["data_id"]);
data_global_elements.get_interface(_name_api).set(id, value)
return response.json(elem)
_app.blueprint(elem_blueprint)

View File

@ -36,6 +36,7 @@ def add(_app, _name_api):
id = int
number = int
group_id = int
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
@ -109,4 +110,27 @@ def add(_app, _name_api):
return response.json({})
raise ServerError("No data found", status_code=404)
@elem_blueprint.post('/' + _name_api + "/<id:int>/add_cover", strict_slashes=True)
@doc.summary("Add cover on video")
@doc.description("Add a cover data ID to the video.")
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful added')
async def create(request, id):
for type_key in ["data_id"]:
if type_key not in request.json.keys():
raise ServerError("Bad Request: Missing Key '" + type_key + "'", status_code=400)
# TODO: check if it is a number...
value = data_global_elements.get_interface(_name_api).get(id)
if value == None:
raise ServerError("No data found", status_code=404)
if "covers" not in value.keys():
value["covers"] = [];
for elem in value["covers"]:
if request.json["data_id"] == elem:
return response.json(elem)
value["covers"].append(request.json["data_id"]);
data_global_elements.get_interface(_name_api).set(id, value)
return response.json(elem)
_app.blueprint(elem_blueprint)

View File

@ -36,6 +36,7 @@ def add(_app, _name_api):
id = int
name = str
description = str
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
@ -119,4 +120,27 @@ def add(_app, _name_api):
list_values = data_global_elements.get_interface(data_global_elements.API_VIDEO).gets_where(select=[["==", "univers_id", id], ["!=", "group_id", None], ["==", "univers_id", None]], filter=["group_id"])
return response.json(list_values)
@elem_blueprint.post('/' + _name_api + "/<id:int>/add_cover", strict_slashes=True)
@doc.summary("Add cover on video")
@doc.description("Add a cover data ID to the video.")
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful added')
async def create(request, id):
for type_key in ["data_id"]:
if type_key not in request.json.keys():
raise ServerError("Bad Request: Missing Key '" + type_key + "'", status_code=400)
# TODO: check if it is a number...
value = data_global_elements.get_interface(_name_api).get(id)
if value == None:
raise ServerError("No data found", status_code=404)
if "covers" not in value.keys():
value["covers"] = [];
for elem in value["covers"]:
if request.json["data_id"] == elem:
return response.json(elem)
value["covers"].append(request.json["data_id"]);
data_global_elements.get_interface(_name_api).set(id, value)
return response.json(elem)
_app.blueprint(elem_blueprint)

View File

@ -84,6 +84,8 @@ def add(_app, _name_api):
date = [int, type(None)]
# number of second
time = [int, type(None)]
# number of second
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
@ -163,4 +165,27 @@ def add(_app, _name_api):
return response.json({})
raise ServerError("No data found", status_code=404)
@elem_blueprint.post('/' + _name_api + "/<id:int>/add_cover", strict_slashes=True)
@doc.summary("Add cover on video")
@doc.description("Add a cover data ID to the video.")
@doc.consumes(DataModel, location='body')#, required=True)
@doc.response_success(status=201, description='If successful added')
async def create(request, id):
for type_key in ["data_id"]:
if type_key not in request.json.keys():
raise ServerError("Bad Request: Missing Key '" + type_key + "'", status_code=400)
# TODO: check if it is a number...
value = data_global_elements.get_interface(_name_api).get(id)
if value == None:
raise ServerError("No data found", status_code=404)
if "covers" not in value.keys():
value["covers"] = [];
for elem in value["covers"]:
if request.json["data_id"] == elem:
return response.json(elem)
value["covers"].append(request.json["data_id"]);
data_global_elements.get_interface(_name_api).set(id, value)
return response.json(elem)
_app.blueprint(elem_blueprint)

View File

@ -142,6 +142,17 @@ class DataInterface():
debug.warning("not found element: " + str(len(self.bdd)))
return None
def set(self, _id, _value):
if type(_id) != int:
debug.warning("get wrong input type...")
for elem in self.bdd:
if 'id' in elem.keys() \
and elem["id"] == _id:
elem = _value
return elem
debug.warning("not found element: " + str(len(self.bdd)))
return None
def delete(self, _id):
debug.info("delete " + self.name + ": " + str(_id))
id_in_bdd = self.get_table_index(_id)

View File

@ -155,6 +155,19 @@ def push_video_file(_path, _basic_key={}):
if file_name in ["cover_1.jpg","cover_1.png", "cover_1.till", "cover_1.bmp", "cover_1.tga"]:
# find a cover...
debug.warning("Not send cover Not managed ... : " + _path + " Not manage ...")
"""
result_group_data = requests.post(get_base_url() + "group/find", data=json.dumps({"name":_basic_key["series-name"]}, sort_keys=True, indent=4))
debug.info("Create group ??? *********** : " + str(result_group_data) + " " + result_group_data.text)
if result_group_data.status_code == 404:
result_group_data = requests.post(get_base_url() + "group", data=json.dumps({"name":_basic_key["series-name"]}, sort_keys=True, indent=4))
debug.info("yes we create new group *********** : " + str(result_group_data) + " " + result_group_data.text)
group_id = result_group_data.json()["id"]
result_group_data = requests.post(get_base_url() + "group", data=json.dumps({"name":_basic_key["series-name"]}, sort_keys=True, indent=4))
debug.info("yes we create new group *********** : " + str(result_group_data) + " " + result_group_data.text)
"""
"""
debug.info("Send cover for: " + _basic_key["series-name"] + " " + _basic_key["saison"]);
if _basic_key["series-name"] == "":