diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index 9864996..78f7ad8 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -943,6 +943,7 @@ components: OperationType: type: string enum: + - undefined - insert - update - delete diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index b462e39..749f1ab 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -1,5 +1,6 @@ from dataclasses import field, dataclass from marshmallow import Schema, fields, INCLUDE, ValidationError +from marshmallow.fields import Field from marshmallow_enum import EnumField from enum import IntEnum @@ -26,15 +27,32 @@ class Berth(Schema): deleted: bool class Operation(IntEnum): - UNDEFINED = 0 - INSERT = 1 - UPDATE = 2 - DELETE = 3 + undefined = 0 + insert = 1 + update = 2 + delete = 3 class ObjectType(IntEnum): - UNDEFINED = 0 - SHIPCALL = 1 - TIMES = 2 + undefined = 0 + shipcall = 1 + times = 2 + +class EvaluationType(IntEnum): + undefined = 0 + green = 1 + yellow = 2 + red = 3 + +class NotificationType(IntEnum): + undefined = 0 + email = 1 + push = 2 + +class ShipcallType(IntEnum): + undefined = 0 + arrival = 1 + departure = 2 + shifting = 3 @dataclass class History: @@ -53,8 +71,8 @@ class History: shipcall_id: int timestamp: datetime eta: datetime - type: EnumField(ObjectType) - operation: EnumField(Operation) + type: ObjectType + operation: Operation @classmethod def from_query_row(self, id, participant_id, shipcall_id, timestamp, eta, type, operation): return self(id, participant_id, shipcall_id, timestamp, eta, ObjectType(type), Operation(operation)) @@ -71,7 +89,7 @@ class Notification: id: int shipcall_id: int level: int - type: int + type: NotificationType message: str created: datetime modified: datetime @@ -103,7 +121,7 @@ class ShipcallSchema(Schema): id = fields.Int() ship_id = fields.Int() - type = fields.Int() + type = EnumField(ShipcallType, by_value=True, required=True) eta = fields.DateTime(Required = False, allow_none=True) voyage = 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} etd = fields.DateTime(Required = False, allow_none=True) @@ -124,7 +142,7 @@ class ShipcallSchema(Schema): anchored = fields.Bool(Required = False, allow_none=True) moored_lock = fields.Bool(Required = False, allow_none=True) canceled = fields.Bool(Required = False, allow_none=True) - evaluation = fields.Int(Required = False, allow_none=True) + evaluation = EnumField(EvaluationType, required=False, allow_none=True, by_value=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_notifications_sent = fields.Bool(Required = False, allow_none=True) @@ -142,6 +160,7 @@ class Participant_Assignment: participant_id: int type: int # a variant would be to use the IntFlag type (with appropriate serialization) + @dataclass class Shipcall: @@ -168,7 +187,7 @@ class Shipcall: anchored: bool moored_lock: bool canceled: bool - evaluation: int + evaluation: str evaluation_message: str evaluation_time: datetime evaluation_notifications_sent: bool