diff --git a/src/server/BreCal/impl/shipcalls.py b/src/server/BreCal/impl/shipcalls.py index 994d5ce..587e321 100644 --- a/src/server/BreCal/impl/shipcalls.py +++ b/src/server/BreCal/impl/shipcalls.py @@ -79,6 +79,11 @@ def PostShipcalls(schemaModel): commands.execute(query, schemaModel) new_id = commands.execute_scalar("select last_insert_id()") + # add participant assignments + pquery = "INSERT INTO shipcall_participant_map (shipcall_id, participant_id) VALUES (?shipcall_id?, ?participant_id?)" + for participant_id in schemaModel["participants"]: + commands.execute(pquery, param={"shipcall_id" : new_id, "participant_id" : participant_id}) + pooledConnection.close() return json.dumps({"id" : new_id}), 201, {'Content-Type': 'application/json; charset=utf-8'} @@ -116,9 +121,16 @@ def PutShipcalls(schemaModel): query += key + " = ?" + key + "? " query += "WHERE id = ?id?" - affected_rows = commands.execute(query, param=schemaModel) + pquery = "SELECT id, participant_id FROM shipcall_participant_map where shipcall_id = ?id?" + pdata = commands.query(pquery,param={"id" : schemaModel.id}) + + # loop across passed participant ids, creating entries for those not present in pdata + + # loop across existing pdata entries, deleting those not present in participant list + + pooledConnection.close() if affected_rows == 1: diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index 1000f4f..079954f 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -79,6 +79,7 @@ class ShipcallSchema(Schema): tidal_window_to = fields.DateTime() rain_sensitive_cargo = fields.Bool() recommended_tugs = fields.Int() + participants = fields.List(fields.Int) created = fields.DateTime() modified = fields.DateTime() diff --git a/src/server/requirements.txt b/src/server/requirements.txt index deb29e9..ca817e1 100644 --- a/src/server/requirements.txt +++ b/src/server/requirements.txt @@ -6,4 +6,8 @@ MarkupSafe==1.1.1 marshmallow==3.9.1 webargs==6.1.1 Werkzeug==1.0.1 -pydapper[mysql-connector-python] \ No newline at end of file +pydapper[mysql-connector-python] +marshmallow-dataclass +bcrypt +jwt +flask-jwt-extended \ No newline at end of file