Enums, work in progress

This commit is contained in:
Daniel Schick 2023-12-15 13:31:31 +01:00
parent c50f82354f
commit c6b16c4fa7
14 changed files with 623 additions and 613 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,9 @@
openapi: "3.0.0"
openapi: "3.1.0"
info:
version: "0.6.0"
version: "1.1.0"
title: "Bremen calling API"
description: Administer DEBRE ship calls, times and notifications
termsOfService: "https://www.bsmd.de/" # url to terms page
termsOfService: "https://www.bsmd.de/" # TBD: url to terms page
contact:
name: "Bremen calling API"
url: "https://www.textbausteine.net"
@ -13,8 +13,8 @@ info:
url: "https://www.bsmd.de/license"
servers:
- url: "https://brecaltest.bsmd-emswe.eu/"
description: "Test server hosted on vcup"
- url: "https://brecaldevel.bsmd-emswe.eu/"
description: "Development server hosted on vcup"
paths:
/login:
@ -353,8 +353,7 @@ components:
ship_id:
type: integer
type:
type: integer
# TODO: use an enum
type: ShipcallType
eta:
type: string
format: date-time
@ -507,8 +506,7 @@ components:
type: boolean
nullable: true
participant_type:
type: integer
nullable: true
type: ParticipantType
created:
type: string
format: date-time
@ -619,8 +617,7 @@ components:
participant_id:
type: integer
notification_type:
type: string
enum: [undefined, email, push]
$ref: "#/components/schemas/NotificationType"
timestamp:
type: string
format: date-time
@ -658,7 +655,7 @@ components:
type: string
maxLength: 64
type:
type: integer
type: ParticipantType
flags:
type: integer
nullable: true
@ -741,6 +738,65 @@ components:
description: A human readable error message
type: string
ShipcallType:
type: string
enum: [undefined, arrival, departure, shifting]
NotificationType:
type: string
enum: [undefined, email, push]
ParticipantType:
type: integer
enum:
- 1
- 2
- 4
- 8
- 16
- 32
- 64
x-enumDescriptions:
1: bsmd
2: terminal
4: pilot
8: agency
16: mooring
32: port_authority
64: tug
# this here works only with OpenAPI 3.1
# ParticipantType:
# type: integer
# oneOf:
# - const: 1
# title: bsmd
# description: Bremen Schiffsmeldedienst
# - const: 2
# title: terminal
# description: Terminal
# - const: 4
# title: pilot
# description: Pilot
# - const: 8
# title: agency
# description: Agency
# - const: 16
# title: mooring
# description: Mooring
# - const: 32
# title: port_authority
# description: Port Authority
# - const: 64
# title: tug
# description: Tug
securitySchemes:
ApiKey:
type: apiKey
@ -760,7 +816,7 @@ components:
schema:
$ref: "#/components/schemas/Id"
400:
description: Invalid input
description: Bad request
content:
application/json:
schema:
@ -771,6 +827,18 @@ components:
application/json:
schema:
$ref: "#/components/schemas/Error"
403:
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
404:
description: Not found
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
500:
description: Unexpected error
content:
@ -778,7 +846,7 @@ components:
schema:
$ref: "#/components/schemas/Error"
503:
description: Not available
description: Service unavailable
content:
application/json:
schema:

View File

@ -106,7 +106,7 @@
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly" Version="7.2.4" />
<PackageReference Include="Polly" Version="8.2.0" />
<PackageReference Include="RestSharp" Version="110.2.0" />
</ItemGroup>

View File

@ -40,7 +40,7 @@ namespace BreCalClient
this.comboBoxAgency.ItemsSource = BreCalLists.Participants_Agent;
this.comboBoxShip.ItemsSource = BreCalLists.Ships;
this.comboBoxCategories.ItemsSource = Enum.GetValues(typeof(TypeEnum));
this.comboBoxCategories.ItemsSource = Enum.GetValues(typeof(ShipcallType));
this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths;
this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths;
@ -91,12 +91,12 @@ namespace BreCalClient
private void comboBoxCategories_SelectionChanged(object? sender, SelectionChangedEventArgs? e)
{
TypeEnum? type = this.comboBoxCategories.SelectedItem as TypeEnum?;
ShipcallType? type = this.comboBoxCategories.SelectedItem as ShipcallType?;
if (type != null)
{
switch (type)
{
case TypeEnum.Incoming:
case ShipcallType.Arrival:
this.datePickerETA.IsEnabled = true;
this.datePickerETD.IsEnabled = false;
this.datePickerETD.Value = null;
@ -104,7 +104,7 @@ namespace BreCalClient
this.comboBoxDepartureBerth.IsEnabled = false;
this.comboBoxArrivalBerth.IsEnabled = true;
break;
case TypeEnum.Outgoing:
case ShipcallType.Departure:
this.datePickerETA.IsEnabled = false;
this.datePickerETD.IsEnabled = true;
this.datePickerETA.Value = null;
@ -112,7 +112,7 @@ namespace BreCalClient
this.comboBoxArrivalBerth.IsEnabled = false;
this.comboBoxDepartureBerth.IsEnabled = true;
break;
case TypeEnum.Shifting:
case ShipcallType.Shifting:
this.datePickerETA.IsEnabled = true;
this.datePickerETD.IsEnabled = true;
this.comboBoxArrivalBerth.IsEnabled = true;
@ -150,18 +150,18 @@ namespace BreCalClient
}
else
{
TypeEnum callType = (TypeEnum)comboBoxCategories.SelectedItem;
ShipcallType callType = (ShipcallType)comboBoxCategories.SelectedItem;
switch (callType)
{
case TypeEnum.Outgoing:
case ShipcallType.Departure:
isEnabled &= this.comboBoxDepartureBerth.SelectedItem != null;
isEnabled &= this.datePickerETD.Value.HasValue;
break;
case TypeEnum.Incoming:
case ShipcallType.Arrival:
isEnabled &= this.comboBoxArrivalBerth.SelectedItem != null;
isEnabled &= this.datePickerETA.Value.HasValue;
break;
case TypeEnum.Shifting:
case ShipcallType.Shifting:
isEnabled &= ((this.comboBoxDepartureBerth.SelectedItem != null) && (this.comboBoxArrivalBerth.SelectedItem != null));
isEnabled &= this.datePickerETD.Value.HasValue;
isEnabled &= this.datePickerETA.Value.HasValue;
@ -178,7 +178,7 @@ namespace BreCalClient
{
if (this.ShipcallModel.Shipcall != null)
{
this.ShipcallModel.Shipcall.Type = (int)this.comboBoxCategories.SelectedItem;
this.ShipcallModel.Shipcall.Type = (ShipcallType) this.comboBoxCategories.SelectedItem;
this.ShipcallModel.Shipcall.Eta = this.datePickerETA.Value;
this.ShipcallModel.Shipcall.Etd = this.datePickerETD.Value;
@ -186,7 +186,7 @@ namespace BreCalClient
this.ShipcallModel.Ship = ((ShipModel)this.comboBoxShip.SelectedItem).Ship;
this.ShipcallModel.Shipcall.Canceled = this.checkBoxCancelled.IsChecked;
if (this.ShipcallModel.Shipcall.Type != 3) // incoming, outgoing
if (this.ShipcallModel.Shipcall.Type != ShipcallType.Shifting) // incoming, outgoing
{
this.ShipcallModel.Shipcall.ArrivalBerthId = (this.comboBoxArrivalBerth.SelectedItem != null) ? ((Berth)this.comboBoxArrivalBerth.SelectedItem).Id : null;
this.ShipcallModel.Shipcall.DepartureBerthId = (this.comboBoxDepartureBerth.SelectedItem != null) ? ((Berth)this.comboBoxDepartureBerth.SelectedItem).Id : null;
@ -204,6 +204,7 @@ namespace BreCalClient
ParticipantAssignment pa = new()
{
ParticipantId = participant.Id,
Type = (int)Extensions.ParticipantType.AGENCY
};
this.ShipcallModel.AssignedParticipants[Extensions.ParticipantType.AGENCY] = pa;

View File

@ -31,7 +31,7 @@ namespace BreCalClient
public Times Times { get; set; } = new();
public Extensions.TypeEnum CallType { get; set; }
public ShipcallType CallType { get; set; }
#endregion

View File

@ -30,7 +30,7 @@ namespace BreCalClient
public Times Times { get; set; } = new();
public Extensions.TypeEnum CallType { get; set; }
public ShipcallType CallType { get; set; }
#endregion

View File

@ -30,7 +30,7 @@ namespace BreCalClient
public Times Times { get; set; } = new();
public Extensions.TypeEnum CallType { get; set; }
public ShipcallType CallType { get; set; }
#endregion

View File

@ -27,7 +27,7 @@ namespace BreCalClient
public Times Times { get; set; } = new();
public Extensions.TypeEnum CallType { get; set; }
public ShipcallType CallType { get; set; }
#endregion

View File

@ -21,7 +21,7 @@ namespace BreCalClient
public Times Times { get; set; } = new();
public Extensions.TypeEnum CallType { get; set; }
public ShipcallType CallType { get; set; }
#endregion

View File

@ -13,30 +13,6 @@ namespace BreCalClient
#region Enum
/// <summary>
/// Copied from models clunky I know
/// </summary>
[Flags]
public enum ParticipantType
{
[Description("not assigned")]
NONE = 0,
[Description("BSMD")]
BSMD = 1,
[Description("Terminal")]
TERMINAL = 2,
[Description("Lotsen")]
PILOT = 4,
[Description("Agentur")]
AGENCY = 8,
[Description("Festmacher")]
MOORING = 16,
[Description("Hafenamt")]
PORT_ADMINISTRATION = 32,
[Description("Schlepper")]
TUG = 64,
}
/// <summary>
/// Custom participant flags
/// </summary>
@ -47,16 +23,6 @@ namespace BreCalClient
ALLOW_BSMD = 1,
}
/// <summary>
/// Should actually be defined in yaml
/// </summary>
public enum TypeEnum
{
Incoming = 1,
Outgoing = 2,
Shifting = 3
}
public enum SortOrder
{
SHIP_NAME,

View File

@ -13,7 +13,7 @@ namespace BreCalClient
string Title { get; set; }
Extensions.TypeEnum CallType { get; set; }
ShipcallType CallType { get; set; }
bool? ShowDialog();

View File

@ -662,7 +662,7 @@ namespace BreCalClient
}
}
private async void Sc_EditTimesRequested(ShipcallControl obj, Times? times, Extensions.ParticipantType participantType)
private async void Sc_EditTimesRequested(ShipcallControl obj, Times? times, ParticipantType participantType)
{
if( obj.ShipcallControlModel == null) { return; }
@ -673,7 +673,7 @@ namespace BreCalClient
etc.Title = obj.ShipcallControlModel.Title;
if(obj.ShipcallControlModel.Shipcall != null)
etc.CallType = (TypeEnum) obj.ShipcallControlModel.Shipcall.Type;
etc.CallType = (ShipcallType) obj.ShipcallControlModel.Shipcall.Type;
bool wasEdit = false;
if (times != null)

View File

@ -44,7 +44,7 @@ namespace BreCalClient
public event Action<ShipcallControl, Times?>? EditAgencyRequested;
internal event Action<ShipcallControl, Times?, Extensions.ParticipantType>? EditTimesRequested;
internal event Action<ShipcallControl, Times?, ParticipantType>? EditTimesRequested;
#endregion

View File

@ -1,6 +1,6 @@
// Copyright (c) 2023 schick Informatik
// Description: Container model for shipcall related info
//
//
using BreCalClient.misc.Api;
using BreCalClient.misc.Model;
@ -44,11 +44,11 @@ namespace BreCalClient
public Shipcall? Shipcall { get; set; }
public Ship? Ship { get; set; }
public Ship? Ship { get; set; }
public string? Berth { get; set; }
internal Dictionary<Extensions.ParticipantType, ParticipantAssignment> AssignedParticipants { get; } = new();
internal Dictionary<ParticipantType, ParticipantAssignment> AssignedParticipants { get; } = new();
public List<Times> Times { get; set; } = new();
@ -56,7 +56,7 @@ namespace BreCalClient
{
get
{
Times? agencyTimes = this.GetTimesForParticipantType(Extensions.ParticipantType.AGENCY);
Times? agencyTimes = this.GetTimesForParticipantType(ParticipantType.AGENCY);
if((agencyTimes != null) && (agencyTimes.EtaBerth != null))
return agencyTimes.EtaBerth;
return Shipcall?.Eta;
@ -88,7 +88,7 @@ namespace BreCalClient
}
}
return tlm;
}
}
}
public string Title
@ -112,12 +112,12 @@ namespace BreCalClient
{
foreach (ParticipantAssignment participantAssignment in Shipcall.Participants)
{
AssignedParticipants[(Extensions.ParticipantType)participantAssignment.Type] = participantAssignment;
AssignedParticipants[(ParticipantType)participantAssignment.Type] = participantAssignment;
}
}
}
internal Times? GetTimesForParticipantType(Extensions.ParticipantType type)
internal Times? GetTimesForParticipantType(ParticipantType type)
{
if (AssignedParticipants.ContainsKey(type)) {
@ -127,14 +127,14 @@ namespace BreCalClient
if ((times.ParticipantId == participantId) && (times.ParticipantType == (int) type))
return times;
}
if(type == Extensions.ParticipantType.AGENCY)
if(type == ParticipantType.AGENCY)
{
// if I am BSMD and no agency entry was found this means we are editing the agency entry
if(App.Participant.Type == (int) Extensions.ParticipantType.BSMD)
if(App.Participant.Type == (int) ParticipantType.BSMD)
{
foreach(Times times in this.Times)
{
if ((times.ParticipantId == App.Participant.Id) && (times.ParticipantType == (int) Extensions.ParticipantType.AGENCY))
if ((times.ParticipantId == App.Participant.Id) && (times.ParticipantType == (int) ParticipantType.AGENCY))
return times;
}
}
@ -160,15 +160,15 @@ namespace BreCalClient
public string? GetBerthText(Times times)
{
string? berthText = null;
if ((BreCalLists.AllBerths != null) && times.BerthId.HasValue && (this.Shipcall?.Type != (int)Extensions.TypeEnum.Shifting))
if ((BreCalLists.Berths != null) && times.BerthId.HasValue && (this.Shipcall?.Type != ShipcallType.Shifting))
{
Berth? berth = BreCalLists.AllBerths.Find((x) => x.Id == times.BerthId);
berthText = berth?.Name;
}
if ((berthText == null) && (times.ParticipantType != (int)Extensions.ParticipantType.TERMINAL))
if ((berthText == null) && (times.ParticipantType != ParticipantType.TERMINAL))
{
if (this.Shipcall?.Type == (int)Extensions.TypeEnum.Incoming)
if (this.Shipcall?.Type == ShipcallType.Arrival)
{
Berth? berth = BreCalLists.AllBerths?.Find((x) => x.Id == this.Shipcall?.ArrivalBerthId);
berthText = berth?.Name;
@ -191,7 +191,7 @@ namespace BreCalClient
/// <param name="_api">API reference to PUT eidted times</param>
internal async void UpdateTimesAssignments(DefaultApi _api)
{
foreach (Extensions.ParticipantType participantType in this.AssignedParticipants.Keys)
foreach (ParticipantType participantType in this.AssignedParticipants.Keys)
{
Times? times = this.GetTimesForParticipantType(participantType);
if(times == null) continue;
@ -236,11 +236,11 @@ namespace BreCalClient
internal Participant? GetParticipantForType(Extensions.ParticipantType participantType)
{
if(AssignedParticipants.ContainsKey(participantType) && BreCalLists.ParticipantLookupDict.ContainsKey(AssignedParticipants[participantType].ParticipantId))
if(AssignedParticipants.ContainsKey(participantType) && BreCalLists.ParticipantLookupDict.ContainsKey(AssignedParticipants[participantType].ParticipantId))
return BreCalLists.ParticipantLookupDict[AssignedParticipants[participantType].ParticipantId];
return null;
}
}
private bool IsFlagSet(StatusFlags flag)
{
@ -248,7 +248,7 @@ namespace BreCalClient
return (this.Shipcall.Flags & (int) flag) != 0;
}
#endregion
#endregion
}
}