Add events v14/feature/add-webhook-events-endpoint (#16192)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Webhook;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Webhooks;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
public class EventsWebhookController : WebhookControllerBase
|
||||
{
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
private readonly WebhookEventCollection _webhookEventCollection;
|
||||
|
||||
public EventsWebhookController(IUmbracoMapper umbracoMapper, WebhookEventCollection webhookEventCollection)
|
||||
{
|
||||
_umbracoMapper = umbracoMapper;
|
||||
_webhookEventCollection = webhookEventCollection;
|
||||
}
|
||||
|
||||
[HttpGet("events")]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(typeof(PagedViewModel<WebhookResponseModel>), StatusCodes.Status200OK)]
|
||||
public Task<ActionResult<PagedViewModel<WebhookEventViewModel>>> All(
|
||||
CancellationToken cancellationToken,
|
||||
int skip = 0,
|
||||
int take = 100)
|
||||
{
|
||||
List<WebhookEventViewModel> events = _umbracoMapper.MapEnumerable<IWebhookEvent, WebhookEventViewModel>(_webhookEventCollection.AsEnumerable());
|
||||
|
||||
var pagedModel = new PagedViewModel<WebhookEventViewModel>
|
||||
{
|
||||
Items = events.Skip(skip).Take(take),
|
||||
Total = events.Count,
|
||||
};
|
||||
|
||||
return Task.FromResult<ActionResult<PagedViewModel<WebhookEventViewModel>>>(Ok(pagedModel));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Cms.Api.Management.Factories;
|
||||
using Umbraco.Cms.Api.Management.Mapping.Webhook;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
@@ -9,6 +10,7 @@ internal static class WebhooksBuilderExtensions
|
||||
internal static IUmbracoBuilder AddWebhooks(this IUmbracoBuilder builder)
|
||||
{
|
||||
builder.Services.AddUnique<IWebhookPresentationFactory, WebhookPresentationFactory>();
|
||||
builder.AddMapDefinition<WebhookEventMapDefinition>();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Webhook;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Webhooks;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Mapping.Webhook;
|
||||
|
||||
public class WebhookEventMapDefinition : IMapDefinition
|
||||
{
|
||||
public void DefineMaps(IUmbracoMapper mapper) => mapper.Define<IWebhookEvent, WebhookEventViewModel>((_, _) => new WebhookEventViewModel(), Map);
|
||||
|
||||
// Umbraco.Code.MapAll
|
||||
private void Map(IWebhookEvent source, WebhookEventViewModel target, MapperContext context)
|
||||
{
|
||||
target.EventName = source.EventName;
|
||||
target.EventType = source.EventType;
|
||||
target.Alias = source.Alias;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Umbraco.Cms.Api.Management.ViewModels.Webhook;
|
||||
|
||||
public class WebhookEventViewModel
|
||||
{
|
||||
public string EventName { get; set; } = string.Empty;
|
||||
|
||||
public string EventType { get; set; } = string.Empty;
|
||||
|
||||
public string Alias { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user