From 6d4c36d07b37a62a32d2af1e9537cb80e88e6961 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 13 Jul 2023 21:32:28 +0200 Subject: [PATCH] Client work in Progress.. --- misc/BreCalApi.cs | 312 +++++++++++++++++++++-- misc/BreCalApi.yaml | 52 +++- src/BreCalClient/MainWindow.xaml | 43 +++- src/BreCalClient/MainWindow.xaml.cs | 53 ++++ src/BreCalClient/ShipcallControl.xaml | 51 ++++ src/BreCalClient/ShipcallControl.xaml.cs | 28 ++ src/BreCalClient/ShipcallControlModel.cs | 15 ++ 7 files changed, 530 insertions(+), 24 deletions(-) create mode 100644 src/BreCalClient/ShipcallControl.xaml create mode 100644 src/BreCalClient/ShipcallControl.xaml.cs create mode 100644 src/BreCalClient/ShipcallControlModel.cs diff --git a/misc/BreCalApi.cs b/misc/BreCalApi.cs index 73c7497..c8c7302 100644 --- a/misc/BreCalApi.cs +++ b/misc/BreCalApi.cs @@ -1,7 +1,7 @@ //---------------------- // -// Generated REST API Client Code Generator v1.7.17.0 on 11.07.2023 17:38:19 +// Generated REST API Client Code Generator v1.7.17.0 on 13.07.2023 19:39:52 // Using the tool OpenAPI Generator v6.6.0 // //---------------------- @@ -3387,7 +3387,7 @@ namespace BreCalClient.misc.Client { Proxy = null; UserAgent = WebUtility.UrlEncode("OpenAPI-Generator/1.0.0/csharp"); - BasePath = "https://brecal.bsmd-emswe.eu/"; + BasePath = "https://puls200.dyn-dns.org:8088/brecal/api"; DefaultHeaders = new ConcurrentDictionary(); ApiKey = new ConcurrentDictionary(); ApiKeyPrefix = new ConcurrentDictionary(); @@ -3395,7 +3395,7 @@ namespace BreCalClient.misc.Client { { new Dictionary { - {"url", "https://brecal.bsmd-emswe.eu/"}, + {"url", "https://puls200.dyn-dns.org:8088/brecal/api"}, {"description", "Test server self-hosted by yours truly"}, } } @@ -3414,7 +3414,7 @@ namespace BreCalClient.misc.Client IDictionary defaultHeaders, IDictionary apiKey, IDictionary apiKeyPrefix, - string basePath = "https://brecal.bsmd-emswe.eu/") : this() + string basePath = "https://puls200.dyn-dns.org:8088/brecal/api") : this() { if (string.IsNullOrWhiteSpace(basePath)) throw new ArgumentException("The provided basePath is invalid.", "basePath"); @@ -3581,7 +3581,7 @@ namespace BreCalClient.misc.Client /// /// ApiKeyPrefix["Authorization"] = "Bearer"; /// - /// � where ApiKey["Authorization"] would then be used to set the value of your bearer token. + /// … where ApiKey["Authorization"] would then be used to set the value of your bearer token. /// /// /// OAuth2 workflows should set tokens via AccessToken. @@ -5672,16 +5672,18 @@ namespace BreCalClient.misc.Model /// name. /// imo. /// callsign. + /// participantId. /// length. /// width. /// created. /// modified. - public Ship(int id = default(int), string name = default(string), int imo = default(int), string callsign = default(string), float length = default(float), float width = default(float), DateTime created = default(DateTime), DateTime modified = default(DateTime)) + public Ship(int id = default(int), string name = default(string), int imo = default(int), string callsign = default(string), int participantId = default(int), float length = default(float), float width = default(float), DateTime created = default(DateTime), DateTime modified = default(DateTime)) { this.Id = id; this.Name = name; this.Imo = imo; this.Callsign = callsign; + this.ParticipantId = participantId; this.Length = length; this.Width = width; this.Created = created; @@ -5708,6 +5710,11 @@ namespace BreCalClient.misc.Model [DataMember(Name = "callsign", EmitDefaultValue = true)] public string Callsign { get; set; } /// + /// Gets or Sets ParticipantId + /// + [DataMember(Name = "participant_id", EmitDefaultValue = true)] + public int ParticipantId { get; set; } + /// /// Gets or Sets Length /// [DataMember(Name = "length", EmitDefaultValue = true)] @@ -5739,6 +5746,7 @@ namespace BreCalClient.misc.Model sb.Append(" Name: ").Append(Name).Append("\n"); sb.Append(" Imo: ").Append(Imo).Append("\n"); sb.Append(" Callsign: ").Append(Callsign).Append("\n"); + sb.Append(" ParticipantId: ").Append(ParticipantId).Append("\n"); sb.Append(" Length: ").Append(Length).Append("\n"); sb.Append(" Width: ").Append(Width).Append("\n"); sb.Append(" Created: ").Append(Created).Append("\n"); @@ -5793,6 +5801,10 @@ namespace BreCalClient.misc.Model (this.Callsign != null && this.Callsign.Equals(input.Callsign)) ) && + ( + this.ParticipantId == input.ParticipantId || + this.ParticipantId.Equals(input.ParticipantId) + ) && ( this.Length == input.Length || this.Length.Equals(input.Length) @@ -5831,6 +5843,7 @@ namespace BreCalClient.misc.Model { hashCode = (hashCode * 59) + this.Callsign.GetHashCode(); } + hashCode = (hashCode * 59) + this.ParticipantId.GetHashCode(); hashCode = (hashCode * 59) + this.Length.GetHashCode(); hashCode = (hashCode * 59) + this.Width.GetHashCode(); if (this.Created != null) @@ -5909,13 +5922,54 @@ namespace BreCalClient.misc.Model /// Initializes a new instance of the class. /// /// The unique identifier of a ship call (required). + /// shipId (required). /// type (required). - /// description. - public Shipcall(int id = default(int), TypeEnum type = default(TypeEnum), string description = default(string)) + /// eta (required). + /// voyage (required). + /// etd (required). + /// arrivalBerthId. + /// departureBerthId. + /// tugReguired. + /// pilotRequired. + /// flags. + /// pierSide. + /// bunkering. + /// replenishing. + /// draft. + /// tidalWindowFrom. + /// tidalWindowTo. + /// rainSensitiveCargo. + /// recommendedTugs. + /// 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), string modified = default(string)) { this.Id = id; + this.ShipId = shipId; this.Type = type; - this.Description = description; + this.Eta = eta; + // to ensure "voyage" is required (not null) + if (voyage == null) + { + throw new ArgumentNullException("voyage is a required property for Shipcall and cannot be null"); + } + this.Voyage = voyage; + this.Etd = etd; + this.ArrivalBerthId = arrivalBerthId; + this.DepartureBerthId = departureBerthId; + this.TugReguired = tugReguired; + this.PilotRequired = pilotRequired; + this.Flags = flags; + this.PierSide = pierSide; + this.Bunkering = bunkering; + this.Replenishing = replenishing; + this.Draft = draft; + this.TidalWindowFrom = tidalWindowFrom; + this.TidalWindowTo = tidalWindowTo; + this.RainSensitiveCargo = rainSensitiveCargo; + this.RecommendedTugs = recommendedTugs; + this.Created = created; + this.Modified = modified; } /// /// The unique identifier of a ship call @@ -5924,10 +5978,100 @@ namespace BreCalClient.misc.Model [DataMember(Name = "id", IsRequired = true, EmitDefaultValue = true)] public int Id { get; set; } /// - /// Gets or Sets Description + /// Gets or Sets ShipId /// - [DataMember(Name = "description", EmitDefaultValue = true)] - public string Description { get; set; } + [DataMember(Name = "ship_id", IsRequired = true, EmitDefaultValue = true)] + public int ShipId { get; set; } + /// + /// Gets or Sets Eta + /// + [DataMember(Name = "eta", IsRequired = true, EmitDefaultValue = true)] + public DateTime Eta { get; set; } + /// + /// Gets or Sets Voyage + /// + [DataMember(Name = "voyage", IsRequired = true, EmitDefaultValue = true)] + public string Voyage { get; set; } + /// + /// Gets or Sets Etd + /// + [DataMember(Name = "etd", IsRequired = true, EmitDefaultValue = true)] + public DateTime Etd { get; set; } + /// + /// Gets or Sets ArrivalBerthId + /// + [DataMember(Name = "arrival_berth_id", EmitDefaultValue = true)] + public int ArrivalBerthId { get; set; } + /// + /// Gets or Sets DepartureBerthId + /// + [DataMember(Name = "departure_berth_id", EmitDefaultValue = true)] + public int DepartureBerthId { get; set; } + /// + /// Gets or Sets TugReguired + /// + [DataMember(Name = "tug_reguired", EmitDefaultValue = true)] + public bool TugReguired { get; set; } + /// + /// Gets or Sets PilotRequired + /// + [DataMember(Name = "pilot_required", EmitDefaultValue = true)] + public bool PilotRequired { get; set; } + /// + /// Gets or Sets Flags + /// + [DataMember(Name = "flags", EmitDefaultValue = true)] + public int Flags { get; set; } + /// + /// Gets or Sets PierSide + /// + [DataMember(Name = "pier_side", EmitDefaultValue = true)] + public bool PierSide { get; set; } + /// + /// Gets or Sets Bunkering + /// + [DataMember(Name = "bunkering", EmitDefaultValue = true)] + public bool Bunkering { get; set; } + /// + /// Gets or Sets Replenishing + /// + [DataMember(Name = "replenishing", EmitDefaultValue = true)] + public bool Replenishing { get; set; } + /// + /// Gets or Sets Draft + /// + [DataMember(Name = "draft", EmitDefaultValue = true)] + public float Draft { get; set; } + /// + /// Gets or Sets TidalWindowFrom + /// + [DataMember(Name = "tidal_window_from", EmitDefaultValue = true)] + public DateTime TidalWindowFrom { get; set; } + /// + /// Gets or Sets TidalWindowTo + /// + [DataMember(Name = "tidal_window_to", EmitDefaultValue = true)] + public DateTime TidalWindowTo { get; set; } + /// + /// Gets or Sets RainSensitiveCargo + /// + [DataMember(Name = "rain_sensitive_cargo", EmitDefaultValue = true)] + public bool RainSensitiveCargo { get; set; } + /// + /// Gets or Sets RecommendedTugs + /// + [DataMember(Name = "recommended_tugs", EmitDefaultValue = true)] + public int RecommendedTugs { get; set; } + /// + /// Gets or Sets Created + /// + [DataMember(Name = "created", EmitDefaultValue = true)] + public DateTime Created { get; set; } + /// + /// Gets or Sets Modified + /// + [DataMember(Name = "modified", EmitDefaultValue = true)] + public string Modified { get; set; } /// /// Returns the string presentation of the object /// @@ -5937,8 +6081,26 @@ namespace BreCalClient.misc.Model StringBuilder sb = new StringBuilder(); sb.Append("class Shipcall {\n"); sb.Append(" Id: ").Append(Id).Append("\n"); + sb.Append(" ShipId: ").Append(ShipId).Append("\n"); sb.Append(" Type: ").Append(Type).Append("\n"); - sb.Append(" Description: ").Append(Description).Append("\n"); + sb.Append(" Eta: ").Append(Eta).Append("\n"); + sb.Append(" Voyage: ").Append(Voyage).Append("\n"); + sb.Append(" Etd: ").Append(Etd).Append("\n"); + sb.Append(" ArrivalBerthId: ").Append(ArrivalBerthId).Append("\n"); + sb.Append(" DepartureBerthId: ").Append(DepartureBerthId).Append("\n"); + sb.Append(" TugReguired: ").Append(TugReguired).Append("\n"); + sb.Append(" PilotRequired: ").Append(PilotRequired).Append("\n"); + sb.Append(" Flags: ").Append(Flags).Append("\n"); + sb.Append(" PierSide: ").Append(PierSide).Append("\n"); + sb.Append(" Bunkering: ").Append(Bunkering).Append("\n"); + sb.Append(" Replenishing: ").Append(Replenishing).Append("\n"); + sb.Append(" Draft: ").Append(Draft).Append("\n"); + sb.Append(" TidalWindowFrom: ").Append(TidalWindowFrom).Append("\n"); + sb.Append(" TidalWindowTo: ").Append(TidalWindowTo).Append("\n"); + sb.Append(" RainSensitiveCargo: ").Append(RainSensitiveCargo).Append("\n"); + sb.Append(" RecommendedTugs: ").Append(RecommendedTugs).Append("\n"); + sb.Append(" Created: ").Append(Created).Append("\n"); + sb.Append(" Modified: ").Append(Modified).Append("\n"); sb.Append("}\n"); return sb.ToString(); } @@ -5975,14 +6137,92 @@ namespace BreCalClient.misc.Model this.Id == input.Id || this.Id.Equals(input.Id) ) && + ( + this.ShipId == input.ShipId || + this.ShipId.Equals(input.ShipId) + ) && ( this.Type == input.Type || this.Type.Equals(input.Type) ) && ( - this.Description == input.Description || - (this.Description != null && - this.Description.Equals(input.Description)) + this.Eta == input.Eta || + (this.Eta != null && + this.Eta.Equals(input.Eta)) + ) && + ( + this.Voyage == input.Voyage || + (this.Voyage != null && + this.Voyage.Equals(input.Voyage)) + ) && + ( + this.Etd == input.Etd || + (this.Etd != null && + this.Etd.Equals(input.Etd)) + ) && + ( + this.ArrivalBerthId == input.ArrivalBerthId || + this.ArrivalBerthId.Equals(input.ArrivalBerthId) + ) && + ( + this.DepartureBerthId == input.DepartureBerthId || + this.DepartureBerthId.Equals(input.DepartureBerthId) + ) && + ( + this.TugReguired == input.TugReguired || + this.TugReguired.Equals(input.TugReguired) + ) && + ( + this.PilotRequired == input.PilotRequired || + this.PilotRequired.Equals(input.PilotRequired) + ) && + ( + this.Flags == input.Flags || + this.Flags.Equals(input.Flags) + ) && + ( + this.PierSide == input.PierSide || + this.PierSide.Equals(input.PierSide) + ) && + ( + this.Bunkering == input.Bunkering || + this.Bunkering.Equals(input.Bunkering) + ) && + ( + this.Replenishing == input.Replenishing || + this.Replenishing.Equals(input.Replenishing) + ) && + ( + this.Draft == input.Draft || + this.Draft.Equals(input.Draft) + ) && + ( + this.TidalWindowFrom == input.TidalWindowFrom || + (this.TidalWindowFrom != null && + this.TidalWindowFrom.Equals(input.TidalWindowFrom)) + ) && + ( + this.TidalWindowTo == input.TidalWindowTo || + (this.TidalWindowTo != null && + this.TidalWindowTo.Equals(input.TidalWindowTo)) + ) && + ( + this.RainSensitiveCargo == input.RainSensitiveCargo || + this.RainSensitiveCargo.Equals(input.RainSensitiveCargo) + ) && + ( + this.RecommendedTugs == input.RecommendedTugs || + this.RecommendedTugs.Equals(input.RecommendedTugs) + ) && + ( + this.Created == input.Created || + (this.Created != null && + this.Created.Equals(input.Created)) + ) && + ( + this.Modified == input.Modified || + (this.Modified != null && + this.Modified.Equals(input.Modified)) ); } /// @@ -5995,10 +6235,46 @@ namespace BreCalClient.misc.Model { int hashCode = 41; hashCode = (hashCode * 59) + this.Id.GetHashCode(); + hashCode = (hashCode * 59) + this.ShipId.GetHashCode(); hashCode = (hashCode * 59) + this.Type.GetHashCode(); - if (this.Description != null) + if (this.Eta != null) { - hashCode = (hashCode * 59) + this.Description.GetHashCode(); + hashCode = (hashCode * 59) + this.Eta.GetHashCode(); + } + if (this.Voyage != null) + { + hashCode = (hashCode * 59) + this.Voyage.GetHashCode(); + } + if (this.Etd != null) + { + hashCode = (hashCode * 59) + this.Etd.GetHashCode(); + } + hashCode = (hashCode * 59) + this.ArrivalBerthId.GetHashCode(); + hashCode = (hashCode * 59) + this.DepartureBerthId.GetHashCode(); + hashCode = (hashCode * 59) + this.TugReguired.GetHashCode(); + hashCode = (hashCode * 59) + this.PilotRequired.GetHashCode(); + hashCode = (hashCode * 59) + this.Flags.GetHashCode(); + hashCode = (hashCode * 59) + this.PierSide.GetHashCode(); + hashCode = (hashCode * 59) + this.Bunkering.GetHashCode(); + hashCode = (hashCode * 59) + this.Replenishing.GetHashCode(); + hashCode = (hashCode * 59) + this.Draft.GetHashCode(); + if (this.TidalWindowFrom != null) + { + hashCode = (hashCode * 59) + this.TidalWindowFrom.GetHashCode(); + } + if (this.TidalWindowTo != null) + { + hashCode = (hashCode * 59) + this.TidalWindowTo.GetHashCode(); + } + hashCode = (hashCode * 59) + this.RainSensitiveCargo.GetHashCode(); + hashCode = (hashCode * 59) + this.RecommendedTugs.GetHashCode(); + if (this.Created != null) + { + hashCode = (hashCode * 59) + this.Created.GetHashCode(); + } + if (this.Modified != null) + { + hashCode = (hashCode * 59) + this.Modified.GetHashCode(); } return hashCode; } diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index 9d88e62..2e195bf 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -14,8 +14,8 @@ info: servers: # tutorial: https://idratherbewriting.com/learnapidoc/pubapis_openapi_step3_servers_object.html - - url : "https://brecal.bsmd-emswe.eu/" - description: "Test server hosted on netcup vserver" + - url : "https://puls200.dyn-dns.org:8088/brecal/api" + description: "Test server self-hosted by yours truly" paths: # tutorial: https://idratherbewriting.com/learnapidoc/pubapis_openapi_step4_paths_object.html @@ -313,15 +313,55 @@ components: properties: id: $ref: '#/components/schemas/shipcallId' - + ship_id: + type: integer type: type: string enum: - incoming - outgoing - shifting - - description: + eta: + type: string + format: date-time + voyage: + type: string + etd: + type: string + format: date-time + arrival_berth_id: + type: integer + departure_berth_id: + type: integer + tug_reguired: + type: boolean + pilot_required: + type: boolean + flags: + type: integer + pier_side: + type: boolean + bunkering: + type: boolean + replenishing: + type: boolean + draft: + type: number + format: float + tidal_window_from: + type: string + format: date-time + tidal_window_to: + type: string + format: date-time + rain_sensitive_cargo: + type: boolean + recommended_tugs: + type: integer + created: + type: string + format: date-time + modified: type: string shipcalls: @@ -390,6 +430,8 @@ components: type: integer callsign: type: string + participant_id: + type: integer length: type: number format: float diff --git a/src/BreCalClient/MainWindow.xaml b/src/BreCalClient/MainWindow.xaml index 5a8c2f0..1ab618e 100644 --- a/src/BreCalClient/MainWindow.xaml +++ b/src/BreCalClient/MainWindow.xaml @@ -38,7 +38,48 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index c496015..48939f3 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -25,12 +27,22 @@ namespace BreCalClient public partial class MainWindow : Window { DefaultApi _api; + ObservableCollection _controlModels = new(); + List _ships = new(); + Dictionary _shipLookupDict = new(); + List _berths = new(); + Dictionary _berthLookupDict = new(); + List _participants = new(); + Dictionary _participantLookupDict = new(); + public MainWindow() { InitializeComponent(); _api = new DefaultApi(); } + #region event handler + private void Window_Loaded(object sender, RoutedEventArgs e) { @@ -55,6 +67,7 @@ namespace BreCalClient if(loginResult.Id > 0) { this.busyIndicator.IsBusy = false; + this.LoadStaticLists(); } } } @@ -72,5 +85,45 @@ namespace BreCalClient { this.Close(); } + + #endregion + + #region private methods + + private async void LoadStaticLists() + { + this._berths = await _api.BerthsGetAsync(); + foreach(var berth in this._berths) + _berthLookupDict[berth.Id] = berth; + this._ships = await _api.ShipsGetAsync(); + foreach(var ship in this._ships) + _shipLookupDict[ship.Id] = ship; + // this._participants = await _api.ParticipantGetAsync(); + } + + private async void RefreshShipcalls() + { + List shipcalls = await _api.ShipcallsGetAsync(0); // TODO: this must return all current calls + foreach(Shipcall shipcall in shipcalls) + { + + + // TODO: find out if we already have this thing + + // yes: update values + + // no: create new entry + ShipcallControlModel scm = new ShipcallControlModel(); + scm.Shipcall = shipcall; + if(this._shipLookupDict.ContainsKey(shipcall.Id)) + scm.Ship = this._shipLookupDict[shipcall.Id]; + _controlModels.Add(scm); + + // TODO: sort this list somehow + } + } + + #endregion + } } diff --git a/src/BreCalClient/ShipcallControl.xaml b/src/BreCalClient/ShipcallControl.xaml new file mode 100644 index 0000000..f8e8b63 --- /dev/null +++ b/src/BreCalClient/ShipcallControl.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/BreCalClient/ShipcallControl.xaml.cs b/src/BreCalClient/ShipcallControl.xaml.cs new file mode 100644 index 0000000..4218613 --- /dev/null +++ b/src/BreCalClient/ShipcallControl.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BreCalClient +{ + /// + /// Interaction logic for ShipcallControl.xaml + /// + public partial class ShipcallControl : UserControl + { + public ShipcallControl() + { + InitializeComponent(); + } + } +} diff --git a/src/BreCalClient/ShipcallControlModel.cs b/src/BreCalClient/ShipcallControlModel.cs new file mode 100644 index 0000000..fe864f4 --- /dev/null +++ b/src/BreCalClient/ShipcallControlModel.cs @@ -0,0 +1,15 @@ +using BreCalClient.misc.Model; + + +namespace BreCalClient +{ + + /// + /// Container model to aggregate separate models for the Shipcall control data binding + /// + public class ShipcallControlModel + { + public Shipcall? Shipcall { get; set; } + public Ship? Ship { get; set; } + } +}