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 authored and myieye committed Dec 18, 2024
1 parent 1cbc542 commit 95bde8a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
26 changes: 13 additions & 13 deletions backend/FwLite/MiniLcm/SyncHelpers/PartOfSpeechSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ 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(
previousPartsOfSpeech,
currentPartsOfSpeech,
beforePartsOfSpeech,
afterPartsOfSpeech,
new PartsOfSpeechDiffApi(api));
}

Expand All @@ -24,16 +24,16 @@ 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,
// currentPartOfSpeech.Abbreviation));
// beforePartOfSpeech.Abbreviation,
// afterPartOfSpeech.Abbreviation));
if (patchDocument.Operations.Count == 0) return null;
return new UpdateObjectInput<PartOfSpeech>(patchDocument);
}
Expand All @@ -46,15 +46,15 @@ public override async Task<int> Add(PartOfSpeech currentPos)
return 1;
}

public override async Task<int> Remove(PartOfSpeech previousPos)
public override async Task<int> Remove(PartOfSpeech beforePos)
{
await api.DeletePartOfSpeech(previousPos.Id);
await api.DeletePartOfSpeech(beforePos.Id);
return 1;
}

public override Task<int> Replace(PartOfSpeech previousPos, PartOfSpeech currentPos)
public override Task<int> Replace(PartOfSpeech beforePos, PartOfSpeech afterPos)
{
return Sync(previousPos, currentPos, api);
return Sync(beforePos, afterPos, api);
}
}
}
26 changes: 13 additions & 13 deletions backend/FwLite/MiniLcm/SyncHelpers/SemanticDomainSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ 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(
previousSemanticDomains,
currentSemanticDomains,
beforeSemanticDomains,
afterSemanticDomains,
new SemanticDomainsDiffApi(api));
}

Expand All @@ -24,16 +24,16 @@ 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,
// currentSemanticDomain.Abbreviation));
// beforeSemanticDomain.Abbreviation,
// afterSemanticDomain.Abbreviation));
if (patchDocument.Operations.Count == 0) return null;
return new UpdateObjectInput<SemanticDomain>(patchDocument);
}
Expand All @@ -46,15 +46,15 @@ public override async Task<int> Add(SemanticDomain currentSemDom)
return 1;
}

public override async Task<int> Remove(SemanticDomain previousSemDom)
public override async Task<int> Remove(SemanticDomain beforeSemDom)
{
await api.DeleteSemanticDomain(previousSemDom.Id);
await api.DeleteSemanticDomain(beforeSemDom.Id);
return 1;
}

public override Task<int> Replace(SemanticDomain previousSemDom, SemanticDomain currentSemDom)
public override Task<int> Replace(SemanticDomain beforeSemDom, SemanticDomain afterSemDom)
{
return Sync(previousSemDom, currentSemDom, api);
return Sync(beforeSemDom, afterSemDom, api);
}
}
}
42 changes: 21 additions & 21 deletions backend/FwLite/MiniLcm/SyncHelpers/WritingSystemSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ 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(
previousWritingSystems,
currentWritingSystems,
beforeWritingSystems,
afterWritingSystems,
new WritingSystemsDiffApi(api));
}

Expand All @@ -29,23 +29,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 All @@ -64,16 +64,16 @@ public override async Task<int> Add(WritingSystem currentWs)
return 1;
}

public override Task<int> Remove(WritingSystem beforeDomain)
public override Task<int> Remove(WritingSystem 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 Task.FromResult(0);
}

public override Task<int> Replace(WritingSystem previousWs, WritingSystem currentWs)
public override Task<int> Replace(WritingSystem beforeWs, WritingSystem afterWs)
{
return Sync(previousWs, currentWs, api);
return Sync(beforeWs, afterWs, api);
}
}
}

0 comments on commit 95bde8a

Please sign in to comment.