Added ship post/put/delete to API

This commit is contained in:
Daniel Schick 2024-01-14 13:35:35 +01:00
parent 88d6a6a994
commit 106247527e
5 changed files with 1052 additions and 326 deletions

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@ tags:
- name: shipcall
- name: times
- name: static
- name: ship
paths:
/login:
post:
@ -158,7 +159,7 @@ paths:
summary: gets a list of ships
description: Gets a list of ships including logically deleted ships to be used with shipcalls
tags:
- static
- ship
operationId: shipsGet
responses:
'200':
@ -175,6 +176,77 @@ paths:
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
post:
summary: create a new ship entry
description: adds a new non-existing ship to the database. The ships IMO number is the unique identifier.
tags:
- ship
operationId: shipsCreate
requestBody:
description: Ship details. **Do not** provide id parameter.
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ship'
responses:
'201':
$ref: '#/components/responses/201'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
put:
summary: Update a ship entry
description: Updating a ship entry. Please do not modify the IMO number. In that case please add a new entry.
tags:
- ship
operationId: shipUpdate
requestBody:
description: Updated ship entry. The id parameter is **required**.
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ship'
responses:
'200':
$ref: '#/components/responses/200'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
delete:
summary: Delete a ship (logically).
description: 'A ship can only be logically deleted, since it is possible to have been used in previous shipcalls. On logical delete, the ship can no longer be selected in a new ship call.'
tags:
- ship
operationId: shipDelete
parameters:
- name: id
in: query
required: true
schema:
type: integer
responses:
'200':
$ref: '#/components/responses/200'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
/participants:
get:
summary: gets one or all participants

View File

@ -75,12 +75,12 @@ namespace BreCalClient
switch (CallType)
{
case Extensions.TypeEnum.Incoming:
case ShipcallType.Arrival:
this.labelETA.FontWeight = FontWeights.Bold;
this.datePickerETABerth.ContextMenu.IsEnabled = false;
break;
case Extensions.TypeEnum.Outgoing:
case Extensions.TypeEnum.Shifting:
case ShipcallType.Departure:
case ShipcallType.Shifting:
this.labelETD.FontWeight = FontWeights.Bold;
this.datePickerETDBerth.ContextMenu.IsEnabled = false;
break;

View File

@ -97,12 +97,12 @@ namespace BreCalClient
switch (CallType)
{
case Extensions.TypeEnum.Incoming:
case ShipcallType.Arrival:
this.labelStart.FontWeight = FontWeights.Bold;
this.datePickerOperationStart.ContextMenu.IsEnabled = false;
break;
case Extensions.TypeEnum.Outgoing:
case Extensions.TypeEnum.Shifting:
case ShipcallType.Departure:
case ShipcallType.Shifting:
this.labelEnd.FontWeight = FontWeights.Bold;
this.datePickerOperationEnd.ContextMenu.IsEnabled = false;
break;

View File

@ -47,6 +47,7 @@ namespace BreCalClient
private readonly UserApi _userApi;
private readonly TimesApi _timesApi;
private readonly StaticApi _staticApi;
private readonly ShipApi _shipApi;
private CancellationTokenSource _tokenSource = new();
private LoginResult? _loginResult;
@ -85,6 +86,8 @@ namespace BreCalClient
_timesApi.Configuration.ApiKeyPrefix["Authorization"] = "Bearer";
_staticApi = new StaticApi(Properties.Settings.Default.API_URL);
_staticApi.Configuration.ApiKeyPrefix["Authorization"] = "Bearer";
_shipApi = new ShipApi(Properties.Settings.Default.API_URL);
_shipApi.Configuration.ApiKeyPrefix["Authorization"] = "Bearer";
}
#endregion
@ -136,6 +139,7 @@ namespace BreCalClient
this._shipcallApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._timesApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._staticApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._shipApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this.LoadStaticLists();
this.labelUsername.Text = $"{_loginResult.FirstName} {_loginResult.LastName}";
_timer = new Timer(RefreshToken, null, 4000000, Timeout.Infinite);
@ -177,6 +181,7 @@ namespace BreCalClient
this._timesApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._shipcallApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._staticApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
this._shipApi.Configuration.ApiKey["Authorization"] = _loginResult.Token;
}
}
else
@ -230,11 +235,11 @@ namespace BreCalClient
_tokenSource.Cancel(); // force timer loop end
// if this was an arrival, create the matching departure call and open it
if (esc.ShipcallModel.Shipcall?.Type == (int)Extensions.TypeEnum.Incoming)
if (esc.ShipcallModel.Shipcall?.Type == ShipcallType.Arrival)
{
ShipcallControlModel scmOut = new();
scmOut.Shipcall = new();
scmOut.Shipcall.Type = (int)Extensions.TypeEnum.Outgoing;
scmOut.Shipcall.Type = ShipcallType.Departure;
scmOut.Shipcall.ShipId = esc.ShipcallModel.Shipcall.ShipId;
scmOut.Ship = esc.ShipcallModel.Ship;
DateTime eta = esc.ShipcallModel.Shipcall?.Eta ?? DateTime.Now;
@ -321,7 +326,7 @@ namespace BreCalClient
private async void LoadStaticLists()
{
BreCalLists.InitializeBerths(await _staticApi.BerthsGetAsync());
BreCalLists.InitializeShips(await _staticApi.ShipsGetAsync());
BreCalLists.InitializeShips(await _shipApi.ShipsGetAsync());
BreCalLists.InitializeParticipants(await _staticApi.ParticipantsGetAsync());
this.searchFilterControl.SetBerths(BreCalLists.Berths);
@ -535,8 +540,8 @@ namespace BreCalClient
if(sfm.Berths.Count > 0 )
{
this._visibleControlModels.RemoveAll(x => (!sfm.Berths.Contains((x.Shipcall?.ArrivalBerthId) ?? -1) && (x.Shipcall?.Type == (int) Extensions.TypeEnum.Incoming)) ||
(!sfm.Berths.Contains((x.Shipcall?.DepartureBerthId) ?? -1) && (x.Shipcall?.Type != (int) Extensions.TypeEnum.Incoming)));
this._visibleControlModels.RemoveAll(x => (!sfm.Berths.Contains((x.Shipcall?.ArrivalBerthId) ?? -1) && (x.Shipcall?.Type == ShipcallType.Arrival)) ||
(!sfm.Berths.Contains((x.Shipcall?.DepartureBerthId) ?? -1) && (x.Shipcall?.Type != ShipcallType.Arrival)));
}
if(sfm.Agencies.Count > 0 )