Anapher/Strive

View on GitHub
src/Services/ConferenceManagement/Strive.Infrastructure/Utilities/CanvasActionUtils.cs

Summary

Maintainability
A
0 mins
Test Coverage
using JsonPatchGenerator;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.Operations;
using Strive.Core.Services.WhiteboardService;
using Strive.Core.Services.WhiteboardService.CanvasData;
using Strive.Infrastructure.Serialization;

namespace Strive.Infrastructure.Utilities
{
    public class CanvasActionUtils : ICanvasActionUtils
    {
        public JsonPatchDocument<CanvasObject> CreatePatch(CanvasObject original, CanvasObject modified)
        {
            var patch = JsonPatchFactory.Create(original, modified, JsonConfig.Default,
                JsonPatchFactory.DefaultOptions);

            var typedPatch = new JsonPatchDocument<CanvasObject>();
            foreach (var operation in patch.Operations)
            {
                typedPatch.Operations.Add(new Operation<CanvasObject>(operation.op, operation.path, operation.from,
                    operation.value));
            }

            return typedPatch;
        }
    }
}