10 changed files with 358 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public static class WebhookDefinitionRecordConsts |
||||
|
{ |
||||
|
public static int MaxNameLength { get; set; } = 128; |
||||
|
|
||||
|
public static int MaxDisplayNameLength { get; set; } = 256; |
||||
|
|
||||
|
public static int MaxDescriptionLength { get; set; } = 256; |
||||
|
|
||||
|
public static int MaxProvidersLength { get; set; } = 128; |
||||
|
|
||||
|
public static int MaxRequiredFeaturesLength { get; set; } = 256; |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
public static class WebhookGroupDefinitionRecordConsts |
||||
|
{ |
||||
|
public static int MaxNameLength { get; set; } = 128; |
||||
|
|
||||
|
public static int MaxDisplayNameLength { get; set; } = 256; |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public interface IWebhookDefinitionRecordRepository : IBasicRepository<WebhookDefinitionRecord, Guid> |
||||
|
{ |
||||
|
Task<WebhookDefinitionRecord> FindByNameAsync( |
||||
|
string name, |
||||
|
CancellationToken cancellationToken = default); |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
public interface IWebhookGroupDefinitionRecordRepository : IBasicRepository<WebhookGroupDefinitionRecord, Guid> |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,153 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public class WebhookDefinitionRecord : BasicAggregateRoot<Guid>, IHasExtraProperties |
||||
|
{ |
||||
|
[System.Text.Json.Serialization.JsonIgnore] |
||||
|
[Newtonsoft.Json.JsonIgnore] |
||||
|
public override Guid Id { get; protected set; } |
||||
|
|
||||
|
public string GroupName { get; set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
public string Description { get; set; } |
||||
|
|
||||
|
public bool IsEnabled { get; set; } |
||||
|
|
||||
|
public string Providers { get; set; } |
||||
|
|
||||
|
public string RequiredFeatures { get; set; } |
||||
|
|
||||
|
public ExtraPropertyDictionary ExtraProperties { get; protected set; } |
||||
|
|
||||
|
public WebhookDefinitionRecord() |
||||
|
{ |
||||
|
ExtraProperties = new ExtraPropertyDictionary(); |
||||
|
this.SetDefaultsForExtraProperties(); |
||||
|
} |
||||
|
|
||||
|
public WebhookDefinitionRecord( |
||||
|
Guid id, |
||||
|
string groupName, |
||||
|
string name, |
||||
|
string displayName, |
||||
|
string description = null, |
||||
|
bool isEnabled = true, |
||||
|
string providers = null, |
||||
|
string requiredFeatures = null) |
||||
|
: base(id) |
||||
|
{ |
||||
|
GroupName = Check.NotNullOrWhiteSpace(groupName, nameof(groupName), WebhookGroupDefinitionRecordConsts.MaxNameLength); |
||||
|
Name = Check.NotNullOrWhiteSpace(name, nameof(name), WebhookDefinitionRecordConsts.MaxNameLength); |
||||
|
DisplayName = Check.NotNullOrWhiteSpace(displayName, nameof(displayName), WebhookDefinitionRecordConsts.MaxDisplayNameLength); |
||||
|
Description = Check.Length(description, nameof(description), WebhookDefinitionRecordConsts.MaxDescriptionLength); |
||||
|
|
||||
|
Providers = Check.Length(providers, nameof(providers), WebhookDefinitionRecordConsts.MaxProvidersLength); |
||||
|
RequiredFeatures = Check.Length(requiredFeatures, nameof(requiredFeatures), WebhookDefinitionRecordConsts.MaxRequiredFeaturesLength); |
||||
|
|
||||
|
IsEnabled = isEnabled; |
||||
|
|
||||
|
ExtraProperties = new ExtraPropertyDictionary(); |
||||
|
this.SetDefaultsForExtraProperties(); |
||||
|
} |
||||
|
|
||||
|
public bool HasSameData(WebhookDefinitionRecord otherRecord) |
||||
|
{ |
||||
|
if (Name != otherRecord.Name) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (GroupName != otherRecord.GroupName) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (DisplayName != otherRecord.DisplayName) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (Description != otherRecord.Description) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (IsEnabled != otherRecord.IsEnabled) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (Providers != otherRecord.Providers) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (RequiredFeatures != otherRecord.RequiredFeatures) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (!this.HasSameExtraProperties(otherRecord)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
public void Patch(WebhookDefinitionRecord otherRecord) |
||||
|
{ |
||||
|
if (Name != otherRecord.Name) |
||||
|
{ |
||||
|
Name = otherRecord.Name; |
||||
|
} |
||||
|
|
||||
|
if (GroupName != otherRecord.GroupName) |
||||
|
{ |
||||
|
GroupName = otherRecord.GroupName; |
||||
|
} |
||||
|
|
||||
|
if (DisplayName != otherRecord.DisplayName) |
||||
|
{ |
||||
|
DisplayName = otherRecord.DisplayName; |
||||
|
} |
||||
|
|
||||
|
if (Description != otherRecord.Description) |
||||
|
{ |
||||
|
Description = otherRecord.Description; |
||||
|
} |
||||
|
|
||||
|
if (IsEnabled != otherRecord.IsEnabled) |
||||
|
{ |
||||
|
IsEnabled = otherRecord.IsEnabled; |
||||
|
} |
||||
|
|
||||
|
if (Providers != otherRecord.Providers) |
||||
|
{ |
||||
|
Providers = otherRecord.Providers; |
||||
|
} |
||||
|
|
||||
|
if (RequiredFeatures != otherRecord.RequiredFeatures) |
||||
|
{ |
||||
|
RequiredFeatures = otherRecord.RequiredFeatures; |
||||
|
} |
||||
|
|
||||
|
if (!this.HasSameExtraProperties(otherRecord)) |
||||
|
{ |
||||
|
ExtraProperties.Clear(); |
||||
|
|
||||
|
foreach (var property in otherRecord.ExtraProperties) |
||||
|
{ |
||||
|
ExtraProperties.Add(property.Key, property.Value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement; |
||||
|
|
||||
|
public class WebhookGroupDefinitionRecord : BasicAggregateRoot<Guid>, IHasExtraProperties |
||||
|
{ |
||||
|
[System.Text.Json.Serialization.JsonIgnore] |
||||
|
[Newtonsoft.Json.JsonIgnore] |
||||
|
public override Guid Id { get; protected set; } |
||||
|
|
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public string DisplayName { get; set; } |
||||
|
|
||||
|
public ExtraPropertyDictionary ExtraProperties { get; protected set; } |
||||
|
|
||||
|
public WebhookGroupDefinitionRecord() |
||||
|
{ |
||||
|
ExtraProperties = new ExtraPropertyDictionary(); |
||||
|
this.SetDefaultsForExtraProperties(); |
||||
|
} |
||||
|
|
||||
|
public WebhookGroupDefinitionRecord( |
||||
|
Guid id, |
||||
|
string name, |
||||
|
string displayName) |
||||
|
: base(id) |
||||
|
{ |
||||
|
Name = Check.NotNullOrWhiteSpace(name, nameof(name), WebhookGroupDefinitionRecordConsts.MaxNameLength); |
||||
|
DisplayName = Check.NotNullOrWhiteSpace(displayName, nameof(displayName), WebhookGroupDefinitionRecordConsts.MaxDisplayNameLength); ; |
||||
|
|
||||
|
ExtraProperties = new ExtraPropertyDictionary(); |
||||
|
this.SetDefaultsForExtraProperties(); |
||||
|
} |
||||
|
|
||||
|
public bool HasSameData(WebhookGroupDefinitionRecord otherRecord) |
||||
|
{ |
||||
|
if (Name != otherRecord.Name) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (DisplayName != otherRecord.DisplayName) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (!this.HasSameExtraProperties(otherRecord)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
public void Patch(WebhookGroupDefinitionRecord otherRecord) |
||||
|
{ |
||||
|
if (Name != otherRecord.Name) |
||||
|
{ |
||||
|
Name = otherRecord.Name; |
||||
|
} |
||||
|
|
||||
|
if (DisplayName != otherRecord.DisplayName) |
||||
|
{ |
||||
|
DisplayName = otherRecord.DisplayName; |
||||
|
} |
||||
|
|
||||
|
if (!this.HasSameExtraProperties(otherRecord)) |
||||
|
{ |
||||
|
ExtraProperties.Clear(); |
||||
|
|
||||
|
foreach (var property in otherRecord.ExtraProperties) |
||||
|
{ |
||||
|
ExtraProperties.Add(property.Key, property.Value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
||||
|
|
||||
|
public class EfCoreWebhookDefinitionRecordRepository : |
||||
|
EfCoreRepository<IWebhooksManagementDbContext, WebhookDefinitionRecord, Guid>, |
||||
|
IWebhookDefinitionRecordRepository |
||||
|
{ |
||||
|
public EfCoreWebhookDefinitionRecordRepository( |
||||
|
IDbContextProvider<IWebhooksManagementDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<WebhookDefinitionRecord> FindByNameAsync( |
||||
|
string name, |
||||
|
CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
return await (await GetDbSetAsync()) |
||||
|
.OrderBy(x => x.Id) |
||||
|
.FirstOrDefaultAsync(r => r.Name == name, cancellationToken); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore; |
||||
|
|
||||
|
public class EfCoreWebhookGroupDefinitionRecordRepository : |
||||
|
EfCoreRepository<IWebhooksManagementDbContext, WebhookGroupDefinitionRecord, Guid>, |
||||
|
IWebhookGroupDefinitionRecordRepository |
||||
|
{ |
||||
|
public EfCoreWebhookGroupDefinitionRecordRepository( |
||||
|
IDbContextProvider<IWebhooksManagementDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue