from dataclasses import field from marshmallow import Schema, fields, INCLUDE, ValidationError from marshmallow_dataclass import dataclass from typing import List import json import datetime def obj_dict(obj): if isinstance(obj, datetime.datetime): return obj.isoformat() return obj.__dict__ @dataclass class Berth(Schema): id: int name: str participant_id: int lock: bool created: datetime modified: datetime deleted: bool class Error(Schema): message = fields.String(required=True) class GetVerifyInlineResp(Schema): pass @dataclass class Notification(Schema): id: int times_id: int acknowledged: bool level: int type: int message: str created: datetime modified: datetime @dataclass class Participant(Schema): id: int name: str street: str postal_code: str city: str type: int flags: int created: datetime modified: datetime deleted: bool class ParticipantList(Participant): pass class ShipcallSchema(Schema): def __init__(self): super().__init__(unknown=None) pass id = fields.Int() ship_id = fields.Int() type = fields.Int() eta = fields.DateTime() voyage = fields.Str(Required = False, allow_none=True) etd = fields.DateTime(Required = False, allow_none=True) arrival_berth_id = fields.Int(Required = False, allow_none=True) departure_berth_id = fields.Int(Required = False, allow_none=True) tug_required = fields.Bool(Required = False, allow_none=True) pilot_required = fields.Bool(Required = False, allow_none=True) flags = fields.Int(Required = False, allow_none=True) pier_side = fields.Bool(Required = False, allow_none=True) bunkering = fields.Bool(Required = False, allow_none=True) replenishing_terminal = fields.Bool(Required = False, allow_none=True) replenishing_lock = fields.Bool(Required = False, allow_none=True) draft = fields.Float(Required = False, allow_none=True) tidal_window_from = fields.DateTime(Required = False, allow_none=True) tidal_window_to = fields.DateTime(Required = False, allow_none=True) rain_sensitive_cargo = fields.Bool(Required = False, allow_none=True) recommended_tugs = fields.Int(Required = False, allow_none=True) 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) participants = fields.List(fields.Int) created = fields.DateTime(Required = False, allow_none=True) modified = fields.DateTime(Required = False, allow_none=True) @dataclass class Shipcall: id: int ship_id: int type: str eta: datetime voyage: str etd: datetime arrival_berth_id: int departure_berth_id: int tug_required: bool pilot_required: bool flags: int pier_side: bool bunkering: bool replenishing_terminal: bool replenishing_lock: bool draft: float tidal_window_from: datetime tidal_window_to: datetime rain_sensitive_cargo: bool recommended_tugs: int anchored: bool moored_lock: bool canceled: bool created: datetime modified: datetime participants: List[int] = field(default_factory=list) class ShipcallId(Schema): pass # this is the way! class TimesSchema(Schema): def __init__(self): super().__init__(unknown=None) pass id = fields.Int(Required=False) eta_berth = fields.DateTime(Required = False, allow_none=True) eta_berth_fixed = fields.Bool(Required = False, allow_none=True) etd_berth = fields.DateTime(Required = False, allow_none=True) etd_berth_fixed = fields.Bool(Required = False, allow_none=True) lock_time = fields.DateTime(Required = False, allow_none=True) lock_time_fixed = fields.Bool(Required = False, allow_none=True) zone_entry = fields.DateTime(Required = False, allow_none=True) zone_entry_fixed = fields.Bool(Required = False, allow_none=True) operations_start = fields.DateTime(Required = False, allow_none=True) operations_end = fields.DateTime(Required = False, allow_none=True) remarks = fields.String(Required = False, allow_none=True) participant_id = fields.Int(Required = True) shipcall_id = fields.Int(Required = True) created = fields.DateTime(Required = False, allow_none=True) modified = fields.DateTime(Required = False, allow_none=True) # deserialize PUT object target class UserSchema(Schema): def __init__(self): super().__init__(unknown=None) pass id = fields.Int(required=True) first_name = fields.Str(required=False) last_name = fields.Str(required=False) user_phone = fields.Str(required=False) old_password = fields.Str(required=False) new_password = fields.Str(required=False) @dataclass class Times: id: int eta_berth: datetime eta_berth_fixed: bool etd_berth: datetime etd_berth_fixed: bool lock_time: datetime lock_time_fixed: bool zone_entry: datetime zone_entry_fixed: bool operations_start: datetime operations_end: datetime remarks: str participant_id: int shipcall_id: int created: datetime modified: datetime @dataclass class User: id: int participant_id: int first_name: str last_name: str user_name: str user_email: str user_phone: str password_hash: str api_key: str created: datetime modified: datetime @dataclass class Ship(Schema): id: int name: str imo: int callsign: str participant_id: int length: float width: float is_tug: bool bollard_pull: int eni: str created: datetime modified: datetime deleted: bool class TimesId(Schema): pass class BerthList(Berth): pass class NotificationList(Notification): pass class Shipcalls(Shipcall): pass class TimesList(Times): pass