[DEV] update checker

This commit is contained in:
Edouard DUPIN 2020-02-21 22:54:58 +01:00
parent 1e90972c04
commit ab31104056
8 changed files with 295 additions and 81 deletions

View File

@ -53,16 +53,39 @@ def add(_app, _name_api):
return response.json(data_global_elements.get_interface(_name_api).gets())
"""
class DataModelBdd:
id = int
size = int
sha512 = str
mime_type = str
original_name = [str, type(None)]
# creating time
create_date = str
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
dataModelBdd = [
{
"name": "id",
"type": "int",
"modifiable": False,
"can_be_null": False
},
{
"name": "size",
"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)

View File

@ -34,13 +34,33 @@ import data_global_elements
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
class DataModelBdd:
id = int
name = str
description = [str, type(None)]
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
dataModelBdd = [
{
"name": "id",
"type": "int",
"modifiable": False,
"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:
name = str

View File

@ -33,14 +33,39 @@ import data_global_elements
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
class DataModelBdd:
id = int
number = int
description = [str, type(None)]
group_id = int
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
dataModelBdd = [
{
"name": "id",
"type": "int",
"modifiable": False,
"can_be_null": False
},
{
"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:
number = int

View File

@ -34,12 +34,33 @@ import data_global_elements
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
class DataModelBdd:
id = int
name = str
description = str
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
dataModelBdd = [
{
"name": "id",
"type": "int",
"modifiable": False,
"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:
name = str

View File

@ -32,13 +32,33 @@ import data_global_elements
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
class DataModelBdd:
id = int
name = str
description = str
covers = [[], type(None)]
data_global_elements.get_interface(_name_api).set_data_model(DataModelBdd)
dataModelBdd = [
{
"name": "id",
"type": "int",
"modifiable": False,
"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:
name = str

View File

@ -73,26 +73,81 @@ def generate_name(_value):
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
class DataModelBdd:
id = int
data_id = int
type_id = int
saison_id = [int, type(None)]
episode = [int, type(None)]
univers_id = [int, type(None)]
group_id = [int, type(None)]
name = str
description = [str, type(None)]
# creating time
create_date = str
# date of the video
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)
dataModelBdd = [
{
"name": "id",
"type": "int",
"modifiable": False,
"can_be_null": False
},
{
"name": "data_id",
"type": "int",
"modifiable": True,
"can_be_null": False
},
{
"name": "type_id",
"type": "int",
"modifiable": True,
"can_be_null": True
},
{
"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:
type_id = int

View File

@ -45,7 +45,7 @@ app = Sanic(__name__)
spf = SanicPluginsFramework(app)
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_DESCRIPTION'] = 'Simple API for the Video broker.'
app.config['API_CONTACT_EMAIL'] = "yui.heero@gmail.com"

View File

@ -18,6 +18,47 @@ from psycopg2.extras import RealDictCursor
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)
##
@ -189,6 +230,34 @@ class DataInterface():
self.mark_to_store();
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):
debug.info("put in " + self.name + ": " + str(_id))
cursor = self.connection.cursor()
@ -198,6 +267,8 @@ class DataInterface():
for elem in _value.keys():
if elem == "id":
continue
if self.is_value_modifiable_and_good_type(elem, _value[elem]) == False:
return;
if first == True:
first = False
else:
@ -209,35 +280,14 @@ class DataInterface():
debug.info("Request executed : '" + request + "'")
cursor.execute(request, list_data)
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
def post(self, _value):
"""
debug.info("post " + self.name)
_value["id"] = self.last_id
self.last_id += 1
"""
if self.check_with_model(_value) == False:
raise ServerError("Corelation with BDD error", status_code=404)
self.bdd.append(_value)
self.mark_to_store()
"""
self.mark_to_store();
return _value