diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs index 348754469..bc143f845 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs @@ -270,6 +270,12 @@ public Task UpdatePartOfSpeech(Guid id, UpdateObjectInput UpdatePartOfSpeech(PartOfSpeech before, PartOfSpeech after) + { + await PartOfSpeechSync.Sync(before, after, this); + return await GetPartOfSpeech(after.Id) ?? throw new NullReferenceException($"unable to find part of speech with id {after.Id}"); + } + public Task DeletePartOfSpeech(Guid id) { UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Delete Part of Speech", @@ -341,6 +347,12 @@ public Task UpdateSemanticDomain(Guid id, UpdateObjectInput UpdateSemanticDomain(SemanticDomain before, SemanticDomain after) + { + await SemanticDomainSync.Sync(before, after, this); + return await GetSemanticDomain(after.Id) ?? throw new NullReferenceException($"unable to find semantic domain with id {after.Id}"); + } + public Task DeleteSemanticDomain(Guid id) { UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Delete Semantic Domain", diff --git a/backend/FwLite/FwLiteProjectSync/DryRunMiniLcmApi.cs b/backend/FwLite/FwLiteProjectSync/DryRunMiniLcmApi.cs index 21dd0a39c..f23161649 100644 --- a/backend/FwLite/FwLiteProjectSync/DryRunMiniLcmApi.cs +++ b/backend/FwLite/FwLiteProjectSync/DryRunMiniLcmApi.cs @@ -62,6 +62,12 @@ public Task UpdatePartOfSpeech(Guid id, UpdateObjectInput UpdatePartOfSpeech(PartOfSpeech before, PartOfSpeech after) + { + DryRunRecords.Add(new DryRunRecord(nameof(UpdatePartOfSpeech), $"Update part of speech {after.Id}")); + return Task.FromResult(after); + } + public Task DeletePartOfSpeech(Guid id) { DryRunRecords.Add(new DryRunRecord(nameof(DeletePartOfSpeech), $"Delete part of speech {id}")); @@ -87,13 +93,19 @@ public Task CreateSemanticDomain(SemanticDomain semanticDomain) public Task UpdateSemanticDomain(Guid id, UpdateObjectInput update) { - DryRunRecords.Add(new DryRunRecord(nameof(UpdateSemanticDomain), $"Update part of speech {id}")); + DryRunRecords.Add(new DryRunRecord(nameof(UpdateSemanticDomain), $"Update semantic domain {id}")); return GetSemanticDomain(id)!; } + public Task UpdateSemanticDomain(SemanticDomain before, SemanticDomain after) + { + DryRunRecords.Add(new DryRunRecord(nameof(UpdateSemanticDomain), $"Update semantic domain {after.Id}")); + return Task.FromResult(after); + } + public Task DeleteSemanticDomain(Guid id) { - DryRunRecords.Add(new DryRunRecord(nameof(DeleteSemanticDomain), $"Delete part of speech {id}")); + DryRunRecords.Add(new DryRunRecord(nameof(DeleteSemanticDomain), $"Delete semantic domain {id}")); return Task.CompletedTask; } diff --git a/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs b/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs index 241c355f3..3a1fbd07c 100644 --- a/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs +++ b/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs @@ -104,6 +104,12 @@ public async Task UpdatePartOfSpeech(Guid id, UpdateObjectInput UpdatePartOfSpeech(PartOfSpeech before, PartOfSpeech after) + { + await PartOfSpeechSync.Sync(before, after, this); + return await GetPartOfSpeech(after.Id) ?? throw new NullReferenceException($"unable to find part of speech with id {after.Id}"); + } + public async Task DeletePartOfSpeech(Guid id) { await dataModel.AddChange(ClientId, new DeleteChange(id)); @@ -134,6 +140,12 @@ public async Task UpdateSemanticDomain(Guid id, UpdateObjectInpu return await GetSemanticDomain(id) ?? throw new NullReferenceException(); } + public async Task UpdateSemanticDomain(SemanticDomain before, SemanticDomain after) + { + await SemanticDomainSync.Sync(before, after, this); + return await GetSemanticDomain(after.Id) ?? throw new NullReferenceException($"unable to find semantic domain with id {after.Id}"); + } + public async Task DeleteSemanticDomain(Guid id) { await dataModel.AddChange(ClientId, new DeleteChange(id)); diff --git a/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs b/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs index 32d185fef..930b2bb75 100644 --- a/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs +++ b/backend/FwLite/MiniLcm/IMiniLcmWriteApi.cs @@ -17,12 +17,14 @@ Task UpdateWritingSystem(WritingSystemId id, #region PartOfSpeech Task CreatePartOfSpeech(PartOfSpeech partOfSpeech); Task UpdatePartOfSpeech(Guid id, UpdateObjectInput update); + Task UpdatePartOfSpeech(PartOfSpeech before, PartOfSpeech after); Task DeletePartOfSpeech(Guid id); #endregion #region SemanticDomain Task CreateSemanticDomain(SemanticDomain semanticDomain); Task UpdateSemanticDomain(Guid id, UpdateObjectInput update); + Task UpdateSemanticDomain(SemanticDomain before, SemanticDomain after); Task DeleteSemanticDomain(Guid id); #endregion diff --git a/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs b/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs index f5bff17e0..9a7cf0bba 100644 --- a/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs +++ b/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs @@ -23,12 +23,16 @@ public static async Task Sync(PartOfSpeech[] currentPartsOfSpeech, await api.DeletePartOfSpeech(previousPos.Id); return 1; }, - async (api, previousPos, currentPos) => - { - var updateObjectInput = PartOfSpeechDiffToUpdate(previousPos, currentPos); - if (updateObjectInput is not null) await api.UpdatePartOfSpeech(currentPos.Id, updateObjectInput); - return updateObjectInput is null ? 0 : 1; - }); + (api, previousPos, currentPos) => Sync(previousPos, currentPos, api)); + } + + public static async Task Sync(PartOfSpeech before, + PartOfSpeech after, + IMiniLcmApi api) + { + var updateObjectInput = PartOfSpeechDiffToUpdate(before, after); + if (updateObjectInput is not null) await api.UpdatePartOfSpeech(after.Id, updateObjectInput); + return updateObjectInput is null ? 0 : 1; } public static UpdateObjectInput? PartOfSpeechDiffToUpdate(PartOfSpeech previousPartOfSpeech, PartOfSpeech currentPartOfSpeech) diff --git a/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs b/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs index d1e150d95..3892e8ed1 100644 --- a/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs +++ b/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs @@ -23,12 +23,16 @@ public static async Task Sync(SemanticDomain[] currentSemanticDomains, await api.DeleteSemanticDomain(previousPos.Id); return 1; }, - async (api, previousPos, currentPos) => - { - var updateObjectInput = SemanticDomainDiffToUpdate(previousPos, currentPos); - if (updateObjectInput is not null) await api.UpdateSemanticDomain(currentPos.Id, updateObjectInput); - return updateObjectInput is null ? 0 : 1; - }); + (api, previousSemdom, currentSemdom) => Sync(previousSemdom, currentSemdom, api)); + } + + public static async Task Sync(SemanticDomain before, + SemanticDomain after, + IMiniLcmApi api) + { + var updateObjectInput = SemanticDomainDiffToUpdate(before, after); + if (updateObjectInput is not null) await api.UpdateSemanticDomain(after.Id, updateObjectInput); + return updateObjectInput is null ? 0 : 1; } public static UpdateObjectInput? SemanticDomainDiffToUpdate(SemanticDomain previousSemanticDomain, SemanticDomain currentSemanticDomain)