Browse Source

add webhook definition record

pull/765/head
cKey 3 years ago
parent
commit
4f8af251d9
  1. 14
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/WebhookDefinitionRecordConsts.cs
  2. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/WebhookGroupDefinitionRecordConsts.cs
  3. 13
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/IWebhookDefinitionRecordRepository.cs
  4. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/IWebhookGroupDefinitionRecordRepository.cs
  5. 153
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookDefinitionRecord.cs
  6. 81
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookGroupDefinitionRecord.cs
  7. 29
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/EfCoreWebhookDefinitionRecordRepository.cs
  8. 16
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/EfCoreWebhookGroupDefinitionRecordRepository.cs
  9. 35
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/WebhooksManagementDbContextModelCreatingExtensions.cs
  10. 3
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/WebhooksManagementEntityFrameworkCoreModule.cs

14
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/WebhookDefinitionRecordConsts.cs

@ -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;
}

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

@ -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;
}

13
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/IWebhookDefinitionRecordRepository.cs

@ -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);
}

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

@ -0,0 +1,7 @@
using System;
using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.WebhooksManagement;
public interface IWebhookGroupDefinitionRecordRepository : IBasicRepository<WebhookGroupDefinitionRecord, Guid>
{
}

153
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookDefinitionRecord.cs

@ -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);
}
}
}
}

81
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookGroupDefinitionRecord.cs

@ -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);
}
}
}
}

29
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/EfCoreWebhookDefinitionRecordRepository.cs

@ -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);
}
}

16
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/EfCoreWebhookGroupDefinitionRecordRepository.cs

@ -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)
{
}
}

35
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/WebhooksManagementDbContextModelCreatingExtensions.cs

@ -80,5 +80,40 @@ public static class WebhooksManagementDbContextModelCreatingExtensions
b.ConfigureByConvention();
});
builder.Entity<WebhookGroupDefinitionRecord>(b =>
{
b.ToTable(options.TablePrefix + "WebhookGroups", options.Schema);
b.ConfigureByConvention();
b.Property(x => x.Name).HasMaxLength(WebhookGroupDefinitionRecordConsts.MaxNameLength).IsRequired();
b.Property(x => x.DisplayName).HasMaxLength(WebhookGroupDefinitionRecordConsts.MaxDisplayNameLength).IsRequired();
b.HasIndex(x => new { x.Name }).IsUnique();
b.ApplyObjectExtensionMappings();
});
builder.Entity<WebhookDefinitionRecord>(b =>
{
b.ToTable(options.TablePrefix + "Webhooks", options.Schema);
b.ConfigureByConvention();
b.Property(x => x.GroupName).HasMaxLength(WebhookGroupDefinitionRecordConsts.MaxNameLength).IsRequired();
b.Property(x => x.Name).HasMaxLength(WebhookDefinitionRecordConsts.MaxNameLength).IsRequired();
b.Property(x => x.DisplayName).HasMaxLength(WebhookDefinitionRecordConsts.MaxDisplayNameLength).IsRequired();
b.Property(x => x.Description).HasMaxLength(WebhookDefinitionRecordConsts.MaxDescriptionLength);
b.Property(x => x.Providers).HasMaxLength(WebhookDefinitionRecordConsts.MaxProvidersLength);
b.Property(x => x.RequiredFeatures).HasMaxLength(WebhookDefinitionRecordConsts.MaxRequiredFeaturesLength);
b.HasIndex(x => new { x.Name }).IsUnique();
b.HasIndex(x => new { x.GroupName });
b.ApplyObjectExtensionMappings();
});
builder.TryConfigureObjectExtensions<WebhooksManagementDbContext>();
}
}

3
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/WebhooksManagementEntityFrameworkCoreModule.cs

@ -17,6 +17,9 @@ public class WebhooksManagementEntityFrameworkCoreModule : AbpModule
options.AddRepository<WebhookEventRecord, EfCoreWebhookEventRecordRepository>();
options.AddRepository<WebhookSubscription, EfCoreWebhookSubscriptionRepository>();
options.AddRepository<WebhookGroupDefinitionRecord, EfCoreWebhookGroupDefinitionRecordRepository>();
options.AddRepository<WebhookDefinitionRecord, EfCoreWebhookDefinitionRecordRepository>();
options.AddDefaultRepositories<IWebhooksManagementDbContext>();
});
}

Loading…
Cancel
Save