|
|
|
@ -11,6 +11,7 @@ using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.Primitives; |
|
|
|
using NodaTime; |
|
|
|
using NSwag.Annotations; |
|
|
|
using Squidex.Controllers.Api.Webhooks.Models; |
|
|
|
using Squidex.Domain.Apps.Read.Schemas.Repositories; |
|
|
|
@ -20,7 +21,7 @@ using Squidex.Infrastructure.Reflection; |
|
|
|
using Squidex.Pipeline; |
|
|
|
|
|
|
|
namespace Squidex.Controllers.Api.Webhooks |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Manages and retrieves information about schemas.
|
|
|
|
/// </summary>
|
|
|
|
@ -33,9 +34,9 @@ namespace Squidex.Controllers.Api.Webhooks |
|
|
|
private readonly ISchemaWebhookRepository webhooksRepository; |
|
|
|
private readonly IWebhookEventRepository webhookEventsRepository; |
|
|
|
|
|
|
|
public WebhooksController(ICommandBus commandBus, |
|
|
|
ISchemaWebhookRepository webhooksRepository, |
|
|
|
IWebhookEventRepository webhookEventsRepository) |
|
|
|
public WebhooksController(ICommandBus commandBus, |
|
|
|
ISchemaWebhookRepository webhooksRepository, |
|
|
|
IWebhookEventRepository webhookEventsRepository) |
|
|
|
: base(commandBus) |
|
|
|
{ |
|
|
|
this.webhooksRepository = webhooksRepository; |
|
|
|
@ -78,7 +79,7 @@ namespace Squidex.Controllers.Api.Webhooks |
|
|
|
/// <param name="name">The name of the schema.</param>
|
|
|
|
/// <param name="request">The webhook object that needs to be added to the app.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// 201 => Webhook created.
|
|
|
|
/// 201 => Webhook created.
|
|
|
|
/// 400 => Webhook name or properties are not valid.
|
|
|
|
/// 409 => Webhook name already in use.
|
|
|
|
/// 404 => App or schema not found.
|
|
|
|
@ -98,7 +99,9 @@ namespace Squidex.Controllers.Api.Webhooks |
|
|
|
|
|
|
|
await CommandBus.PublishAsync(command); |
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetWebhooks), new { app }, SimpleMapper.Map(command, new WebhookCreatedDto { SchemaId = command.SchemaId.Id.ToString() })); |
|
|
|
var response = SimpleMapper.Map(command, new WebhookCreatedDto { SchemaId = command.SchemaId.Id.ToString() }; |
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetWebhooks), new { app }, response)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -125,6 +128,8 @@ namespace Squidex.Controllers.Api.Webhooks |
|
|
|
/// Get webhook events.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="app">The name of the app.</param>
|
|
|
|
/// <param name="skip">The number of events to skip.</param>
|
|
|
|
/// <param name="take">The number of events to take.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// 200 => Webhook events returned.
|
|
|
|
/// 404 => App not found.
|
|
|
|
@ -133,9 +138,9 @@ namespace Squidex.Controllers.Api.Webhooks |
|
|
|
[Route("apps/{app}/webhooks/events")] |
|
|
|
[ProducesResponseType(typeof(WebhookEventsDto), 200)] |
|
|
|
[ApiCosts(0)] |
|
|
|
public async Task<IActionResult> GetEvents(string app) |
|
|
|
public async Task<IActionResult> GetEvents(string app, [FromQuery] int skip = 0, [FromQuery] int take = 20) |
|
|
|
{ |
|
|
|
var taskForItems = webhookEventsRepository.QueryByAppAsync(App.Id); |
|
|
|
var taskForItems = webhookEventsRepository.QueryByAppAsync(App.Id, skip, take); |
|
|
|
var taskForCount = webhookEventsRepository.CountByAppAsync(App.Id); |
|
|
|
|
|
|
|
await Task.WhenAll(taskForItems, taskForCount); |
|
|
|
@ -156,5 +161,31 @@ namespace Squidex.Controllers.Api.Webhooks |
|
|
|
|
|
|
|
return Ok(response); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Enqueue the event to be send.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="app">The name of the app.</param>
|
|
|
|
/// <param name="id">The event to enqueue.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// 200 => Webhook enqueued.
|
|
|
|
/// 404 => App or webhook event not found.
|
|
|
|
/// </returns>
|
|
|
|
[HttpPut] |
|
|
|
[Route("apps/{app}/webhooks/events/{id}")] |
|
|
|
[ApiCosts(0)] |
|
|
|
public async Task<IActionResult> PutEvent(string app, Guid id) |
|
|
|
{ |
|
|
|
var entity = await webhookEventsRepository.FindAsync(id); |
|
|
|
|
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
return NotFound(); |
|
|
|
} |
|
|
|
|
|
|
|
await webhookEventsRepository.EnqueueAsync(id, SystemClock.Instance.GetCurrentInstant()); |
|
|
|
|
|
|
|
return Ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|