[DEV] update checker
This commit is contained in:
parent
1e90972c04
commit
ab31104056
@ -53,16 +53,39 @@ def add(_app, _name_api):
|
|||||||
return response.json(data_global_elements.get_interface(_name_api).gets())
|
return response.json(data_global_elements.get_interface(_name_api).gets())
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class DataModelBdd:
|
dataModelBdd = [
|
||||||
id = int
|
{
|
||||||
size = int
|
"name": "id",
|
||||||
sha512 = str
|
"type": "int",
|
||||||
mime_type = str
|
"modifiable": False,
|
||||||
original_name = [str, type(None)]
|
"can_be_null": False
|
||||||
# creating time
|
},
|
||||||
create_date = str
|
{
|
||||||
|
"name": "size",
|
||||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
"type": "int",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "sha512",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mime_type",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "original_name",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
]
|
||||||
|
data_global_elements.get_interface(_name_api).set_data_model(dataModelBdd)
|
||||||
|
|
||||||
|
|
||||||
@elem_blueprint.get('/' + _name_api + '/exist/<sha512:string>', strict_slashes=True)
|
@elem_blueprint.get('/' + _name_api + '/exist/<sha512:string>', strict_slashes=True)
|
||||||
|
@ -34,13 +34,33 @@ import data_global_elements
|
|||||||
def add(_app, _name_api):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
class DataModelBdd:
|
dataModelBdd = [
|
||||||
id = int
|
{
|
||||||
name = str
|
"name": "id",
|
||||||
description = [str, type(None)]
|
"type": "int",
|
||||||
covers = [[], type(None)]
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "description",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cover",
|
||||||
|
"type": "list",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
]
|
||||||
|
data_global_elements.get_interface(_name_api).set_data_model(dataModelBdd)
|
||||||
|
|
||||||
class DataModel:
|
class DataModel:
|
||||||
name = str
|
name = str
|
||||||
|
@ -33,14 +33,39 @@ import data_global_elements
|
|||||||
def add(_app, _name_api):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
class DataModelBdd:
|
dataModelBdd = [
|
||||||
id = int
|
{
|
||||||
number = int
|
"name": "id",
|
||||||
description = [str, type(None)]
|
"type": "int",
|
||||||
group_id = int
|
"modifiable": False,
|
||||||
covers = [[], type(None)]
|
"can_be_null": False
|
||||||
|
},
|
||||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
{
|
||||||
|
"name": "number",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "description",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "group_id",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cover",
|
||||||
|
"type": "list",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
]
|
||||||
|
data_global_elements.get_interface(_name_api).set_data_model(dataModelBdd)
|
||||||
|
|
||||||
class DataModel:
|
class DataModel:
|
||||||
number = int
|
number = int
|
||||||
|
@ -34,12 +34,33 @@ import data_global_elements
|
|||||||
def add(_app, _name_api):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
class DataModelBdd:
|
dataModelBdd = [
|
||||||
id = int
|
{
|
||||||
name = str
|
"name": "id",
|
||||||
description = str
|
"type": "int",
|
||||||
|
"modifiable": False,
|
||||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "description",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cover",
|
||||||
|
"type": "list",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
]
|
||||||
|
data_global_elements.get_interface(_name_api).set_data_model(dataModelBdd)
|
||||||
|
|
||||||
class DataModel:
|
class DataModel:
|
||||||
name = str
|
name = str
|
||||||
|
@ -32,13 +32,33 @@ import data_global_elements
|
|||||||
def add(_app, _name_api):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
class DataModelBdd:
|
dataModelBdd = [
|
||||||
id = int
|
{
|
||||||
name = str
|
"name": "id",
|
||||||
description = str
|
"type": "int",
|
||||||
covers = [[], type(None)]
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "description",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cover",
|
||||||
|
"type": "list",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": False
|
||||||
|
},
|
||||||
|
]
|
||||||
|
data_global_elements.get_interface(_name_api).set_data_model(dataModelBdd)
|
||||||
|
|
||||||
class DataModel:
|
class DataModel:
|
||||||
name = str
|
name = str
|
||||||
|
@ -73,26 +73,81 @@ def generate_name(_value):
|
|||||||
def add(_app, _name_api):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
class DataModelBdd:
|
dataModelBdd = [
|
||||||
id = int
|
{
|
||||||
data_id = int
|
"name": "id",
|
||||||
type_id = int
|
"type": "int",
|
||||||
saison_id = [int, type(None)]
|
"modifiable": False,
|
||||||
episode = [int, type(None)]
|
"can_be_null": False
|
||||||
univers_id = [int, type(None)]
|
},
|
||||||
group_id = [int, type(None)]
|
{
|
||||||
name = str
|
"name": "data_id",
|
||||||
description = [str, type(None)]
|
"type": "int",
|
||||||
# creating time
|
"modifiable": True,
|
||||||
create_date = str
|
"can_be_null": False
|
||||||
# date of the video
|
},
|
||||||
date = [int, type(None)]
|
{
|
||||||
# number of second
|
"name": "type_id",
|
||||||
time = [int, type(None)]
|
"type": "int",
|
||||||
# number of second
|
"modifiable": True,
|
||||||
covers = [[], type(None)]
|
"can_be_null": True
|
||||||
|
},
|
||||||
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
|
{
|
||||||
|
"name": "saison_id",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "episode",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "univers_id",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "group_id",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "description",
|
||||||
|
"type": "str",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "date",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "time",
|
||||||
|
"type": "int",
|
||||||
|
"modifiable": True,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cover",
|
||||||
|
"type": "list",
|
||||||
|
"modifiable": False,
|
||||||
|
"can_be_null": True
|
||||||
|
},
|
||||||
|
]
|
||||||
|
data_global_elements.get_interface(_name_api).set_data_model(dataModelBdd)
|
||||||
|
|
||||||
class DataModel:
|
class DataModel:
|
||||||
type_id = int
|
type_id = int
|
||||||
|
@ -45,7 +45,7 @@ app = Sanic(__name__)
|
|||||||
spf = SanicPluginsFramework(app)
|
spf = SanicPluginsFramework(app)
|
||||||
spf.register_plugin(cors, automatic_options=True)
|
spf.register_plugin(cors, automatic_options=True)
|
||||||
|
|
||||||
app.config['API_VERSION'] = '1.0.0'
|
app.config['API_VERSION'] = '2.0.0'
|
||||||
app.config['API_TITLE'] = 'Rest personal video API'
|
app.config['API_TITLE'] = 'Rest personal video API'
|
||||||
app.config['API_DESCRIPTION'] = 'Simple API for the Video broker.'
|
app.config['API_DESCRIPTION'] = 'Simple API for the Video broker.'
|
||||||
app.config['API_CONTACT_EMAIL'] = "yui.heero@gmail.com"
|
app.config['API_CONTACT_EMAIL'] = "yui.heero@gmail.com"
|
||||||
|
@ -18,6 +18,47 @@ from psycopg2.extras import RealDictCursor
|
|||||||
|
|
||||||
import db
|
import db
|
||||||
|
|
||||||
|
def is_str(s, authorise):
|
||||||
|
if s == None:
|
||||||
|
if authorise == True:
|
||||||
|
return True
|
||||||
|
return False;
|
||||||
|
if type(s) == str:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def is_boolean(s, authorise):
|
||||||
|
if s == None:
|
||||||
|
if authorise == True:
|
||||||
|
return True
|
||||||
|
return False;
|
||||||
|
if s == True or s == False:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def is_int(s, authorise):
|
||||||
|
if s == None:
|
||||||
|
if authorise == True:
|
||||||
|
return True
|
||||||
|
return False;
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
return False
|
||||||
|
|
||||||
|
def is_float(s, authorise):
|
||||||
|
if s == None:
|
||||||
|
if authorise == True:
|
||||||
|
return True
|
||||||
|
return False;
|
||||||
|
try:
|
||||||
|
float(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
return False
|
||||||
##
|
##
|
||||||
## @breif Generic interface to access to the BDD (no BDD, direct file IO)
|
## @breif Generic interface to access to the BDD (no BDD, direct file IO)
|
||||||
##
|
##
|
||||||
@ -189,6 +230,34 @@ class DataInterface():
|
|||||||
self.mark_to_store();
|
self.mark_to_store();
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def is_value_modifiable_and_good_type(self, _key, _value):
|
||||||
|
if self.model == None:
|
||||||
|
return True
|
||||||
|
for elem in self.model:
|
||||||
|
if _key == elem["name"]:
|
||||||
|
if elem["modifiable"] == False:
|
||||||
|
debug.warning("Try to set an input '" + str(_key) + "' but the element is not modifiable ... ");
|
||||||
|
raise ServerError("FORBIDDEN Try to set an input '" + str(_key) + "' but the element is not modifiable", status_code=403)
|
||||||
|
if elem["type"] == "str":
|
||||||
|
if is_str(_value, elem["can_be_null"]) == True:
|
||||||
|
return True
|
||||||
|
elif if elem["type"] == "int":
|
||||||
|
if is_int(_value, elem["can_be_null"]) == True:
|
||||||
|
return True
|
||||||
|
elif if elem["type"] == "float":
|
||||||
|
if is_float(_value, elem["can_be_null"]) == True:
|
||||||
|
return True
|
||||||
|
elif if elem["type"] == "boolean":
|
||||||
|
if is_boolean(_value, elem["can_be_null"]) == True:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return True;
|
||||||
|
debug.warning("get element type == '" + str(type(_value)) + "' but request " + str(elem["type"]));
|
||||||
|
raise ServerError("FORBIDDEN get element type == '" + str(type(_value)) + "' but request " + str(elem["type"]), status_code=403)
|
||||||
|
# The key does not exist ...
|
||||||
|
debug.warning("The KEY: '" + str(_key) + "' Is not in the list of availlable keys");
|
||||||
|
raise ServerError("FORBIDDEN The KEY: '" + str(_key) + "' Is not in the list of availlable keys", status_code=403)
|
||||||
|
|
||||||
def put(self, _id, _value):
|
def put(self, _id, _value):
|
||||||
debug.info("put in " + self.name + ": " + str(_id))
|
debug.info("put in " + self.name + ": " + str(_id))
|
||||||
cursor = self.connection.cursor()
|
cursor = self.connection.cursor()
|
||||||
@ -198,6 +267,8 @@ class DataInterface():
|
|||||||
for elem in _value.keys():
|
for elem in _value.keys():
|
||||||
if elem == "id":
|
if elem == "id":
|
||||||
continue
|
continue
|
||||||
|
if self.is_value_modifiable_and_good_type(elem, _value[elem]) == False:
|
||||||
|
return;
|
||||||
if first == True:
|
if first == True:
|
||||||
first = False
|
first = False
|
||||||
else:
|
else:
|
||||||
@ -209,35 +280,14 @@ class DataInterface():
|
|||||||
debug.info("Request executed : '" + request + "'")
|
debug.info("Request executed : '" + request + "'")
|
||||||
cursor.execute(request, list_data)
|
cursor.execute(request, list_data)
|
||||||
self.mark_to_store();
|
self.mark_to_store();
|
||||||
|
|
||||||
"""
|
|
||||||
debug.info("put " + self.name + ": " + str(_id))
|
|
||||||
id_in_bdd = self.get_table_index(_id)
|
|
||||||
if id_in_bdd == None:
|
|
||||||
return False
|
|
||||||
# todo: check the model before update ...
|
|
||||||
debug.warning("update element: " + str(_id))
|
|
||||||
value_bdd = copy.deepcopy(self.bdd[id_in_bdd]);
|
|
||||||
for elem in _value.keys():
|
|
||||||
debug.warning(" [" + elem + "] " + str(value_bdd[elem]) + " ==> " + str(_value[elem]))
|
|
||||||
value_bdd[elem] = _value[elem]
|
|
||||||
if self.check_with_model(value_bdd) == False:
|
|
||||||
raise ServerError("FORBIDDEN Corelation with BDD error", status_code=403)
|
|
||||||
self.bdd[id_in_bdd] = value_bdd
|
|
||||||
debug.warning(" ==> " + str(self.bdd[id_in_bdd]))
|
|
||||||
self.mark_to_store()
|
|
||||||
"""
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def post(self, _value):
|
def post(self, _value):
|
||||||
"""
|
|
||||||
debug.info("post " + self.name)
|
debug.info("post " + self.name)
|
||||||
_value["id"] = self.last_id
|
"""
|
||||||
self.last_id += 1
|
|
||||||
if self.check_with_model(_value) == False:
|
if self.check_with_model(_value) == False:
|
||||||
raise ServerError("Corelation with BDD error", status_code=404)
|
raise ServerError("Corelation with BDD error", status_code=404)
|
||||||
self.bdd.append(_value)
|
self.bdd.append(_value)
|
||||||
self.mark_to_store()
|
|
||||||
"""
|
"""
|
||||||
self.mark_to_store();
|
self.mark_to_store();
|
||||||
return _value
|
return _value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user