15 changed files with 233 additions and 6 deletions
@ -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); |
|||
} |
|||
@ -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; } |
|||
} |
|||
@ -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(); |
|||
} |
|||
@ -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; } |
|||
} |
|||
@ -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, |
|||
}); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue