diff --git a/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs b/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs index ccc16dfcd..2ea26691a 100644 --- a/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs +++ b/backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs @@ -5,25 +5,25 @@ namespace MiniLcm.SyncHelpers; public static class PartOfSpeechSync { - public static async Task Sync(PartOfSpeech[] previousPartsOfSpeech, - PartOfSpeech[] currentPartsOfSpeech, + public static async Task Sync(PartOfSpeech[] beforePartsOfSpeech, + PartOfSpeech[] afterPartsOfSpeech, IMiniLcmApi api) { return await DiffCollection.Diff(api, - previousPartsOfSpeech, - currentPartsOfSpeech, + beforePartsOfSpeech, + afterPartsOfSpeech, pos => pos.Id, - async (api, currentPos) => + async (api, afterPos) => { - await api.CreatePartOfSpeech(currentPos); + await api.CreatePartOfSpeech(afterPos); return 1; }, - async (api, previousPos) => + async (api, beforePos) => { - await api.DeletePartOfSpeech(previousPos.Id); + await api.DeletePartOfSpeech(beforePos.Id); return 1; }, - (api, previousPos, currentPos) => Sync(previousPos, currentPos, api)); + (api, beforePos, afterPos) => Sync(beforePos, afterPos, api)); } public static async Task Sync(PartOfSpeech before, @@ -35,12 +35,12 @@ public static async Task Sync(PartOfSpeech before, return updateObjectInput is null ? 0 : 1; } - public static UpdateObjectInput? PartOfSpeechDiffToUpdate(PartOfSpeech previousPartOfSpeech, PartOfSpeech currentPartOfSpeech) + public static UpdateObjectInput? PartOfSpeechDiffToUpdate(PartOfSpeech beforePartOfSpeech, PartOfSpeech afterPartOfSpeech) { JsonPatchDocument patchDocument = new(); patchDocument.Operations.AddRange(MultiStringDiff.GetMultiStringDiff(nameof(PartOfSpeech.Name), - previousPartOfSpeech.Name, - currentPartOfSpeech.Name)); + beforePartOfSpeech.Name, + afterPartOfSpeech.Name)); // TODO: Once we add abbreviations to MiniLcm's PartOfSpeech objects, then: // patchDocument.Operations.AddRange(GetMultiStringDiff(nameof(PartOfSpeech.Abbreviation), // previousPartOfSpeech.Abbreviation, diff --git a/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs b/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs index 582386660..93c58f89b 100644 --- a/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs +++ b/backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs @@ -5,25 +5,25 @@ namespace MiniLcm.SyncHelpers; public static class SemanticDomainSync { - public static async Task Sync(SemanticDomain[] previousSemanticDomains, - SemanticDomain[] currentSemanticDomains, + public static async Task Sync(SemanticDomain[] beforeSemanticDomains, + SemanticDomain[] afterSemanticDomains, IMiniLcmApi api) { return await DiffCollection.Diff(api, - previousSemanticDomains, - currentSemanticDomains, + beforeSemanticDomains, + afterSemanticDomains, pos => pos.Id, - async (api, currentPos) => + async (api, afterPos) => { - await api.CreateSemanticDomain(currentPos); + await api.CreateSemanticDomain(afterPos); return 1; }, - async (api, previousPos) => + async (api, beforePos) => { - await api.DeleteSemanticDomain(previousPos.Id); + await api.DeleteSemanticDomain(beforePos.Id); return 1; }, - (api, previousSemdom, currentSemdom) => Sync(previousSemdom, currentSemdom, api)); + (api, beforeSemdom, afterSemdom) => Sync(beforeSemdom, afterSemdom, api)); } public static async Task Sync(SemanticDomain before, @@ -35,12 +35,12 @@ public static async Task Sync(SemanticDomain before, return updateObjectInput is null ? 0 : 1; } - public static UpdateObjectInput? SemanticDomainDiffToUpdate(SemanticDomain previousSemanticDomain, SemanticDomain currentSemanticDomain) + public static UpdateObjectInput? SemanticDomainDiffToUpdate(SemanticDomain beforeSemanticDomain, SemanticDomain afterSemanticDomain) { JsonPatchDocument patchDocument = new(); patchDocument.Operations.AddRange(MultiStringDiff.GetMultiStringDiff(nameof(SemanticDomain.Name), - previousSemanticDomain.Name, - currentSemanticDomain.Name)); + beforeSemanticDomain.Name, + afterSemanticDomain.Name)); // TODO: Once we add abbreviations to MiniLcm's SemanticDomain objects, then: // patchDocument.Operations.AddRange(GetMultiStringDiff(nameof(SemanticDomain.Abbreviation), // previousSemanticDomain.Abbreviation, diff --git a/backend/FwLite/MiniLcm/SyncHelpers/WritingSystemSync.cs b/backend/FwLite/MiniLcm/SyncHelpers/WritingSystemSync.cs index 34cb2124a..71ebc684e 100644 --- a/backend/FwLite/MiniLcm/SyncHelpers/WritingSystemSync.cs +++ b/backend/FwLite/MiniLcm/SyncHelpers/WritingSystemSync.cs @@ -5,35 +5,35 @@ namespace MiniLcm.SyncHelpers; public static class WritingSystemSync { - public static async Task Sync(WritingSystems previousWritingSystems, - WritingSystems currentWritingSystems, + public static async Task Sync(WritingSystems beforeWritingSystems, + WritingSystems afterWritingSystems, IMiniLcmApi api) { - return await Sync(previousWritingSystems.Vernacular, currentWritingSystems.Vernacular, api) + - await Sync(previousWritingSystems.Analysis, currentWritingSystems.Analysis, api); + return await Sync(beforeWritingSystems.Vernacular, afterWritingSystems.Vernacular, api) + + await Sync(beforeWritingSystems.Analysis, afterWritingSystems.Analysis, api); } - public static async Task Sync(WritingSystem[] previousWritingSystems, - WritingSystem[] currentWritingSystems, + public static async Task Sync(WritingSystem[] beforeWritingSystems, + WritingSystem[] afterWritingSystems, IMiniLcmApi api) { return await DiffCollection.Diff(api, - previousWritingSystems, - currentWritingSystems, + beforeWritingSystems, + afterWritingSystems, ws => (ws.WsId, ws.Type), - async (api, currentWs) => + async (api, afterWs) => { - await api.CreateWritingSystem(currentWs.Type, currentWs); + await api.CreateWritingSystem(afterWs.Type, afterWs); return 1; }, - async (api, previousWs) => + async (api, beforeWs) => { - // await api.DeleteWritingSystem(previousWs.Id); // Deleting writing systems is dangerous as it causes cascading data deletion. Needs careful thought. + // await api.DeleteWritingSystem(beforeWs.Id); // Deleting writing systems is dangerous as it causes cascading data deletion. Needs careful thought. // TODO: should we throw an exception? return 0; }, - async (api, previousWs, currentWs) => + async (api, beforeWs, afterWs) => { - return await Sync(previousWs, currentWs, api); + return await Sync(beforeWs, afterWs, api); }); } @@ -44,23 +44,23 @@ public static async Task Sync(WritingSystem beforeWs, WritingSystem afterWs return updateObjectInput is null ? 0 : 1; } - public static UpdateObjectInput? WritingSystemDiffToUpdate(WritingSystem previousWritingSystem, WritingSystem currentWritingSystem) + public static UpdateObjectInput? WritingSystemDiffToUpdate(WritingSystem beforeWritingSystem, WritingSystem afterWritingSystem) { JsonPatchDocument patchDocument = new(); - if (previousWritingSystem.WsId != currentWritingSystem.WsId) + if (beforeWritingSystem.WsId != afterWritingSystem.WsId) { // TODO: Throw? Or silently ignore? - throw new InvalidOperationException($"Tried to change immutable WsId from {previousWritingSystem.WsId} to {currentWritingSystem.WsId}"); + throw new InvalidOperationException($"Tried to change immutable WsId from {beforeWritingSystem.WsId} to {afterWritingSystem.WsId}"); } patchDocument.Operations.AddRange(SimpleStringDiff.GetStringDiff(nameof(WritingSystem.Name), - previousWritingSystem.Name, - currentWritingSystem.Name)); + beforeWritingSystem.Name, + afterWritingSystem.Name)); patchDocument.Operations.AddRange(SimpleStringDiff.GetStringDiff(nameof(WritingSystem.Abbreviation), - previousWritingSystem.Abbreviation, - currentWritingSystem.Abbreviation)); + beforeWritingSystem.Abbreviation, + afterWritingSystem.Abbreviation)); patchDocument.Operations.AddRange(SimpleStringDiff.GetStringDiff(nameof(WritingSystem.Font), - previousWritingSystem.Font, - currentWritingSystem.Font)); + beforeWritingSystem.Font, + afterWritingSystem.Font)); // TODO: Exemplars, Order, and do we need DeletedAt? if (patchDocument.Operations.Count == 0) return null; return new UpdateObjectInput(patchDocument);