From 794cd8efaf8b36504921f20b3f1df250cc09f58c Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 11 Aug 2023 15:07:42 +0200 Subject: [PATCH] added shipcall participant list to API GET call --- misc/BreCalApi.cs | 22 ++++++++++++++++++++-- misc/BreCalApi.yaml | 5 +++++ src/server/BreCal/connection_data.json | 6 +++--- src/server/BreCal/impl/shipcalls.py | 11 +++++++++++ src/server/BreCal/schemas/model.py | 4 +++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs index 7ca119f..7441519 100644 --- a/misc/BreCalApi.cs +++ b/misc/BreCalApi.cs @@ -1,7 +1,7 @@ //---------------------- // -// Generated REST API Client Code Generator v1.7.17.0 on 07.08.2023 15:13:59 +// Generated REST API Client Code Generator v1.7.17.0 on 11.08.2023 12:15:43 // Using the tool OpenAPI Generator v6.6.0 // //---------------------- @@ -6017,9 +6017,10 @@ namespace BreCalClient.misc.Model /// tidalWindowTo. /// rainSensitiveCargo. /// recommendedTugs. + /// participants. /// created. /// modified. - public Shipcall(int id = default(int), int shipId = default(int), TypeEnum type = default(TypeEnum), DateTime eta = default(DateTime), string voyage = default(string), DateTime? etd = default(DateTime?), int? arrivalBerthId = default(int?), int? departureBerthId = default(int?), bool? tugReguired = default(bool?), bool? pilotRequired = default(bool?), int? flags = default(int?), bool? pierSide = default(bool?), bool? bunkering = default(bool?), bool? replenishing = default(bool?), float? draft = default(float?), DateTime? tidalWindowFrom = default(DateTime?), DateTime? tidalWindowTo = default(DateTime?), bool? rainSensitiveCargo = default(bool?), int? recommendedTugs = default(int?), DateTime created = default(DateTime), DateTime? modified = default(DateTime?)) + public Shipcall(int id = default(int), int shipId = default(int), TypeEnum type = default(TypeEnum), DateTime eta = default(DateTime), string voyage = default(string), DateTime? etd = default(DateTime?), int? arrivalBerthId = default(int?), int? departureBerthId = default(int?), bool? tugReguired = default(bool?), bool? pilotRequired = default(bool?), int? flags = default(int?), bool? pierSide = default(bool?), bool? bunkering = default(bool?), bool? replenishing = default(bool?), float? draft = default(float?), DateTime? tidalWindowFrom = default(DateTime?), DateTime? tidalWindowTo = default(DateTime?), bool? rainSensitiveCargo = default(bool?), int? recommendedTugs = default(int?), List participants = default(List), DateTime created = default(DateTime), DateTime? modified = default(DateTime?)) { this.Id = id; this.ShipId = shipId; @@ -6050,6 +6051,7 @@ namespace BreCalClient.misc.Model this.TidalWindowTo = tidalWindowTo; this.RainSensitiveCargo = rainSensitiveCargo; this.RecommendedTugs = recommendedTugs; + this.Participants = participants; this.Created = created; this.Modified = modified; } @@ -6145,6 +6147,11 @@ namespace BreCalClient.misc.Model [DataMember(Name = "recommended_tugs", EmitDefaultValue = true)] public int? RecommendedTugs { get; set; } /// + /// Gets or Sets Participants + /// + [DataMember(Name = "participants", EmitDefaultValue = true)] + public List Participants { get; set; } + /// /// Gets or Sets Created /// [DataMember(Name = "created", EmitDefaultValue = true)] @@ -6181,6 +6188,7 @@ namespace BreCalClient.misc.Model sb.Append(" TidalWindowTo: ").Append(TidalWindowTo).Append("\n"); sb.Append(" RainSensitiveCargo: ").Append(RainSensitiveCargo).Append("\n"); sb.Append(" RecommendedTugs: ").Append(RecommendedTugs).Append("\n"); + sb.Append(" Participants: ").Append(Participants).Append("\n"); sb.Append(" Created: ").Append(Created).Append("\n"); sb.Append(" Modified: ").Append(Modified).Append("\n"); sb.Append("}\n"); @@ -6307,6 +6315,12 @@ namespace BreCalClient.misc.Model (this.RecommendedTugs != null && this.RecommendedTugs.Equals(input.RecommendedTugs)) ) && + ( + this.Participants == input.Participants || + this.Participants != null && + input.Participants != null && + this.Participants.SequenceEqual(input.Participants) + ) && ( this.Created == input.Created || (this.Created != null && @@ -6394,6 +6408,10 @@ namespace BreCalClient.misc.Model { hashCode = (hashCode * 59) + this.RecommendedTugs.GetHashCode(); } + if (this.Participants != null) + { + hashCode = (hashCode * 59) + this.Participants.GetHashCode(); + } if (this.Created != null) { hashCode = (hashCode * 59) + this.Created.GetHashCode(); diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index 0ac733a..432436f 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -375,6 +375,11 @@ components: recommended_tugs: type: integer nullable: true + participants: + type: array + items: + type: integer + example: [1, 5, 7] created: type: string format: date-time diff --git a/src/server/BreCal/connection_data.json b/src/server/BreCal/connection_data.json index 8feca32..16b58c0 100644 --- a/src/server/BreCal/connection_data.json +++ b/src/server/BreCal/connection_data.json @@ -1,8 +1,8 @@ { -"host" : "lager", -"port" : 3306, +"host" : "localhost", +"port" : 33306, "user" : "ds", -"password" : "HalloWach23", +"password" : "HalloWach_2323XXL!!", "pool_name" : "brecal_pool", "pool_size" : 20, "database" : "bremen_calling", diff --git a/src/server/BreCal/impl/shipcalls.py b/src/server/BreCal/impl/shipcalls.py index 03c13b3..994d5ce 100644 --- a/src/server/BreCal/impl/shipcalls.py +++ b/src/server/BreCal/impl/shipcalls.py @@ -21,6 +21,11 @@ def GetShipcalls(options): "flags, pier_side, bunkering, replenishing, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, " + "created, modified FROM shipcall WHERE eta IS NULL OR eta >= DATE(NOW() - INTERVAL 2 DAY) " + "ORDER BY eta", model=model.Shipcall) + for shipcall in data: + participant_query = "SELECT participant_id FROM shipcall_participant_map WHERE shipcall_id=?shipcall_id?"; + for record in commands.query(participant_query, model=dict, param={"shipcall_id" : shipcall.id}, buffered=False): + shipcall.participants.append(record["participant_id"]) + pooledConnection.close() except Exception as ex: @@ -52,6 +57,8 @@ def PostShipcalls(schemaModel): for key in schemaModel.keys(): if key == "id": continue + if key == "participants": + continue if isNotFirst: query += "," isNotFirst = True @@ -61,6 +68,8 @@ def PostShipcalls(schemaModel): for key in schemaModel.keys(): if key == "id": continue + if key == "participants": + continue if isNotFirst: query += "," isNotFirst = True @@ -99,6 +108,8 @@ def PutShipcalls(schemaModel): for key in schemaModel.keys(): if key == "id": continue + if key == "participants": + continue if isNotFirst: query += ", " isNotFirst = True diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index 505cac6..1000f4f 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -1,5 +1,7 @@ +from dataclasses import field from marshmallow import Schema, fields, INCLUDE, ValidationError from marshmallow_dataclass import dataclass +from typing import List import json import datetime @@ -104,7 +106,7 @@ class Shipcall: recommended_tugs: int created: datetime modified: datetime - + participants: List[int] = field(default_factory=list) class ShipcallId(Schema): pass