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' $ref: '#/components/responses/500'
'503': '503':
$ref: '#/components/responses/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: components:
schemas: 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: credentials:
type: object type: object
properties: properties:

View File

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