Skip to content

Commit

Permalink
Update names: previous => before, current => after
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Dec 4, 2024
1 parent 98c43ed commit 613a1cd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
24 changes: 12 additions & 12 deletions backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ namespace MiniLcm.SyncHelpers;

public static class PartOfSpeechSync
{
public static async Task<int> Sync(PartOfSpeech[] previousPartsOfSpeech,
PartOfSpeech[] currentPartsOfSpeech,
public static async Task<int> 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<int> Sync(PartOfSpeech before,
Expand All @@ -35,12 +35,12 @@ public static async Task<int> Sync(PartOfSpeech before,
return updateObjectInput is null ? 0 : 1;
}

public static UpdateObjectInput<PartOfSpeech>? PartOfSpeechDiffToUpdate(PartOfSpeech previousPartOfSpeech, PartOfSpeech currentPartOfSpeech)
public static UpdateObjectInput<PartOfSpeech>? PartOfSpeechDiffToUpdate(PartOfSpeech beforePartOfSpeech, PartOfSpeech afterPartOfSpeech)
{
JsonPatchDocument<PartOfSpeech> patchDocument = new();
patchDocument.Operations.AddRange(MultiStringDiff.GetMultiStringDiff<PartOfSpeech>(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<PartOfSpeech>(nameof(PartOfSpeech.Abbreviation),
// previousPartOfSpeech.Abbreviation,
Expand Down
24 changes: 12 additions & 12 deletions backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ namespace MiniLcm.SyncHelpers;

public static class SemanticDomainSync
{
public static async Task<int> Sync(SemanticDomain[] previousSemanticDomains,
SemanticDomain[] currentSemanticDomains,
public static async Task<int> 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<int> Sync(SemanticDomain before,
Expand All @@ -35,12 +35,12 @@ public static async Task<int> Sync(SemanticDomain before,
return updateObjectInput is null ? 0 : 1;
}

public static UpdateObjectInput<SemanticDomain>? SemanticDomainDiffToUpdate(SemanticDomain previousSemanticDomain, SemanticDomain currentSemanticDomain)
public static UpdateObjectInput<SemanticDomain>? SemanticDomainDiffToUpdate(SemanticDomain beforeSemanticDomain, SemanticDomain afterSemanticDomain)
{
JsonPatchDocument<SemanticDomain> patchDocument = new();
patchDocument.Operations.AddRange(MultiStringDiff.GetMultiStringDiff<SemanticDomain>(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<SemanticDomain>(nameof(SemanticDomain.Abbreviation),
// previousSemanticDomain.Abbreviation,
Expand Down
46 changes: 23 additions & 23 deletions backend/FwLite/MiniLcm/SyncHelpers/WritingSystemSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ namespace MiniLcm.SyncHelpers;

public static class WritingSystemSync
{
public static async Task<int> Sync(WritingSystems previousWritingSystems,
WritingSystems currentWritingSystems,
public static async Task<int> 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<int> Sync(WritingSystem[] previousWritingSystems,
WritingSystem[] currentWritingSystems,
public static async Task<int> 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);
});
}

Expand All @@ -44,23 +44,23 @@ public static async Task<int> Sync(WritingSystem beforeWs, WritingSystem afterWs
return updateObjectInput is null ? 0 : 1;
}

public static UpdateObjectInput<WritingSystem>? WritingSystemDiffToUpdate(WritingSystem previousWritingSystem, WritingSystem currentWritingSystem)
public static UpdateObjectInput<WritingSystem>? WritingSystemDiffToUpdate(WritingSystem beforeWritingSystem, WritingSystem afterWritingSystem)
{
JsonPatchDocument<WritingSystem> 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<WritingSystem>(nameof(WritingSystem.Name),
previousWritingSystem.Name,
currentWritingSystem.Name));
beforeWritingSystem.Name,
afterWritingSystem.Name));
patchDocument.Operations.AddRange(SimpleStringDiff.GetStringDiff<WritingSystem>(nameof(WritingSystem.Abbreviation),
previousWritingSystem.Abbreviation,
currentWritingSystem.Abbreviation));
beforeWritingSystem.Abbreviation,
afterWritingSystem.Abbreviation));
patchDocument.Operations.AddRange(SimpleStringDiff.GetStringDiff<WritingSystem>(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<WritingSystem>(patchDocument);
Expand Down

0 comments on commit 613a1cd

Please sign in to comment.