From dce1a83517ee4f283e5ef7a25c6a7dec653b20b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Tue, 5 Nov 2024 12:50:33 +0100 Subject: [PATCH] feat: Add `LastStateChange` to `IntegrationJournalData` to be able to track _when_ an integration did something to a journal. ref #37 --- .../Models/Journal/IntegrationJournalData.cs | 5 ++++- Journal-Limpet/Jobs/SharedCode/GameStateHandler.cs | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Journal-Limpet.Shared/Models/Journal/IntegrationJournalData.cs b/Journal-Limpet.Shared/Models/Journal/IntegrationJournalData.cs index 1190d96..47cf7d4 100644 --- a/Journal-Limpet.Shared/Models/Journal/IntegrationJournalData.cs +++ b/Journal-Limpet.Shared/Models/Journal/IntegrationJournalData.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System; +using System.Text.Json.Serialization; namespace Journal_Limpet.Shared.Models.Journal { @@ -10,5 +11,7 @@ public class IntegrationJournalData public int LastSentLineNumber { get; set; } [JsonPropertyName("currentGameState")] public EDGameState CurrentGameState { get; set; } + [JsonPropertyName("lastStateChange")] + public DateTimeOffset? LastStateChange { get; set; } } } diff --git a/Journal-Limpet/Jobs/SharedCode/GameStateHandler.cs b/Journal-Limpet/Jobs/SharedCode/GameStateHandler.cs index b4490d7..3d9be82 100644 --- a/Journal-Limpet/Jobs/SharedCode/GameStateHandler.cs +++ b/Journal-Limpet/Jobs/SharedCode/GameStateHandler.cs @@ -72,6 +72,8 @@ public static IntegrationJournalData GetIntegrationJournalData(UserJournal journ public async static Task UpdateJournalIntegrationDataAsync(MSSQLDB db, long journalId, string integrationKey, IntegrationJournalData integrationJournalData) { + integrationJournalData.LastStateChange = DateTimeOffset.UtcNow; + return (await db.ExecuteNonQueryAsync( "UPDATE user_journal SET integration_data = JSON_MODIFY(ISNULL(integration_data, JSON_QUERY('{}')), '$.\"" + integrationKey + "\"', JSON_QUERY(@integration_data)) WHERE journal_id = @journal_id", new SqlParameter("journal_id", journalId),