V14: Webhook Management API (#15147)
* Add webhook to management api * Update webhook controllers * Add ByKey webhook controller * Fix typo * Fix typo * Update multiple webhooks * Update using * Remove duplicate constant after merge * Fix typo in file name * Update casing of IWebhookService * Fix typo * Use Webhook entity type * Fix ambiguous reference * Update webhook mapping * Update after change of CreatedAtAction * Use CreatedAtId instead * Update src/Umbraco.Cms.Api.Management/Controllers/Webhook/ByKeyWebhookController.cs Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> * Update src/Umbraco.Cms.Api.Management/Controllers/Webhook/ByKeyWebhookController.cs Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> * Update src/Umbraco.Cms.Api.Management/ViewModels/Webhook/CreateWebhookRequestModel.cs Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> * Update src/Umbraco.Cms.Api.Management/Controllers/Webhook/DeleteWebhookController.cs Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> * Update src/Umbraco.Cms.Api.Management/Controllers/Webhook/CreateWebhookController.cs Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> * Add Guid to WebhookResponseModel * Cleanup * Add Auth * Move webhook logic from backoffice to management api * Add mapping --------- Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
0f6705795a
commit
f47830b165
@@ -0,0 +1,44 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Webhook;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Web.Common.Authorization;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
[Authorize(Policy = "New" + AuthorizationPolicies.TreeAccessWebhooks)]
|
||||
public class CreateWebhookController : WebhookControllerBase
|
||||
{
|
||||
private readonly IWebhookService _webhookService;
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
|
||||
public CreateWebhookController(
|
||||
IWebhookService webhookService, IUmbracoMapper umbracoMapper)
|
||||
{
|
||||
_webhookService = webhookService;
|
||||
_umbracoMapper = umbracoMapper;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[MapToApiVersion("1.0")]
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Create(CreateWebhookRequestModel createWebhookRequestModel)
|
||||
{
|
||||
IWebhook created = _umbracoMapper.Map<IWebhook>(createWebhookRequestModel)!;
|
||||
|
||||
Attempt<IWebhook, WebhookOperationStatus> result = await _webhookService.CreateAsync(created);
|
||||
|
||||
return result.Success
|
||||
? CreatedAtId<ByKeyWebhookController>(controller => nameof(controller.ByKey), result.Result!.Key)
|
||||
: WebhookOperationStatusResult(result.Status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user