48 changed files with 722 additions and 196 deletions
@ -0,0 +1,21 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Webhooks.Extensions |
||||
|
{ |
||||
|
public static class WebhookSubscriptionExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// checks if subscribed to given webhook
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public static bool IsSubscribed(this WebhookSubscriptionInfo webhookSubscription, string webhookName) |
||||
|
{ |
||||
|
if (webhookSubscription.Webhooks.IsNullOrEmpty()) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return webhookSubscription.Webhooks.Contains(webhookName); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,8 +1,8 @@ |
|||||
{ |
{ |
||||
"culture": "en", |
"culture": "en", |
||||
"texts": { |
"texts": { |
||||
"Features:WebhooksManagement": "WebhooksManagement", |
"Features:WebhooksManagement": "Webhooks", |
||||
"Permission:WebhooksManagement": "WebhooksManagement", |
"Permission:WebhooksManagement": "Webhooks", |
||||
"Permission:ManageSettings": "Manage Settings" |
"Permission:ManageSettings": "Manage Settings" |
||||
} |
} |
||||
} |
} |
||||
@ -1,8 +1,8 @@ |
|||||
{ |
{ |
||||
"culture": "zh-Hans", |
"culture": "zh-Hans", |
||||
"texts": { |
"texts": { |
||||
"Features:WebhooksManagement": "WebhooksManagement", |
"Features:WebhooksManagement": "Webhooks", |
||||
"Permission:WebhooksManagement": "WebhooksManagement", |
"Permission:WebhooksManagement": "Webhooks", |
||||
"Permission:ManageSettings": "管理设置" |
"Permission:ManageSettings": "管理设置" |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class WebhookEventEto : IMultiTenant |
||||
|
{ |
||||
|
public Guid Id { get; set; } |
||||
|
public Guid? TenantId { get; set; } |
||||
|
public string WebhookName { get; set; } |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public static class WebhookEventRecordConsts |
||||
|
{ |
||||
|
public static int MaxWebhookNameLength { get; set; } = 100; |
||||
|
public static int MaxDataLength { get; set; } = int.MaxValue; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class WebhookSendAttemptEto : IMultiTenant |
||||
|
{ |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
public Guid? TenantId { get; set; } |
||||
|
|
||||
|
public Guid WebhookEventId { get; set; } |
||||
|
|
||||
|
public Guid WebhookSubscriptionId { get; set; } |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public static class WebhookSendRecordConsts |
||||
|
{ |
||||
|
public static int MaxResponseLength { get; set; } = int.MaxValue; |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public static class WebhookSubscriptionConsts |
||||
|
{ |
||||
|
public static int MaxWebhookUriLength { get; set; } = 255; |
||||
|
public static int MaxSecretLength { get; set; } = 128; |
||||
|
public static int MaxWebhooksLength { get; set; } = int.MaxValue; |
||||
|
public static int MaxHeadersLength { get; set; } = int.MaxValue; |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class WebhookSubscriptionEto : IMultiTenant |
||||
|
{ |
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
public Guid? TenantId { get; set; } |
||||
|
|
||||
|
public string WebhookUri { get; set; } |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using LINGYUN.Abp.Webhooks; |
||||
|
using Newtonsoft.Json; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.Extensions |
||||
|
{ |
||||
|
public static class WebhookSubscriptionExtensions |
||||
|
{ |
||||
|
public static string ToSubscribedWebhooksString(this WebhookSubscriptionInfo webhookSubscription) |
||||
|
{ |
||||
|
if (webhookSubscription.Webhooks.Any()) |
||||
|
{ |
||||
|
return JsonConvert.SerializeObject(webhookSubscription.Webhooks); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public static string ToWebhookHeadersString(this WebhookSubscriptionInfo webhookSubscription) |
||||
|
{ |
||||
|
if (webhookSubscription.Headers.Any()) |
||||
|
{ |
||||
|
return JsonConvert.SerializeObject(webhookSubscription.Headers); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,175 @@ |
|||||
|
using LINGYUN.Abp.Webhooks; |
||||
|
using Newtonsoft.Json; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.Extensions |
||||
|
{ |
||||
|
public static class WebhookSubscriptionInfoExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Return List of subscribed webhooks definitions <see cref="WebhookSubscriptionInfo.Webhooks"/>
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public static List<string> GetSubscribedWebhooks(this WebhookSubscription webhookSubscription) |
||||
|
{ |
||||
|
if (webhookSubscription.Webhooks.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
return new List<string>(); |
||||
|
} |
||||
|
|
||||
|
return JsonConvert.DeserializeObject<List<string>>(webhookSubscription.Webhooks); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Adds webhook subscription to <see cref="WebhookSubscriptionInfo.Webhooks"/> if not exists
|
||||
|
/// </summary>
|
||||
|
/// <param name="webhookSubscription"></param>
|
||||
|
/// <param name="name">webhook unique name</param>
|
||||
|
public static void SubscribeWebhook(this WebhookSubscription webhookSubscription, string name) |
||||
|
{ |
||||
|
name = name.Trim(); |
||||
|
if (name.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(name), $"{nameof(name)} can not be null, empty or whitespace!"); |
||||
|
} |
||||
|
|
||||
|
var webhookDefinitions = webhookSubscription.GetSubscribedWebhooks(); |
||||
|
if (webhookDefinitions.Contains(name)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
webhookDefinitions.Add(name); |
||||
|
webhookSubscription.SetWebhooks(JsonConvert.SerializeObject(webhookDefinitions)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Removes webhook subscription from <see cref="WebhookSubscriptionInfo.Webhooks"/> if exists
|
||||
|
/// </summary>
|
||||
|
/// <param name="webhookSubscription"></param>
|
||||
|
/// <param name="name">webhook unique name</param>
|
||||
|
public static void UnsubscribeWebhook(this WebhookSubscription webhookSubscription, string name) |
||||
|
{ |
||||
|
name = name.Trim(); |
||||
|
if (name.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(name), $"{nameof(name)} can not be null, empty or whitespace!"); |
||||
|
} |
||||
|
|
||||
|
var webhookDefinitions = webhookSubscription.GetSubscribedWebhooks(); |
||||
|
if (!webhookDefinitions.Contains(name)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
webhookDefinitions.Remove(name); |
||||
|
webhookSubscription.SetWebhooks(JsonConvert.SerializeObject(webhookDefinitions)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Clears all <see cref="WebhookSubscriptionInfo.Webhooks"/>
|
||||
|
/// </summary>
|
||||
|
/// <param name="webhookSubscription"></param>
|
||||
|
public static void RemoveAllSubscribedWebhooks(this WebhookSubscription webhookSubscription) |
||||
|
{ |
||||
|
webhookSubscription.SetWebhooks(null); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// if subscribed to given webhook
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public static bool IsSubscribed(this WebhookSubscription webhookSubscription, string webhookName) |
||||
|
{ |
||||
|
if (webhookSubscription.Webhooks.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return webhookSubscription.GetSubscribedWebhooks().Contains(webhookName); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Returns additional webhook headers <see cref="WebhookSubscriptionInfo.Headers"/>
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
public static IDictionary<string, string> GetWebhookHeaders(this WebhookSubscription webhookSubscription) |
||||
|
{ |
||||
|
if (webhookSubscription.Headers.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
return new Dictionary<string, string>(); |
||||
|
} |
||||
|
|
||||
|
return JsonConvert.DeserializeObject<Dictionary<string, string>>(webhookSubscription.Headers); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Adds webhook subscription to <see cref="WebhookSubscriptionInfo.Webhooks"/> if not exists
|
||||
|
/// </summary>
|
||||
|
public static void AddWebhookHeader(this WebhookSubscription webhookSubscription, string key, string value) |
||||
|
{ |
||||
|
if (key.IsNullOrWhiteSpace() ) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(key), $"{nameof(key)} can not be null, empty or whitespace!"); |
||||
|
} |
||||
|
|
||||
|
if (value.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(value), $"{nameof(value)} can not be null, empty or whitespace!"); |
||||
|
} |
||||
|
|
||||
|
var headers = webhookSubscription.GetWebhookHeaders(); |
||||
|
headers[key] = value; |
||||
|
|
||||
|
webhookSubscription.SetHeaders(JsonConvert.SerializeObject(headers)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Adds webhook subscription to <see cref="WebhookSubscriptionInfo.Webhooks"/> if not exists
|
||||
|
/// </summary>
|
||||
|
/// <param name="webhookSubscription"></param>
|
||||
|
/// <param name="header">Key of header</param>
|
||||
|
public static void RemoveWebhookHeader(this WebhookSubscription webhookSubscription, string header) |
||||
|
{ |
||||
|
if (header.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(header), $"{nameof(header)} can not be null, empty or whitespace!"); |
||||
|
} |
||||
|
|
||||
|
var headers = webhookSubscription.GetWebhookHeaders(); |
||||
|
|
||||
|
if (!headers.ContainsKey(header)) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
headers.Remove(header); |
||||
|
|
||||
|
webhookSubscription.SetHeaders(JsonConvert.SerializeObject(headers)); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Clears all <see cref="WebhookSubscriptionInfo.Webhooks"/>
|
||||
|
/// </summary>
|
||||
|
/// <param name="webhookSubscription"></param>
|
||||
|
public static void RemoveAllWebhookHeaders(this WebhookSubscription webhookSubscription) |
||||
|
{ |
||||
|
webhookSubscription.SetHeaders(null); |
||||
|
} |
||||
|
|
||||
|
public static WebhookSubscriptionInfo ToWebhookSubscriptionInfo(this WebhookSubscription webhookSubscription) |
||||
|
{ |
||||
|
return new WebhookSubscriptionInfo |
||||
|
{ |
||||
|
Id = webhookSubscription.Id, |
||||
|
TenantId = webhookSubscription.TenantId, |
||||
|
IsActive = webhookSubscription.IsActive, |
||||
|
Secret = webhookSubscription.Secret, |
||||
|
WebhookUri = webhookSubscription.WebhookUri, |
||||
|
Webhooks = webhookSubscription.GetSubscribedWebhooks(), |
||||
|
Headers = webhookSubscription.GetWebhookHeaders() |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,55 +1,148 @@ |
|||||
using LINGYUN.Abp.Webhooks; |
using LINGYUN.Abp.Webhooks; |
||||
|
using LINGYUN.Abp.WebhooksManagement.Extensions; |
||||
|
using Newtonsoft.Json; |
||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Domain.Services; |
using Volo.Abp.Domain.Services; |
||||
|
using Volo.Abp.Uow; |
||||
|
|
||||
namespace LINGYUN.Abp.WebhooksManagement; |
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
public class WebhookSubscriptionsStore : DomainService, IWebhookSubscriptionsStore |
public class WebhookSubscriptionsStore : DomainService, IWebhookSubscriptionsStore |
||||
{ |
{ |
||||
public Task DeleteAsync(Guid id) |
protected IWebhookSubscriptionRepository SubscriptionRepository { get; } |
||||
|
|
||||
|
public WebhookSubscriptionsStore( |
||||
|
IWebhookSubscriptionRepository subscriptionRepository) |
||||
|
{ |
||||
|
SubscriptionRepository = subscriptionRepository; |
||||
|
} |
||||
|
|
||||
|
[UnitOfWork] |
||||
|
public async virtual Task DeleteAsync(Guid id) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
await SubscriptionRepository.DeleteAsync(id); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsAsync(Guid? tenantId) |
[UnitOfWork] |
||||
|
public async virtual Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsAsync(Guid? tenantId) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var queryable = await SubscriptionRepository.GetQueryableAsync(); |
||||
|
|
||||
|
var subscriptions = await AsyncExecuter.ToListAsync(queryable.Where(x => x.TenantId == tenantId)); |
||||
|
|
||||
|
return subscriptions.Select(subscription => subscription.ToWebhookSubscriptionInfo()).ToList(); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsAsync(Guid? tenantId, string webhookName) |
[UnitOfWork] |
||||
|
public async virtual Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsAsync(Guid? tenantId, string webhookName) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var queryable = await SubscriptionRepository.GetQueryableAsync(); |
||||
|
|
||||
|
var subscriptions = await AsyncExecuter.ToListAsync( |
||||
|
queryable.Where(x => |
||||
|
x.TenantId == tenantId && |
||||
|
x.IsActive && |
||||
|
x.Webhooks.Contains("\"" + webhookName + "\""))); |
||||
|
|
||||
|
return subscriptions.Select(subscription => subscription.ToWebhookSubscriptionInfo()).ToList(); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsOfTenantsAsync(Guid?[] tenantIds) |
[UnitOfWork] |
||||
|
public async virtual Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsOfTenantsAsync(Guid?[] tenantIds) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var queryable = await SubscriptionRepository.GetQueryableAsync(); |
||||
|
|
||||
|
var subscriptions = await AsyncExecuter.ToListAsync(queryable.Where(x => tenantIds.Contains(x.TenantId))); |
||||
|
|
||||
|
return subscriptions.Select(subscription => subscription.ToWebhookSubscriptionInfo()).ToList(); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsOfTenantsAsync(Guid?[] tenantIds, string webhookName) |
[UnitOfWork] |
||||
|
public async virtual Task<List<WebhookSubscriptionInfo>> GetAllSubscriptionsOfTenantsAsync(Guid?[] tenantIds, string webhookName) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var queryable = await SubscriptionRepository.GetQueryableAsync(); |
||||
|
|
||||
|
var subscriptions = await AsyncExecuter.ToListAsync( |
||||
|
queryable.Where(x => |
||||
|
x.IsActive && |
||||
|
tenantIds.Contains(x.TenantId) && |
||||
|
x.Webhooks.Contains("\"" + webhookName + "\""))); |
||||
|
|
||||
|
return subscriptions.Select(subscription => subscription.ToWebhookSubscriptionInfo()).ToList(); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task<WebhookSubscriptionInfo> GetAsync(Guid id) |
[UnitOfWork] |
||||
|
public async virtual Task<WebhookSubscriptionInfo> GetAsync(Guid id) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var subscription = await SubscriptionRepository.GetAsync(id); |
||||
|
|
||||
|
return subscription.ToWebhookSubscriptionInfo(); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task InsertAsync(WebhookSubscriptionInfo webhookSubscription) |
[UnitOfWork] |
||||
|
public async virtual Task InsertAsync(WebhookSubscriptionInfo webhookSubscription) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var subscription = new WebhookSubscription( |
||||
|
webhookSubscription.Id, |
||||
|
webhookSubscription.WebhookUri, |
||||
|
webhookSubscription.Secret, |
||||
|
JsonConvert.SerializeObject(webhookSubscription.Webhooks), |
||||
|
JsonConvert.SerializeObject(webhookSubscription.Headers), |
||||
|
webhookSubscription.TenantId); |
||||
|
|
||||
|
await SubscriptionRepository.InsertAsync(subscription); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task<bool> IsSubscribedAsync(Guid? tenantId, string webhookName) |
[UnitOfWork] |
||||
|
public async virtual Task<bool> IsSubscribedAsync(Guid? tenantId, string webhookName) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(null)) |
||||
|
{ |
||||
|
var queryable = await SubscriptionRepository.GetQueryableAsync(); |
||||
|
|
||||
|
return await AsyncExecuter.AnyAsync( |
||||
|
queryable.Where(x => |
||||
|
x.TenantId == tenantId && |
||||
|
x.IsActive && |
||||
|
x.Webhooks.Contains("\"" + webhookName + "\""))); |
||||
|
} |
||||
} |
} |
||||
|
|
||||
public Task UpdateAsync(WebhookSubscriptionInfo webhookSubscription) |
[UnitOfWork] |
||||
|
public async virtual Task UpdateAsync(WebhookSubscriptionInfo webhookSubscription) |
||||
{ |
{ |
||||
throw new NotImplementedException(); |
using (CurrentTenant.Change(webhookSubscription.TenantId)) |
||||
|
{ |
||||
|
var subscription = await SubscriptionRepository.GetAsync(webhookSubscription.Id); |
||||
|
subscription.SetWebhookUri(webhookSubscription.WebhookUri); |
||||
|
subscription.SetWebhooks(webhookSubscription.ToSubscribedWebhooksString()); |
||||
|
subscription.SetHeaders(webhookSubscription.ToWebhookHeadersString()); |
||||
|
|
||||
|
await SubscriptionRepository.UpdateAsync(subscription); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,15 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
||||
|
|
||||
|
public class EfCoreWebhookEventRecordRepository : |
||||
|
EfCoreRepository<IWebhooksManagementDbContext, WebhookEventRecord, Guid>, |
||||
|
IWebhookEventRecordRepository |
||||
|
{ |
||||
|
public EfCoreWebhookEventRecordRepository(IDbContextProvider<IWebhooksManagementDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Dynamic.Core; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
||||
|
|
||||
|
public class EfCoreWebhookSendRecordRepository : |
||||
|
EfCoreRepository<IWebhooksManagementDbContext, WebhookSendRecord, Guid>, |
||||
|
IWebhookSendRecordRepository |
||||
|
{ |
||||
|
public EfCoreWebhookSendRecordRepository( |
||||
|
IDbContextProvider<IWebhooksManagementDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async virtual Task<int> GetCountAsync( |
||||
|
WebhookSendRecordFilter filter, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await ApplyFilter(await GetDbSetAsync(), filter) |
||||
|
.CountAsync(GetCancellationToken(cancellationToken)); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public async virtual Task<List<WebhookSendRecord>> GetListAsync( |
||||
|
WebhookSendRecordFilter filter, |
||||
|
string sorting = "CreationTime", |
||||
|
int maxResultCount = 10, |
||||
|
int skipCount = 10, |
||||
|
bool includeDetails = false, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await ApplyFilter((await GetDbSetAsync()).IncludeDetails(includeDetails), filter) |
||||
|
.OrderBy(sorting ?? $"{nameof(WebhookSendRecord.CreationTime)} DESC") |
||||
|
.PageBy(skipCount, maxResultCount) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
protected virtual IQueryable<WebhookSendRecord> ApplyFilter( |
||||
|
IQueryable<WebhookSendRecord> queryable, |
||||
|
WebhookSendRecordFilter filter) |
||||
|
{ |
||||
|
return queryable |
||||
|
.WhereIf(filter.WebhookEventId.HasValue, x => x.WebhookEventId == filter.WebhookEventId) |
||||
|
.WhereIf(filter.SubscriptionId.HasValue, x => x.WebhookSubscriptionId == filter.SubscriptionId) |
||||
|
.WhereIf(filter.ResponseStatusCode.HasValue, x => x.ResponseStatusCode == filter.ResponseStatusCode) |
||||
|
.WhereIf(filter.BeginCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.BeginCreationTime) >= 0) |
||||
|
.WhereIf(filter.EndCreationTime.HasValue, x => x.CreationTime.CompareTo(filter.EndCreationTime) <= 0) |
||||
|
.WhereIf(!filter.Filter.IsNullOrWhiteSpace(), x => x.Response.Contains(filter.Filter)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
||||
|
|
||||
|
public class EfCoreWebhookSubscriptionRepository : |
||||
|
EfCoreRepository<IWebhooksManagementDbContext, WebhookSubscription, Guid>, |
||||
|
IWebhookSubscriptionRepository |
||||
|
{ |
||||
|
public EfCoreWebhookSubscriptionRepository( |
||||
|
IDbContextProvider<IWebhooksManagementDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -1,6 +1,19 @@ |
|||||
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
using Microsoft.EntityFrameworkCore; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
||||
|
|
||||
public static class WebhooksManagementEfCoreQueryableExtensions |
public static class WebhooksManagementEfCoreQueryableExtensions |
||||
{ |
{ |
||||
// 在此聚合仓储服务的扩展方法
|
// 在此聚合仓储服务的扩展方法
|
||||
|
public static IQueryable<WebhookSendRecord> IncludeDetails(this IQueryable<WebhookSendRecord> queryable, bool include = true) |
||||
|
{ |
||||
|
if (!include) |
||||
|
{ |
||||
|
return queryable; |
||||
|
} |
||||
|
|
||||
|
return queryable |
||||
|
.Include(x => x.WebhookEvent); |
||||
|
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue