Browse Source

feat: added send attempts api

pull/532/head
cKey 4 years ago
parent
commit
d53e34cd6a
  1. 11
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/Authorization/WebhooksManagementPermissionDefinitionProvider.cs
  2. 6
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/Authorization/WebhooksManagementPermissions.cs
  3. 15
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhooksSendRecordAppService.cs
  4. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhooksSubscriptionAppService.cs
  5. 12
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookEventRecordDto.cs
  6. 24
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordDto.cs
  7. 20
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordGetListInput.cs
  8. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhooksManagementApplicationMapperProfile.cs
  9. 74
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhooksSendRecordAppService.cs
  10. 4
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhooksSubscriptionAppService.cs
  11. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/en.json
  12. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/zh-Hans.json
  13. 5
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/EfCoreWebhookSendRecordRepository.cs
  14. 44
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhooksSendRecordController.cs
  15. 6
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhooksSubscriptionController.cs

11
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/Authorization/WebhooksManagementPermissionDefinitionProvider.cs

@ -32,6 +32,17 @@ public class WebhooksManagementPermissionDefinitionProvider : PermissionDefiniti
MultiTenancySides.Host)
.WithProviders(ClientPermissionValueProvider.ProviderName);
var sendAttempts = group.AddPermission(
WebhooksManagementPermissions.WebhooksSendAttempts.Default,
L("Permission:SendAttempts"),
MultiTenancySides.Host)
.WithProviders(ClientPermissionValueProvider.ProviderName);
sendAttempts.AddChild(
WebhooksManagementPermissions.WebhooksSendAttempts.Resend,
L("Permission:Resend"),
MultiTenancySides.Host)
.WithProviders(ClientPermissionValueProvider.ProviderName);
group.AddPermission(
WebhooksManagementPermissions.Publish,
L("Permission:Publish"))

6
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/Authorization/WebhooksManagementPermissions.cs

@ -18,4 +18,10 @@ public static class WebhooksManagementPermissions
public const string Update = Default + ".Update";
public const string Delete = Default + ".Delete";
}
public static class WebhooksSendAttempts
{
public const string Default = GroupName + ".SendAttempts";
public const string Resend = Default + ".Resend";
}
}

15
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhooksSendRecordAppService.cs

@ -0,0 +1,15 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.WebhooksManagement;
public interface IWebhooksSendRecordAppService : IApplicationService
{
Task<WebhookSendRecordDto> GetAsync(Guid id);
Task ResendAsync(Guid id);
Task<PagedResultDto<WebhookSendRecordDto>> GetListAsync(WebhookSendRecordGetListInput input);
}

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhookSubscriptionAppService.cs → aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/IWebhooksSubscriptionAppService.cs

@ -5,7 +5,7 @@ using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.WebhooksManagement;
public interface IWebhookSubscriptionAppService :
public interface IWebhooksSubscriptionAppService :
ICrudAppService<
WebhookSubscriptionDto,
Guid,

12
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookEventRecordDto.cs

@ -0,0 +1,12 @@
using System;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.WebhooksManagement;
public class WebhookEventRecordDto : EntityDto<Guid>
{
public Guid? TenantId { get; set; }
public string WebhookName { get; set; }
public string Data { get; set; }
public DateTime CreationTime { get; set; }
}

24
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordDto.cs

@ -0,0 +1,24 @@
using System;
using System.Net;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.WebhooksManagement;
public class WebhookSendRecordDto : EntityDto<Guid>
{
public Guid? TenantId { get; set; }
public Guid WebhookEventId { get; set; }
public Guid WebhookSubscriptionId { get; set; }
public string Response { get; set; }
public HttpStatusCode? ResponseStatusCode { get; set; }
public DateTime CreationTime { get; set; }
public DateTime? LastModificationTime { get; set; }
public WebhookEventRecordDto WebhookEvent { get; set; } = new WebhookEventRecordDto();
}

20
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSendRecordGetListInput.cs

@ -0,0 +1,20 @@
using System;
using System.Net;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.WebhooksManagement;
public class WebhookSendRecordGetListInput : PagedAndSortedResultRequestDto
{
public string Filter { get; set; }
public Guid? WebhookEventId { get; set; }
public Guid? SubscriptionId { get; set; }
public HttpStatusCode? ResponseStatusCode { get; set; }
public DateTime? BeginCreationTime { get; set; }
public DateTime? EndCreationTime { get; set; }
}

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhooksManagementApplicationMapperProfile.cs

@ -6,5 +6,7 @@ public class WebhooksManagementApplicationMapperProfile : Profile
{
public WebhooksManagementApplicationMapperProfile()
{
CreateMap<WebhookEventRecord, WebhookEventRecordDto>();
CreateMap<WebhookSendRecord, WebhookSendRecordDto>();
}
}

74
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhooksSendRecordAppService.cs

@ -0,0 +1,74 @@
using LINGYUN.Abp.Webhooks;
using LINGYUN.Abp.WebhooksManagement.Authorization;
using LINGYUN.Abp.WebhooksManagement.Extensions;
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.BackgroundJobs;
namespace LINGYUN.Abp.WebhooksManagement;
[Authorize(WebhooksManagementPermissions.WebhooksSendAttempts.Default)]
public class WebhooksSendRecordAppService : WebhooksManagementAppServiceBase, IWebhooksSendRecordAppService
{
protected IBackgroundJobManager BackgroundJobManager => LazyServiceProvider.LazyGetRequiredService<IBackgroundJobManager>();
protected IWebhookEventRecordRepository EventRepository => LazyServiceProvider.LazyGetRequiredService<IWebhookEventRecordRepository>();
protected IWebhookSubscriptionRepository SubscriptionRepository => LazyServiceProvider.LazyGetRequiredService<IWebhookSubscriptionRepository>();
protected IWebhookSendRecordRepository RecordRepository { get; }
public WebhooksSendRecordAppService(
IWebhookSendRecordRepository recordRepository)
{
RecordRepository = recordRepository;
}
public async virtual Task<WebhookSendRecordDto> GetAsync(Guid id)
{
var sendRecord = await RecordRepository.GetAsync(id);
return ObjectMapper.Map<WebhookSendRecord, WebhookSendRecordDto>(sendRecord);
}
public async virtual Task<PagedResultDto<WebhookSendRecordDto>> GetListAsync(WebhookSendRecordGetListInput input)
{
var filter = new WebhookSendRecordFilter
{
SubscriptionId = input.SubscriptionId,
ResponseStatusCode = input.ResponseStatusCode,
BeginCreationTime = input.BeginCreationTime,
EndCreationTime = input.EndCreationTime,
WebhookEventId = input.WebhookEventId,
Filter = input.Filter
};
var totalCount = await RecordRepository.GetCountAsync(filter);
var sendRecords = await RecordRepository.GetListAsync(filter,
input.Sorting, input.MaxResultCount, input.SkipCount);
return new PagedResultDto<WebhookSendRecordDto>(totalCount,
ObjectMapper.Map<List<WebhookSendRecord>, List<WebhookSendRecordDto>>(sendRecords));
}
[Authorize(WebhooksManagementPermissions.WebhooksSendAttempts.Resend)]
public async virtual Task ResendAsync(Guid id)
{
var sendRecord = await RecordRepository.GetAsync(id);
var sendEvent = await EventRepository.GetAsync(sendRecord.WebhookEventId);
var subscription = await SubscriptionRepository.GetAsync(sendRecord.WebhookSubscriptionId);
await BackgroundJobManager.EnqueueAsync(new WebhookSenderArgs
{
TenantId = CurrentTenant.Id,
WebhookSubscriptionId = sendRecord.WebhookSubscriptionId,
WebhookEventId = sendRecord.WebhookEventId,
WebhookName = sendEvent.WebhookName,
WebhookUri = subscription.WebhookUri,
Data = sendEvent.Data,
Headers = subscription.GetWebhookHeaders(),
Secret = subscription.Secret,
});
}
}

4
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionAppService.cs → aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhooksSubscriptionAppService.cs

@ -13,12 +13,12 @@ using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.WebhooksManagement;
[Authorize(WebhooksManagementPermissions.WebhookSubscription.Default)]
public class WebhookSubscriptionAppService : WebhooksManagementAppServiceBase, IWebhookSubscriptionAppService
public class WebhooksSubscriptionAppService : WebhooksManagementAppServiceBase, IWebhooksSubscriptionAppService
{
protected IWebhookDefinitionManager WebhookDefinitionManager { get; }
protected IWebhookSubscriptionRepository SubscriptionRepository { get; }
public WebhookSubscriptionAppService(
public WebhooksSubscriptionAppService(
IWebhookDefinitionManager webhookDefinitionManager,
IWebhookSubscriptionRepository subscriptionRepository)
{

7
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/en.json

@ -3,6 +3,13 @@
"texts": {
"Features:WebhooksManagement": "Webhooks",
"Permission:WebhooksManagement": "Webhooks",
"Permission:Subscriptions": "Subscriptions",
"Permission:SendAttempts": "Attempts",
"Permission:Create": "Create",
"Permission:Update": "Update",
"Permission:Delete": "Delete",
"Permission:Resend": "Resend",
"Permission:Publish": "Publish",
"Permission:ManageSettings": "Manage Settings",
"DisplayName:CheckConnect": "Check Connect",
"Description:CheckConnect": "When a third-party service is connected, it is used to check whether the communication is normal.",

7
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/zh-Hans.json

@ -3,6 +3,13 @@
"texts": {
"Features:WebhooksManagement": "Webhooks",
"Permission:WebhooksManagement": "Webhooks",
"Permission:Subscriptions": "管理订阅",
"Permission:SendAttempts": "管理发送",
"Permission:Create": "创建",
"Permission:Update": "编辑",
"Permission:Delete": "删除",
"Permission:Resend": "重新发送",
"Permission:Publish": "发布事件",
"Permission:ManageSettings": "管理设置",
"DisplayName:CheckConnect": "检查连接",
"Description:CheckConnect": "第三方服务接入时,用于检查是否通讯正常.",

5
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.EntityFrameworkCore/LINGYUN/Abp/WebhooksManagement/EntityFrameworkCore/EfCoreWebhookSendRecordRepository.cs

@ -43,6 +43,11 @@ public class EfCoreWebhookSendRecordRepository :
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async override Task<IQueryable<WebhookSendRecord>> WithDetailsAsync()
{
return (await base.WithDetailsAsync()).IncludeDetails();
}
protected virtual IQueryable<WebhookSendRecord> ApplyFilter(
IQueryable<WebhookSendRecord> queryable,
WebhookSendRecordFilter filter)

44
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhooksSendRecordController.cs

@ -0,0 +1,44 @@
using LINGYUN.Abp.WebhooksManagement.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.WebhooksManagement;
[RemoteService(Name = WebhooksManagementRemoteServiceConsts.RemoteServiceName)]
[Area(WebhooksManagementRemoteServiceConsts.ModuleName)]
[Authorize(WebhooksManagementPermissions.WebhooksSendAttempts.Default)]
[Route("api/webhooks/send-attempts")]
public class WebhooksSendRecordController : WebhooksManagementControllerBase, IWebhooksSendRecordAppService
{
protected IWebhooksSendRecordAppService SendRecordAppService { get; }
public WebhooksSendRecordController(IWebhooksSendRecordAppService sendRecordAppService)
{
SendRecordAppService = sendRecordAppService;
}
[HttpGet]
[Route("{id}")]
public Task<WebhookSendRecordDto> GetAsync(Guid id)
{
return SendRecordAppService.GetAsync(id);
}
[HttpGet]
public Task<PagedResultDto<WebhookSendRecordDto>> GetListAsync(WebhookSendRecordGetListInput input)
{
return SendRecordAppService.GetListAsync(input);
}
[HttpPost]
[Route("{id}/resend")]
[Authorize(WebhooksManagementPermissions.WebhooksSendAttempts.Resend)]
public Task ResendAsync(Guid id)
{
return SendRecordAppService.ResendAsync(id);
}
}

6
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionController.cs → aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.HttpApi/LINGYUN/Abp/WebhooksManagement/WebhooksSubscriptionController.cs

@ -12,11 +12,11 @@ namespace LINGYUN.Abp.WebhooksManagement;
[Area(WebhooksManagementRemoteServiceConsts.ModuleName)]
[Authorize(WebhooksManagementPermissions.WebhookSubscription.Default)]
[Route("api/webhooks/subscriptions")]
public class WebhookSubscriptionController : WebhooksManagementControllerBase, IWebhookSubscriptionAppService
public class WebhooksSubscriptionController : WebhooksManagementControllerBase, IWebhooksSubscriptionAppService
{
protected IWebhookSubscriptionAppService SubscriptionAppService { get; }
protected IWebhooksSubscriptionAppService SubscriptionAppService { get; }
public WebhookSubscriptionController(IWebhookSubscriptionAppService subscriptionAppService)
public WebhooksSubscriptionController(IWebhooksSubscriptionAppService subscriptionAppService)
{
SubscriptionAppService = subscriptionAppService;
}
Loading…
Cancel
Save