Skip to content

Commit

Permalink
Webhook Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Apr 15, 2024
1 parent 6af500a commit ed8fd54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions uSync.BackOffice/SyncHandlers/Handlers/WebhookHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

namespace uSync.BackOffice.SyncHandlers.Handlers;

/// <summary>
/// handler for webhook events.
/// </summary>
[SyncHandler(uSyncConstants.Handlers.WebhookHandler, "Webhooks", "Webhooks",
uSyncConstants.Priorites.Webhooks,
Icon = "icon-filter-arrows",
Expand All @@ -35,6 +38,9 @@ public class WebhookHandler : SyncHandlerRoot<IWebhook, IWebhook>, ISyncHandler,
{
private readonly IWebhookService _webhookService;

/// <summary>
/// constructor
/// </summary>
public WebhookHandler(
ILogger<SyncHandlerRoot<IWebhook, IWebhook>> logger,
AppCaches appCaches,
Expand All @@ -49,11 +55,13 @@ public WebhookHandler(
_webhookService = webhookService;
}

/// <inheritdoc/>
protected override IEnumerable<uSyncAction> DeleteMissingItems(IWebhook parent, IEnumerable<Guid> keysToKeep, bool reportOnly)
{
return [];
}

/// <inheritdoc/>
protected override IEnumerable<IWebhook> GetChildItems(IWebhook parent)
{
if (parent == null)
Expand All @@ -64,10 +72,13 @@ protected override IEnumerable<IWebhook> GetChildItems(IWebhook parent)
return [];
}

/// <inheritdoc/>
protected override IEnumerable<IWebhook> GetFolders(IWebhook parent) => [];

/// <inheritdoc/>
protected override IWebhook GetFromService(IWebhook item)
=> _webhookService.GetAsync(item.Key).Result;

/// <inheritdoc/>
protected override string GetItemName(IWebhook item) => item.Key.ToString();
}
12 changes: 10 additions & 2 deletions uSync.Core/Serialization/Serializers/WebhookSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Linq;
using System.Xml.Linq;

using Lucene.Net.Queries.Function.ValueSources;

using Microsoft.Extensions.Logging;

using Umbraco.Cms.Core.Models;
Expand All @@ -14,6 +12,9 @@

namespace uSync.Core.Serialization.Serializers;

/// <summary>
/// serializing webhook events
/// </summary>
[SyncSerializer("ED18C89D-A9FF-4217-9F8E-6898CA63ED81", "Webhook Serializer", uSyncConstants.Serialization.Webhook, IsTwoPass = false)]
public class WebhookSerializer : SyncSerializerBase<IWebhook>, ISyncSerializer<IWebhook>
{
Expand All @@ -28,16 +29,20 @@ public WebhookSerializer(
_webhookService = webhookService;
}

/// <inheritdoc/>
public override void DeleteItem(IWebhook item)
{
_webhookService.DeleteAsync(item.Key).Wait();
}

/// <inheritdoc/>
public override IWebhook FindItem(int id) => null;

/// <inheritdoc/>
public override IWebhook FindItem(Guid key)
=> _webhookService.GetAsync(key).Result;

/// <inheritdoc/>
public override IWebhook FindItem(string alias)
{
if (Guid.TryParse(alias, out Guid key))
Expand All @@ -46,9 +51,11 @@ public override IWebhook FindItem(string alias)
return null;
}

/// <inheritdoc/>
public override string ItemAlias(IWebhook item)
=> item.Key.ToString();

/// <inheritdoc/>
public override void SaveItem(IWebhook item)
{
if (item.Id > 0)
Expand All @@ -61,6 +68,7 @@ public override void SaveItem(IWebhook item)
}
}

/// <inheritdoc/>
protected override SyncAttempt<IWebhook> DeserializeCore(XElement node, SyncSerializerOptions options)
{
var key = node.GetKey();
Expand Down

0 comments on commit ed8fd54

Please sign in to comment.