mirror of https://github.com/Squidex/squidex.git
12 changed files with 220 additions and 34 deletions
@ -0,0 +1,127 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AppPatternsController.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 NSwag.Annotations; |
||||
|
using Squidex.Areas.Api.Controllers.Apps.Models; |
||||
|
using Squidex.Domain.Apps.Entities.Apps.Commands; |
||||
|
using Squidex.Infrastructure.Commands; |
||||
|
using Squidex.Infrastructure.Reflection; |
||||
|
using Squidex.Pipeline; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Manages and configures app patterns.
|
||||
|
/// </summary>
|
||||
|
[ApiAuthorize] |
||||
|
[MustBeAppDeveloper] |
||||
|
[ApiExceptionFilter] |
||||
|
[AppApi] |
||||
|
[SwaggerTag(nameof(Apps))] |
||||
|
public sealed class AppPatternsController : ApiController |
||||
|
{ |
||||
|
public AppPatternsController(ICommandBus commandBus) |
||||
|
: base(commandBus) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Get app patterns.
|
||||
|
/// </summary>
|
||||
|
/// <param name="app">The name of the app.</param>
|
||||
|
/// <returns>
|
||||
|
/// 200 => Patterns returned.
|
||||
|
/// 404 => App not found.
|
||||
|
/// </returns>
|
||||
|
/// <remarks>
|
||||
|
/// Gets all configured regex patterns for the app with the specified name.
|
||||
|
/// </remarks>
|
||||
|
[HttpGet] |
||||
|
[Route("apps/{app}/patterns/")] |
||||
|
[ProducesResponseType(typeof(AppPatternDto[]), 200)] |
||||
|
[ApiCosts(1)] |
||||
|
public IActionResult GetPatterns(string app) |
||||
|
{ |
||||
|
var response = |
||||
|
App.Patterns.Select(x => SimpleMapper.Map(x.Value, new AppPatternDto { Id = x.Key })).OrderBy(x => x.Name).ToList(); |
||||
|
|
||||
|
return Ok(response); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Create a new app patterm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="app">The name of the app.</param>
|
||||
|
/// <param name="request">Pattern to be added to the app.</param>
|
||||
|
/// <returns>
|
||||
|
/// 201 => Pattern generated.
|
||||
|
/// 404 => App not found.
|
||||
|
/// </returns>
|
||||
|
[HttpPost] |
||||
|
[Route("apps/{app}/patterns/")] |
||||
|
[ProducesResponseType(typeof(AppPatternDto), 201)] |
||||
|
[ApiCosts(1)] |
||||
|
public async Task<IActionResult> PostPattern(string app, [FromBody] UpdatePatternDto request) |
||||
|
{ |
||||
|
var command = SimpleMapper.Map(request, new AddPattern()); |
||||
|
|
||||
|
await CommandBus.PublishAsync(command); |
||||
|
|
||||
|
return CreatedAtAction(nameof(GetPatterns), new { app }, request); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Update an existing app patterm.
|
||||
|
/// </summary>
|
||||
|
/// <param name="app">The name of the app.</param>
|
||||
|
/// <param name="id">The id of the pattern to be updated.</param>
|
||||
|
/// <param name="request">Pattern to be updated for the app.</param>
|
||||
|
/// <returns>
|
||||
|
/// 204 => Pattern updated.
|
||||
|
/// 404 => App not found or pattern not found.
|
||||
|
/// </returns>
|
||||
|
[HttpPut] |
||||
|
[Route("apps/{app}/patterns/{name}")] |
||||
|
[ProducesResponseType(typeof(AppPatternDto), 201)] |
||||
|
[ApiCosts(1)] |
||||
|
public async Task<IActionResult> UpdatePattern(string app, Guid id, [FromBody] UpdatePatternDto request) |
||||
|
{ |
||||
|
var command = SimpleMapper.Map(request, new UpdatePattern { Id = id }); |
||||
|
|
||||
|
await CommandBus.PublishAsync(command); |
||||
|
|
||||
|
return NoContent(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Revoke an app client
|
||||
|
/// </summary>
|
||||
|
/// <param name="app">The name of the app.</param>
|
||||
|
/// <param name="id">The id of the pattern to be deleted.</param>
|
||||
|
/// <returns>
|
||||
|
/// 204 => Pattern removed.
|
||||
|
/// 404 => App or pattern not found.
|
||||
|
/// </returns>
|
||||
|
/// <remarks>
|
||||
|
/// Schemas using this pattern will still function using the same Regular Expression
|
||||
|
/// </remarks>
|
||||
|
[HttpDelete] |
||||
|
[Route("apps/{app}/patterns/{id}/")] |
||||
|
[ApiCosts(1)] |
||||
|
public async Task<IActionResult> DeletePattern(string app, Guid id) |
||||
|
{ |
||||
|
await CommandBus.PublishAsync(new DeletePattern { Id = id }); |
||||
|
|
||||
|
return NoContent(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AppPatternDto.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps.Models |
||||
|
{ |
||||
|
public sealed class AppPatternDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Identifier for Pattern
|
||||
|
/// </summary>
|
||||
|
public Guid Id { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The name of the suggestion.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The regex pattern.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public string Pattern { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The regex message.
|
||||
|
/// </summary>
|
||||
|
public string Message { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
// ==========================================================================
|
||||
|
// AddPatternDto.cs
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex Group
|
||||
|
// All rights reserved.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace Squidex.Areas.Api.Controllers.Apps.Models |
||||
|
{ |
||||
|
public class UpdatePatternDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The name of the suggestion.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The regex pattern.
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
public string Pattern { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The regex message.
|
||||
|
/// </summary>
|
||||
|
public string Message { get; set; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue