added ship delete and fixed schema loading error for shipclass

This commit is contained in:
Daniel Schick 2023-12-27 08:10:26 +01:00
parent dd4ae7def8
commit 1ef74b51ba
3 changed files with 49 additions and 1 deletions

View File

@ -47,3 +47,18 @@ def PutShip():
return json.dumps("bad format"), 400
return impl.ships.PutShip(loadedModel)
@bp.route('/ships', methods=['delete'])
@auth_guard() # no restriction by role
def DeleteShip():
try:
content = request.get_json(force=True)
loadedModel = model.ShipSchema().load(data=content, many=False, partial=True, unknown=EXCLUDE)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("bad format"), 400
return impl.ships.DeleteShip(loadedModel)

View File

@ -124,3 +124,32 @@ def PutShip(schemaModel):
result = {}
result["message"] = "call failed"
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
def DeleteShip(options):
"""
:param options: A dictionary containing all the paramters for the Operations
options["id"]
"""
try:
pooledConnection = local_db.getPoolConnection()
commands = pydapper.using(pooledConnection)
affected_rows = commands.execute("UPDATE ship SET deleted = 1 WHERE id = ?id?", param={"id" : options["id"]})
pooledConnection.close()
if affected_rows == 1:
return json.dumps({"id" : options["id"]}), 200, {'Content-Type': 'application/json; charset=utf-8'}
result = {}
result["message"] = "no such record"
return json.dumps(result), 404, {'Content-Type': 'application/json; charset=utf-8'}
except Exception as ex:
logging.error(ex)
print(ex)
result = {}
result["message"] = "call failed"
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}

View File

@ -128,6 +128,8 @@ class ShipcallSchema(Schema):
canceled = fields.Bool(Required = False, allow_none=True)
evaluation = fields.Int(Required = False, allow_none=True)
evaluation_message = fields.Str(allow_none=True, metadata={'Required':False}) # Solving: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'Required': False}
evaluation_time = fields.DateTime(Required = False, allow_none=True)
evaluation_message_sent = fields.Bool(Required = False, allow_none=True)
participants = fields.List(fields.Nested(ParticipantAssignmentSchema))
created = fields.DateTime(Required = False, allow_none=True)
modified = fields.DateTime(Required = False, allow_none=True)
@ -140,7 +142,7 @@ class Participant_Assignment:
pass
participant_id: int
type: int
type: int # a variant would be to use the IntFlag type (with appropriate serialization)
@dataclass
class Shipcall:
@ -170,6 +172,8 @@ class Shipcall:
canceled: bool
evaluation: int
evaluation_message: str
evaluation_time: datetime
evaluation_message_sent: bool
created: datetime
modified: datetime
participants: List[Participant_Assignment] = field(default_factory=list)