Browse Source

feat: add webHooks definition queries that are available

pull/532/head
cKey 4 years ago
parent
commit
6a6eca4608
  1. 3
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhookSubscriptionAppService.cs
  2. 8
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhooksAvailableDto.cs
  3. 30
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionAppService.cs
  4. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSubscription.cs
  5. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionController.cs

3
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhookSubscriptionAppService.cs

@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.WebhooksManagement;
@ -11,4 +13,5 @@ public interface IWebhookSubscriptionAppService :
WebhookSubscriptionCreateInput,
WebhookSubscriptionUpdateInput>
{
Task<ListResultDto<WebhooksAvailableDto>> GetAllAvailableWebhooksAsync();
}

8
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhooksAvailableDto.cs

@ -0,0 +1,8 @@
namespace LINGYUN.Abp.WebhooksManagement;
public class WebhooksAvailableDto
{
public string Name { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
}

30
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionAppService.cs

@ -1,8 +1,10 @@
using LINGYUN.Abp.WebhooksManagement.Authorization;
using LINGYUN.Abp.Webhooks;
using LINGYUN.Abp.WebhooksManagement.Authorization;
using LINGYUN.Abp.WebhooksManagement.Extensions;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp;
@ -13,11 +15,14 @@ namespace LINGYUN.Abp.WebhooksManagement;
[Authorize(WebhooksManagementPermissions.WebhookSubscription.Default)]
public class WebhookSubscriptionAppService : WebhooksManagementAppServiceBase, IWebhookSubscriptionAppService
{
protected IWebhookDefinitionManager WebhookDefinitionManager { get; }
protected IWebhookSubscriptionRepository SubscriptionRepository { get; }
public WebhookSubscriptionAppService(
IWebhookDefinitionManager webhookDefinitionManager,
IWebhookSubscriptionRepository subscriptionRepository)
{
WebhookDefinitionManager = webhookDefinitionManager;
SubscriptionRepository = subscriptionRepository;
}
@ -85,9 +90,11 @@ public class WebhookSubscriptionAppService : WebhooksManagementAppServiceBase, I
await CheckSubscribedAsync(input);
}
subscription.SetSecret(input.Secret);
subscription.SetWebhookUri(input.WebhookUri);
subscription.SetWebhooks(input.ToSubscribedWebhooksString());
subscription.SetHeaders(input.ToWebhookHeadersString());
subscription.IsActive = input.IsActive;
await SubscriptionRepository.UpdateAsync(subscription);
@ -96,6 +103,27 @@ public class WebhookSubscriptionAppService : WebhooksManagementAppServiceBase, I
return subscription.ToWebhookSubscriptionDto();
}
public async virtual Task<ListResultDto<WebhooksAvailableDto>> GetAllAvailableWebhooksAsync()
{
var webhooks = WebhookDefinitionManager.GetAll();
var definitions = new List<WebhooksAvailableDto>();
foreach (var webhookDefinition in webhooks)
{
if (await WebhookDefinitionManager.IsAvailableAsync(CurrentTenant.Id, webhookDefinition.Name))
{
definitions.Add(new WebhooksAvailableDto
{
Name = webhookDefinition.Name,
Description = webhookDefinition.Description?.Localize(StringLocalizerFactory),
DisplayName = webhookDefinition.DisplayName?.Localize(StringLocalizerFactory)
});
}
}
return new ListResultDto<WebhooksAvailableDto>(definitions.OrderBy(d => d.Name).ToList());
}
protected async virtual Task CheckSubscribedAsync(WebhookSubscriptionCreateOrUpdateInput input)
{
foreach (var webhookName in input.Webhooks)

7
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSubscription.cs

@ -23,7 +23,7 @@ public class WebhookSubscription : CreationAuditedEntity<Guid>
string headers,
Guid? tenantId = null) : base(id)
{
Secret = Check.NotNullOrWhiteSpace(secret, nameof(secret), WebhookSubscriptionConsts.MaxSecretLength);
SetSecret(secret);
SetWebhookUri(webhookUri);
SetWebhooks(webhooks);
SetHeaders(headers);
@ -32,6 +32,11 @@ public class WebhookSubscription : CreationAuditedEntity<Guid>
IsActive = true;
}
public void SetSecret(string secret)
{
Secret = Check.NotNullOrWhiteSpace(secret, nameof(secret), WebhookSubscriptionConsts.MaxSecretLength);
}
public void SetWebhookUri(string webhookUri)
{
WebhookUri = Check.NotNullOrWhiteSpace(webhookUri, nameof(webhookUri), WebhookSubscriptionConsts.MaxWebhookUriLength);

7
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionController.cs

@ -56,4 +56,11 @@ public class WebhookSubscriptionController : WebhooksManagementControllerBase, I
{
return SubscriptionAppService.UpdateAsync(id, input);
}
[HttpGet]
[Route("availables")]
public Task<ListResultDto<WebhooksAvailableDto>> GetAllAvailableWebhooksAsync()
{
return SubscriptionAppService.GetAllAvailableWebhooksAsync();
}
}

Loading…
Cancel
Save