Created sensible notification messages without replicating data
This commit is contained in:
parent
607cb4fc7d
commit
fb3b0fced5
@ -136,7 +136,7 @@ def PostShipcalls(schemaModel):
|
|||||||
new_id = commands.execute_scalar("select last_insert_id()")
|
new_id = commands.execute_scalar("select last_insert_id()")
|
||||||
|
|
||||||
shipdata = get_ship_data_for_id(schemaModel["ship_id"])
|
shipdata = get_ship_data_for_id(schemaModel["ship_id"])
|
||||||
message = shipdata['name']
|
message = "The participant has been assigned to the shipcall."
|
||||||
if "type_value" in schemaModel:
|
if "type_value" in schemaModel:
|
||||||
match schemaModel["type_value"]:
|
match schemaModel["type_value"]:
|
||||||
case 1:
|
case 1:
|
||||||
@ -242,20 +242,6 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
query = "UPDATE shipcall SET " + ", ".join(update_clauses) + " WHERE id = ?id?"
|
query = "UPDATE shipcall SET " + ", ".join(update_clauses) + " WHERE id = ?id?"
|
||||||
commands.execute(query, param=schemaModel)
|
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"]
|
|
||||||
|
|
||||||
shipdata = get_ship_data_for_id(ship_id_value)
|
|
||||||
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 is not None:
|
|
||||||
match type_value:
|
|
||||||
case 1:
|
|
||||||
message += " [ARRIVAL]"
|
|
||||||
case 2:
|
|
||||||
message += " [DEPARTURE]"
|
|
||||||
case 3:
|
|
||||||
message += " [SHIFTING]"
|
|
||||||
|
|
||||||
# pquery = SQLQuery.get_shipcall_participant_map_by_shipcall_id()
|
# pquery = SQLQuery.get_shipcall_participant_map_by_shipcall_id()
|
||||||
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
|
||||||
@ -274,6 +260,7 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
found_participant = True
|
found_participant = True
|
||||||
break
|
break
|
||||||
if not found_participant:
|
if not found_participant:
|
||||||
|
message = "The participant has been assigned to the shipcall."
|
||||||
# nquery = SQLQuery.get_shipcall_post_update_shipcall_participant_map()
|
# nquery = SQLQuery.get_shipcall_post_update_shipcall_participant_map()
|
||||||
spquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
|
spquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id, type) VALUES (?shipcall_id?, ?participant_id?, ?type?)"
|
||||||
commands.execute(spquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
|
commands.execute(spquery, param={"shipcall_id" : schemaModel["id"], "participant_id" : participant_assignment["participant_id"], "type" : participant_assignment["type"]})
|
||||||
@ -307,6 +294,7 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
commands.execute(nquery, param={"nid" : existing_notification["id"]})
|
commands.execute(nquery, param={"nid" : existing_notification["id"]})
|
||||||
else:
|
else:
|
||||||
# create un-assignment notification
|
# create un-assignment notification
|
||||||
|
message = "The participant has been unassigned from the shipcall."
|
||||||
nquery = "INSERT INTO notification (shipcall_id, participant_id, level, type, message) VALUES (?shipcall_id?, ?participant_id?, 0, 5, ?message?)"
|
nquery = "INSERT INTO notification (shipcall_id, participant_id, level, type, message) VALUES (?shipcall_id?, ?participant_id?, 0, 5, ?message?)"
|
||||||
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
|
||||||
@ -314,6 +302,7 @@ def PutShipcalls(schemaModel, original_payload=None):
|
|||||||
canceled_value = schemaModel.get("canceled")
|
canceled_value = schemaModel.get("canceled")
|
||||||
if canceled_value is not None:
|
if canceled_value is not None:
|
||||||
if canceled_value and not was_canceled:
|
if canceled_value and not was_canceled:
|
||||||
|
message = "The shipcall has been 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"]:
|
||||||
|
|||||||
@ -314,7 +314,8 @@ def eval_next_24_hrs():
|
|||||||
found_notification = True
|
found_notification = True
|
||||||
break
|
break
|
||||||
if not found_notification:
|
if not found_notification:
|
||||||
commands.execute(nquery, param={"shipcall_id":shipcall["id"], "participant_id": participant["participant_id"], "message":shipcall["name"]})
|
message = "The shipcall is scheduled to arrive/depart within the next 24 hours."
|
||||||
|
commands.execute(nquery, param={"shipcall_id":shipcall["id"], "participant_id": participant["participant_id"], "message":message})
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user