Compare commits
No commits in common. "60baf0229977b68f91a48321466d5acd62f05967" and "44dd6010d7729e8df3979172163c6a3aaa8ff567" have entirely different histories.
60baf02299
...
44dd6010d7
@ -89,7 +89,7 @@ def PutShipcalls():
|
|||||||
|
|
||||||
# validate the PUT shipcall data and the user's authority
|
# validate the PUT shipcall data and the user's authority
|
||||||
InputValidationShipcall.evaluate_put_data(user_data, loadedModel, content)
|
InputValidationShipcall.evaluate_put_data(user_data, loadedModel, content)
|
||||||
return impl.shipcalls.PutShipcalls(loadedModel, content)
|
return impl.shipcalls.PutShipcalls(loadedModel)
|
||||||
|
|
||||||
except ValidationError as ex:
|
except ValidationError as ex:
|
||||||
return create_validation_error_response(ex=ex, status_code=400)
|
return create_validation_error_response(ex=ex, status_code=400)
|
||||||
|
|||||||
@ -72,7 +72,7 @@ def PutTimes():
|
|||||||
|
|
||||||
# validate the request
|
# validate the request
|
||||||
InputValidationTimes.evaluate_put_data(user_data, loadedModel, content)
|
InputValidationTimes.evaluate_put_data(user_data, loadedModel, content)
|
||||||
return impl.times.PutTimes(loadedModel, content)
|
return impl.times.PutTimes(loadedModel)
|
||||||
|
|
||||||
except ValidationError as ex:
|
except ValidationError as ex:
|
||||||
return create_validation_error_response(ex=ex, status_code=400)
|
return create_validation_error_response(ex=ex, status_code=400)
|
||||||
|
|||||||
@ -185,7 +185,7 @@ def PostShipcalls(schemaModel):
|
|||||||
pooledConnection.close()
|
pooledConnection.close()
|
||||||
|
|
||||||
|
|
||||||
def PutShipcalls(schemaModel, original_payload=None):
|
def PutShipcalls(schemaModel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
:param schemaModel: The deserialized dict of the request
|
:param schemaModel: The deserialized dict of the request
|
||||||
@ -209,12 +209,10 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
|
|
||||||
was_canceled = theshipcall["canceled"]
|
was_canceled = theshipcall["canceled"]
|
||||||
|
|
||||||
provided_keys = set(original_payload.keys()) if isinstance(original_payload, dict) else None
|
# query = SQLQuery.get_shipcall_put(schemaModel)
|
||||||
|
query = "UPDATE shipcall SET "
|
||||||
update_clauses = []
|
isNotFirst = False
|
||||||
for key in schemaModel.keys():
|
for key in schemaModel.keys():
|
||||||
if provided_keys is not None and key not in provided_keys:
|
|
||||||
continue
|
|
||||||
param_key = key
|
param_key = key
|
||||||
if key == "id":
|
if key == "id":
|
||||||
continue
|
continue
|
||||||
@ -236,19 +234,19 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
param_key = "evaluation_value"
|
param_key = "evaluation_value"
|
||||||
if key == "evaluation_value":
|
if key == "evaluation_value":
|
||||||
continue
|
continue
|
||||||
update_clauses.append(f"{key} = ?{param_key}?")
|
if isNotFirst:
|
||||||
|
query += ", "
|
||||||
|
isNotFirst = True
|
||||||
|
query += key + " = ?" + param_key + "? "
|
||||||
|
|
||||||
if update_clauses:
|
query += "WHERE id = ?id?"
|
||||||
query = "UPDATE shipcall SET " + ", ".join(update_clauses) + " WHERE id = ?id?"
|
|
||||||
commands.execute(query, param=schemaModel)
|
|
||||||
|
|
||||||
ship_id_value = schemaModel.get("ship_id") if (provided_keys is None or "ship_id" in provided_keys) else theshipcall["ship_id"]
|
affected_rows = commands.execute(query, param=schemaModel)
|
||||||
|
|
||||||
shipdata = get_ship_data_for_id(ship_id_value)
|
shipdata = get_ship_data_for_id(schemaModel["ship_id"])
|
||||||
message = shipdata['name']
|
message = shipdata['name']
|
||||||
type_value = schemaModel.get("type_value") if (provided_keys is None or "type" in provided_keys) else theshipcall["type"]
|
if "type_value" in schemaModel:
|
||||||
if type_value is not None:
|
match schemaModel["type_value"]:
|
||||||
match type_value:
|
|
||||||
case 1:
|
case 1:
|
||||||
message += " [ARRIVAL]"
|
message += " [ARRIVAL]"
|
||||||
case 2:
|
case 2:
|
||||||
@ -260,9 +258,6 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
pquery = "SELECT id, participant_id, type FROM shipcall_participant_map where shipcall_id = ?id?"
|
pquery = "SELECT id, participant_id, type FROM shipcall_participant_map where shipcall_id = ?id?"
|
||||||
pdata = commands.query(pquery,param={"id" : schemaModel["id"]}) # existing list of assignments
|
pdata = commands.query(pquery,param={"id" : schemaModel["id"]}) # existing list of assignments
|
||||||
|
|
||||||
if schemaModel.get("participants") is None:
|
|
||||||
schemaModel["participants"] = []
|
|
||||||
|
|
||||||
# loop across passed participant ids, creating entries for those not present in pdata
|
# loop across passed participant ids, creating entries for those not present in pdata
|
||||||
|
|
||||||
existing_notifications = get_notification_for_shipcall_and_type(schemaModel["id"], 1) # type = 1 is assignment
|
existing_notifications = get_notification_for_shipcall_and_type(schemaModel["id"], 1) # type = 1 is assignment
|
||||||
@ -311,9 +306,8 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
commands.execute(nquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : elem["participant_id"], "message" : message})
|
commands.execute(nquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : elem["participant_id"], "message" : message})
|
||||||
break
|
break
|
||||||
|
|
||||||
canceled_value = schemaModel.get("canceled")
|
if schemaModel["canceled"] is not None:
|
||||||
if canceled_value is not None:
|
if schemaModel["canceled"] and not was_canceled:
|
||||||
if canceled_value and not was_canceled:
|
|
||||||
# create a canceled notification for all currently assigned participants
|
# create a canceled notification for all currently assigned participants
|
||||||
stornoNotificationQuery = "INSERT INTO notification (shipcall_id, participant_id, level, type, message) VALUES (?shipcall_id?, ?participant_id?, 0, 7, ?message?)"
|
stornoNotificationQuery = "INSERT INTO notification (shipcall_id, participant_id, level, type, message) VALUES (?shipcall_id?, ?participant_id?, 0, 7, ?message?)"
|
||||||
for participant_assignment in schemaModel["participants"]:
|
for participant_assignment in schemaModel["participants"]:
|
||||||
|
|||||||
@ -115,7 +115,7 @@ def PostTimes(schemaModel):
|
|||||||
pooledConnection.close()
|
pooledConnection.close()
|
||||||
|
|
||||||
|
|
||||||
def PutTimes(schemaModel, original_payload=None):
|
def PutTimes(schemaModel):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
:param schemaModel: The deserialized model of the record to be inserted
|
:param schemaModel: The deserialized model of the record to be inserted
|
||||||
@ -127,33 +127,24 @@ def PutTimes(schemaModel, original_payload=None):
|
|||||||
pooledConnection = local_db.getPoolConnection()
|
pooledConnection = local_db.getPoolConnection()
|
||||||
commands = pydapper.using(pooledConnection)
|
commands = pydapper.using(pooledConnection)
|
||||||
|
|
||||||
sentinel = object()
|
query = "UPDATE times SET "
|
||||||
existing_times = commands.query_single_or_default("SELECT * FROM times WHERE id = ?id?", sentinel, param={"id": schemaModel["id"]})
|
isNotFirst = False
|
||||||
if existing_times is sentinel:
|
|
||||||
return json.dumps("no such record"), 404, {'Content-Type': 'application/json; charset=utf-8'}
|
|
||||||
|
|
||||||
provided_keys = set(original_payload.keys()) if isinstance(original_payload, dict) else None
|
|
||||||
|
|
||||||
if "shipcall_id" not in schemaModel or (provided_keys is not None and "shipcall_id" not in provided_keys):
|
|
||||||
schemaModel["shipcall_id"] = existing_times["shipcall_id"]
|
|
||||||
|
|
||||||
schemaModel = {k:v.value if isinstance(v, (Enum, Flag)) else v for k,v in schemaModel.items()}
|
|
||||||
|
|
||||||
update_clauses = []
|
|
||||||
for key in schemaModel.keys():
|
for key in schemaModel.keys():
|
||||||
if provided_keys is not None and key not in provided_keys:
|
|
||||||
continue
|
|
||||||
if key == "id":
|
if key == "id":
|
||||||
continue
|
continue
|
||||||
if key == "created":
|
if key == "created":
|
||||||
continue
|
continue
|
||||||
if key == "modified":
|
if key == "modified":
|
||||||
continue
|
continue
|
||||||
update_clauses.append(f"{key} = ?{key}?")
|
if isNotFirst:
|
||||||
|
query += ", "
|
||||||
|
isNotFirst = True
|
||||||
|
query += key + " = ?" + key + "? "
|
||||||
|
|
||||||
if update_clauses:
|
query += "WHERE id = ?id?"
|
||||||
query = "UPDATE times SET " + ", ".join(update_clauses) + " WHERE id = ?id?"
|
|
||||||
commands.execute(query, param=schemaModel)
|
schemaModel = {k:v.value if isinstance(v, (Enum, Flag)) else v for k,v in schemaModel.items()}
|
||||||
|
affected_rows = commands.execute(query, param=schemaModel)
|
||||||
|
|
||||||
# apply 'Traffic Light' evaluation to obtain 'GREEN', 'YELLOW' or 'RED' evaluation state. The function internally updates the mysql database 'shipcall'
|
# apply 'Traffic Light' evaluation to obtain 'GREEN', 'YELLOW' or 'RED' evaluation state. The function internally updates the mysql database 'shipcall'
|
||||||
evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=schemaModel["shipcall_id"]) # every times data object refers to the 'shipcall_id'
|
evaluate_shipcall_state(mysql_connector_instance=pooledConnection, shipcall_id=schemaModel["shipcall_id"]) # every times data object refers to the 'shipcall_id'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user