-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement update and delete apis for ComplexFormTypes and sync them i…
…n CrdtFwdataProjectSyncService
- Loading branch information
Showing
15 changed files
with
210 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using MiniLcm.Models; | ||
using SystemTextJsonPatch; | ||
|
||
namespace MiniLcm.SyncHelpers; | ||
|
||
public static class ComplexFormTypeSync | ||
{ | ||
public static async Task<int> Sync(ComplexFormType[] afterComplexFormTypes, | ||
ComplexFormType[] beforeComplexFormTypes, | ||
IMiniLcmApi api) | ||
{ | ||
return await DiffCollection.Diff(api, | ||
beforeComplexFormTypes, | ||
afterComplexFormTypes, | ||
complexFormType => complexFormType.Id, | ||
static async (api, afterComplexFormType) => | ||
{ | ||
await api.CreateComplexFormType(afterComplexFormType); | ||
return 1; | ||
}, | ||
static async (api, beforeComplexFormType) => | ||
{ | ||
await api.DeleteComplexFormType(beforeComplexFormType.Id); | ||
return 1; | ||
}, | ||
static (api, beforeComplexFormType, afterComplexFormType) => Sync(beforeComplexFormType, afterComplexFormType, api)); | ||
} | ||
|
||
public static async Task<int> Sync(ComplexFormType before, | ||
ComplexFormType after, | ||
IMiniLcmApi api) | ||
{ | ||
var updateObjectInput = ComplexFormTypeDiffToUpdate(before, after); | ||
if (updateObjectInput is not null) await api.UpdateComplexFormType(after.Id, updateObjectInput); | ||
return updateObjectInput is null ? 0 : 1; | ||
} | ||
|
||
public static UpdateObjectInput<ComplexFormType>? ComplexFormTypeDiffToUpdate(ComplexFormType before, ComplexFormType after) | ||
{ | ||
JsonPatchDocument<ComplexFormType> patchDocument = new(); | ||
patchDocument.Operations.AddRange(MultiStringDiff.GetMultiStringDiff<ComplexFormType>(nameof(ComplexFormType.Name), | ||
before.Name, | ||
after.Name)); | ||
if (patchDocument.Operations.Count == 0) return null; | ||
return new UpdateObjectInput<ComplexFormType>(patchDocument); | ||
} | ||
} |