Skip to content

Commit

Permalink
adjust models to match sync API response for serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pokornyd committed Oct 24, 2023
1 parent d108042 commit bae868a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
25 changes: 1 addition & 24 deletions Kontent.Ai.Delivery.Abstractions/Sync/ISyncItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,7 @@ namespace Kontent.Ai.Delivery.Abstractions;
/// </summary>
public interface ISyncItem
{
/// <summary>
/// Gets the content item's codename.
/// </summary>
string Codename { get; }

/// <summary>
/// Gets the content item's internal ID.
/// </summary>
Guid Id { get; }

/// <summary>
/// Gets the content item's type codename.
/// </summary>
string Type { get; }

/// <summary>
/// Gets the codename of the language that the content is in.
/// </summary>
string Language { get; }

/// <summary>
/// Gets the content item's collection codename. For projects without collections enabled, the value is default.
/// </summary>
string Collection { get; }
ISyncItemData Data { get; }

/// <summary>
/// Gets the information whether the content item was modified or deleted since the last synchronization.
Expand Down
12 changes: 12 additions & 0 deletions Kontent.Ai.Delivery.Abstractions/Sync/ISyncItemData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace Kontent.Ai.Delivery.Abstractions;

/// <summary>
/// Represents a delta update.
/// </summary>
public interface ISyncItemData
{
IContentItemSystemAttributes System { get; }
object Elements { get; }
}
36 changes: 9 additions & 27 deletions Kontent.Ai.Delivery/Sync/SyncItem.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
using System;
using System.Collections.Generic;
using Kontent.Ai.Delivery.Abstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Kontent.Ai.Delivery.Sync;

/// <inheritdoc/>
public class SyncItem : ISyncItem
internal sealed class SyncItem : ISyncItem
{
/// <inheritdoc/>
[JsonProperty("codename")]
public string Codename { get; internal set; }
[JsonProperty("data")]
public ISyncItemData Data { get; internal set; }

/// <inheritdoc/>
[JsonProperty("id")]
public Guid Id { get; internal set; }

/// <inheritdoc/>
[JsonProperty("type")]
public string Type { get; internal set; }

/// <inheritdoc/>
[JsonProperty("language")]
public string Language { get; internal set; }

/// <inheritdoc/>
[JsonProperty("collection")]
public string Collection { get; internal set; }

/// <inheritdoc/>
[JsonProperty("change_type")]
public string ChangeType { get; internal set; }

/// <inheritdoc/>
[JsonProperty("timestamp")]
public DateTime Timestamp { get; internal set; }

/// <summary>
/// Constructor used for deserialization (e.g. for caching purposes), contains no logic.
/// </summary>
[JsonConstructor]
public SyncItem()
{
public SyncItem(ISyncItemData data, string changeType, DateTime timestamp) {
Data = data;
ChangeType = changeType;
Timestamp = timestamp;
}
}
22 changes: 22 additions & 0 deletions Kontent.Ai.Delivery/Sync/SyncItemData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using Kontent.Ai.Delivery.Abstractions;
using Kontent.Ai.Delivery.ContentTypes.Element;
using Newtonsoft.Json;

namespace Kontent.Ai.Delivery.Sync
{
public class SyncItemData : ISyncItemData
{
[JsonProperty("system")]
public IContentItemSystemAttributes System { get; internal set; }

[JsonProperty("elements")]
public object Elements { get; internal set; }

[JsonConstructor]
public SyncItemData()
{
}
}
}

0 comments on commit bae868a

Please sign in to comment.