Include getlatest endpoint in yaml and call before shipcall sync in reg update

This commit is contained in:
Daniel Schick 2024-06-11 09:41:45 +02:00
parent 50e9261267
commit 129b8c8d49
3 changed files with 1791 additions and 28 deletions

File diff suppressed because it is too large Load Diff

View File

@ -457,8 +457,43 @@ paths:
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
/getlatest:
get:
description: 'Returns timestamps for latest data changes'
summary: Get latest timestamps of changes
tags:
- shipcall
operationId: getLatest
responses:
'200':
description: ship call list
content:
application/json:
schema:
$ref: '#/components/schemas/latest'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'
'503':
$ref: '#/components/responses/503'
components:
schemas:
latest:
type: object
properties:
shipcalls:
type: string
format: date-time
nullable: true
times:
type: string
format: date-time
nullable: true
ship:
type: string
format: date-time
nullable: true
credentials:
type: object
properties:

View File

@ -39,7 +39,7 @@ namespace BreCalClient
#region Fields
//private static int _uiUpdateRunning = 0;
private static SemaphoreSlim uiLock = new SemaphoreSlim(1);
private static readonly SemaphoreSlim uiLock = new SemaphoreSlim(1);
private Credentials? _credentials;
@ -65,6 +65,10 @@ namespace BreCalClient
// private bool _sequenceChanged = false;
private HistoryDialog? _historyDialog;
// Fields to store the latest check flags
private DateTime? _latestShipcall;
private DateTime? _latestShip;
#endregion
#region Enums
@ -443,20 +447,61 @@ namespace BreCalClient
}
List<Shipcall>? shipcalls = null;
bool skipShipLoad, skipShipcallLoad;
skipShipLoad = false;
skipShipcallLoad = false;
try
{
if(this.searchPastDays != 0)
shipcalls = await _shipcallApi.ShipcallsGetAsync(this.searchPastDays);
else
shipcalls = await _shipcallApi.ShipcallsGetAsync();
this.Dispatcher.Invoke(new Action(() =>
// this only works with API v1.3 onwards
Latest latest = await _shipcallApi.GetLatestAsync();
if (latest != null)
{
labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}";
labelLatestUpdate.Text = $"Last update: {DateTime.Now.ToLongTimeString()}";
labelStatusBar.Text = "";
generalProgressStatus.Value = 0;
}));
// compare timestamps to decide whether an update is required
if ((_latestShip != null) && ((latest.Ship.HasValue &&
(latest.Ship.Value <= _latestShip.Value)) ||
!_latestShip.HasValue)
)
{
skipShipLoad = true;
}
if(!skipShipLoad)
{
_latestShip = latest.Ship ?? DateTime.Now;
}
if ((_latestShipcall != null) && ((latest.Shipcalls.HasValue &&
(latest.Shipcalls.Value <= _latestShipcall.Value)) ||
!_latestShipcall.HasValue)
)
{
skipShipcallLoad = true;
}
if(!skipShipcallLoad)
{
_latestShipcall = latest.Shipcalls ?? DateTime.Now;
}
}
if (!skipShipcallLoad)
{
if (this.searchPastDays != 0)
shipcalls = await _shipcallApi.ShipcallsGetAsync(this.searchPastDays);
else
shipcalls = await _shipcallApi.ShipcallsGetAsync();
this.Dispatcher.Invoke(new Action(() =>
{
labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}";
labelLatestUpdate.Text = $"Last update: {DateTime.Now.ToLongTimeString()}";
labelStatusBar.Text = "";
generalProgressStatus.Value = 0;
}));
}
}
catch (Exception ex)
{
@ -474,7 +519,7 @@ namespace BreCalClient
try
{
if (shipcalls != null)
{
foreach (Shipcall shipcall in shipcalls)