Browse Source

Webhook API.

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
83aa00d03b
  1. 1
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs
  2. 14
      src/Squidex/Controllers/Api/Apps/AppClientsController.cs
  3. 6
      src/Squidex/Controllers/Api/Apps/AppLanguagesController.cs
  4. 8
      src/Squidex/Controllers/Api/Apps/Models/AppDto.cs
  5. 2
      src/Squidex/Controllers/Api/Apps/Models/AssignAppContributorDto.cs
  6. 2
      src/Squidex/Controllers/Api/Apps/Models/ContributorDto.cs
  7. 2
      src/Squidex/Controllers/Api/Apps/Models/UpdateAppLanguageDto.cs
  8. 2
      src/Squidex/Controllers/Api/Schemas/SchemasController.cs
  9. 22
      src/Squidex/Controllers/Api/Webhooks/Models/CreateWebhookDto.cs
  10. 38
      src/Squidex/Controllers/Api/Webhooks/Models/WebhookDto.cs
  11. 114
      src/Squidex/Controllers/Api/Webhooks/WebhooksController.cs

1
src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs

@ -7,7 +7,6 @@
// ==========================================================================
using System;
using System.Collections.Generic;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json.Linq;
using Squidex.Core.Schemas;

14
src/Squidex/Controllers/Api/Apps/AppClientsController.cs

@ -42,7 +42,7 @@ namespace Squidex.Controllers.Api.Apps
/// 404 => App not found.
/// </returns>
/// <remarks>
/// Gets all configured client keys for the app with the specified name.
/// Gets all configured clients for the app with the specified name.
/// </remarks>
[HttpGet]
[Route("apps/{app}/clients/")]
@ -63,12 +63,12 @@ namespace Squidex.Controllers.Api.Apps
/// <param name="app">The name of the app.</param>
/// <param name="request">Client object that needs to be added to the app.</param>
/// <returns>
/// 201 => Client key generated.
/// 201 => Client generated.
/// 404 => App not found.
/// </returns>
/// <remarks>
/// Create a new key for the app with the specified name.
/// The client secret is auto generated on the server and returned. The client is valid for one year.
/// Create a new client for the app with the specified name.
/// The client secret is auto generated on the server and returned. The client does not exire, the access token is valid for 30 days.
/// </remarks>
[HttpPost]
[Route("apps/{app}/clients/")]
@ -95,6 +95,9 @@ namespace Squidex.Controllers.Api.Apps
/// 204 => Client updated.
/// 404 => App not found or client not found.
/// </returns>
/// <remarks>
/// Only the display name can be changed, create a new client if necessary.
/// </remarks>
[HttpPut]
[Route("apps/{app}/clients/{clientId}/")]
[ApiCosts(1)]
@ -114,6 +117,9 @@ namespace Squidex.Controllers.Api.Apps
/// 204 => Client revoked.
/// 404 => App not found or client not found.
/// </returns>
/// <remarks>
/// The application that uses this client credentials cannot access the API after it has been revoked.
/// </remarks>
[HttpDelete]
[Route("apps/{app}/clients/{clientId}/")]
[ApiCosts(1)]

6
src/Squidex/Controllers/Api/Apps/AppLanguagesController.cs

@ -70,7 +70,7 @@ namespace Squidex.Controllers.Api.Apps
/// <param name="app">The name of the app.</param>
/// <param name="request">The language to add to the app.</param>
/// <returns>
/// 201 => App language created.
/// 201 => Language created.
/// 400 => Language is an invalid language.
/// 404 => App not found.
/// </returns>
@ -96,7 +96,7 @@ namespace Squidex.Controllers.Api.Apps
/// <param name="language">The language to delete from the app.</param>
/// <param name="model">The language properties.</param>
/// <returns>
/// 204 => App language updated.
/// 204 => Language updated.
/// 400 => Language is an invalid language.
/// 404 => App not found.
/// </returns>
@ -117,7 +117,7 @@ namespace Squidex.Controllers.Api.Apps
/// <param name="app">The name of the app.</param>
/// <param name="language">The language to delete from the app.</param>
/// <returns>
/// 204 => App language deleted.
/// 204 => Language deleted.
/// 400 => Language is an invalid language.
/// 404 => App not found.
/// </returns>

8
src/Squidex/Controllers/Api/Apps/Models/AppDto.cs

@ -30,17 +30,17 @@ namespace Squidex.Controllers.Api.Apps.Models
public long Version { get; set; }
/// <summary>
/// The name of the app.
/// The id of the app.
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// The date and time when the app has been created.
/// The timestamp when the app has been created.
/// </summary>
public Instant Created { get; set; }
/// <summary>
/// The date and time when the app has been modified last.
/// The timestamp when the app has been modified last.
/// </summary>
public Instant LastModified { get; set; }

2
src/Squidex/Controllers/Api/Apps/Models/AssignAppContributorDto.cs

@ -16,7 +16,7 @@ namespace Squidex.Controllers.Api.Apps.Models
public sealed class AssignAppContributorDto
{
/// <summary>
/// The id of the user to add to the app (GUID).
/// The id of the user to add to the app.
/// </summary>
[Required]
public string ContributorId { get; set; }

2
src/Squidex/Controllers/Api/Apps/Models/ContributorDto.cs

@ -16,7 +16,7 @@ namespace Squidex.Controllers.Api.Apps.Models
public sealed class ContributorDto
{
/// <summary>
/// The id of the user that contributes to the app (GUID).
/// The id of the user that contributes to the app.
/// </summary>
[Required]
public string ContributorId { get; set; }

2
src/Squidex/Controllers/Api/Apps/Models/UpdateAppLanguageDto.cs

@ -14,7 +14,7 @@ namespace Squidex.Controllers.Api.Apps.Models
public class UpdateAppLanguageDto
{
/// <summary>
/// Set the value to true to make the language to the master language.
/// Set the value to true to make the language the master.
/// </summary>
public bool? IsMaster { get; set; }

2
src/Squidex/Controllers/Api/Schemas/SchemasController.cs

@ -41,7 +41,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <summary>
/// Get schemas.
/// </summary>
/// <param name="app">The name of the app to create the schema to.</param>
/// <param name="app">The name of the app to get the schemas for.</param>
/// <returns>
/// 200 => Schemas returned.
/// 404 => App not found.

22
src/Squidex/Controllers/Api/Webhooks/Models/CreateWebhookDto.cs

@ -0,0 +1,22 @@
// ==========================================================================
// CreateWebhookDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Webhooks.Models
{
public class CreateWebhookDto
{
/// <summary>
/// The url of the webhook.
/// </summary>
[Required]
public Uri Url { get; set; }
}
}

38
src/Squidex/Controllers/Api/Webhooks/Models/WebhookDto.cs

@ -0,0 +1,38 @@
// ==========================================================================
// WebhookDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Webhooks.Models
{
public class WebhookDto
{
/// <summary>
/// The id of the webhook.
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// The id of the schema.
/// </summary>
public Guid SchemaId { get; set; }
/// <summary>
/// The url of the webhook.
/// </summary>
[Required]
public Uri Url { get; set; }
/// <summary>
/// The security token that is added as request header.
/// </summary>
[Required]
public string SecurityToken { get; set; }
}
}

114
src/Squidex/Controllers/Api/Webhooks/WebhooksController.cs

@ -0,0 +1,114 @@
// ==========================================================================
// WebhooksController.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using NSwag.Annotations;
using Squidex.Controllers.Api.Webhooks.Models;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.Reflection;
using Squidex.Pipeline;
using Squidex.Read.Schemas.Repositories;
using Squidex.Write.Schemas.Commands;
namespace Squidex.Controllers.Api.Webhooks
{
/// <summary>
/// Manages and retrieves information about schemas.
/// </summary>
[ApiExceptionFilter]
[AppApi]
[SwaggerTag("Webhooks")]
[MustBeAppDeveloper]
public class WebhooksController : ControllerBase
{
private readonly ISchemaWebhookRepository webhooksRepository;
public WebhooksController(ICommandBus commandBus, ISchemaWebhookRepository webhooksRepository)
: base(commandBus)
{
this.webhooksRepository = webhooksRepository;
}
/// <summary>
/// Get webhooks.
/// </summary>
/// <param name="app">The name of the app to get the schema for.</param>
/// <returns>
/// 200 => Schemas returned.
/// 404 => App not found.
/// </returns>
[HttpGet]
[Route("apps/{app}/webhooks/")]
[ProducesResponseType(typeof(WebhookDto[]), 200)]
[ApiCosts(1)]
public async Task<IActionResult> GetWebhooks(string app)
{
var webhooks = await webhooksRepository.QueryByAppAsync(App.Id);
Response.Headers["ETag"] = new StringValues(App.Version.ToString());
var response = webhooks.Select(w => SimpleMapper.Map(w, new WebhookDto()));
return Ok(response);
}
/// <summary>
/// Create a new webhook.
/// </summary>
/// <param name="request">The webhook object that needs to be added to the app.</param>
/// <param name="name">The name of the schema.</param>
/// <param name="app">The name of the app to create the webhook for.</param>
/// <returns>
/// 201 => Webhook created.
/// 400 => Webhook name or properties are not valid.
/// 409 => Webhook name already in use.
/// 404 => App or schema not found.
/// </returns>
/// <remarks>
/// All events for the specified app will be sent to the url. The timeout is 2 seconds.
/// </remarks>
[HttpPost]
[Route("apps/{app}/schemas/{name}/webhooks/")]
[ProducesResponseType(typeof(WebhookDto), 201)]
[ProducesResponseType(typeof(ErrorDto), 400)]
[ProducesResponseType(typeof(ErrorDto), 409)]
[ApiCosts(1)]
public async Task<IActionResult> PostWebhook(string app, string name, [FromBody] CreateWebhookDto request)
{
var command = new AddWebhook { Url = request.Url };
await CommandBus.PublishAsync(command);
return CreatedAtAction(nameof(GetWebhooks), new { app }, SimpleMapper.Map(command, new WebhookDto()));
}
/// <summary>
/// Delete a webhook.
/// </summary>
/// <param name="app">The app where the webhook is a part of.</param>
/// <param name="name">The name of the schema.</param>
/// <param name="id">The id of the webhook to delete.</param>
/// <returns>
/// 204 => Webhook has been deleted.
/// 404 => Webhook or shema or app not found.
/// </returns>
[HttpDelete]
[Route("apps/{app}/schemas/{name}/webhooks/{id}")]
[ApiCosts(1)]
public async Task<IActionResult> DeleteSchema(string app, string name, Guid id)
{
await CommandBus.PublishAsync(new DeleteWebhook { Id = id });
return NoContent();
}
}
}
Loading…
Cancel
Save