Browse Source

No Api for languages

pull/1/head
Sebastian 9 years ago
parent
commit
ab8d774c93
  1. 2
      src/Squidex.Core/Schemas/Schema.cs
  2. 2
      src/Squidex.Infrastructure/Dispatching/ActionContextDispatcher.cs
  3. 2
      src/Squidex.Infrastructure/Dispatching/ActionDispatcher.cs
  4. 2
      src/Squidex.Infrastructure/Dispatching/FuncDispatcher.cs
  5. 1
      src/Squidex.Store.MongoDb/Apps/MongoAppRepository.cs
  6. 26
      src/Squidex.Write/Apps/AppDomainObject.cs
  7. 5
      src/Squidex.Write/Apps/AppLanguages.cs
  8. 26
      src/Squidex.Write/Apps/Commands/ConfigureLanguages.cs
  9. 18
      src/Squidex.Write/Schemas/SchemaDomainObject.cs
  10. 10
      src/Squidex/Controllers/Api/Apps/AppContributorsController.cs
  11. 6
      src/Squidex/Controllers/Api/Apps/AppController.cs
  12. 65
      src/Squidex/Controllers/Api/Apps/AppLanguagesController.cs
  13. 11
      src/Squidex/Controllers/Api/Apps/Models/AddLanguageDto.cs
  14. 18
      src/Squidex/Controllers/Api/Apps/Models/SetMasterLanguageDto.cs
  15. 32
      src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs
  16. 14
      src/Squidex/Controllers/Api/Schemas/SchemasController.cs
  17. 2
      src/Squidex/Controllers/Api/Users/UsersController.cs
  18. 1
      tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs
  19. 135
      tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs

2
src/Squidex.Core/Schemas/Schema.cs

@ -129,7 +129,7 @@ namespace Squidex.Core.Schemas
if (!fieldsById.TryGetValue(fieldId, out field)) if (!fieldsById.TryGetValue(fieldId, out field))
{ {
throw new DomainObjectNotFoundException(fieldId.ToString(), typeof(Field)); throw new DomainObjectNotFoundException(fieldId.ToString(), "Fields", typeof(Field));
} }
var newField = updater(field); var newField = updater(field);

2
src/Squidex.Infrastructure/Dispatching/ActionContextDispatcher.cs

@ -21,7 +21,7 @@ namespace Squidex.Infrastructure.Dispatching
{ {
Handlers = Handlers =
typeof(TTarget) typeof(TTarget)
.GetMethods() .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(Helper.HasRightName) .Where(Helper.HasRightName)
.Where(Helper.HasRightParameters<TIn, TContext>) .Where(Helper.HasRightParameters<TIn, TContext>)
.Select(ActionContextDispatcherFactory.CreateActionHandler<TTarget, TContext>) .Select(ActionContextDispatcherFactory.CreateActionHandler<TTarget, TContext>)

2
src/Squidex.Infrastructure/Dispatching/ActionDispatcher.cs

@ -21,7 +21,7 @@ namespace Squidex.Infrastructure.Dispatching
{ {
Handlers = Handlers =
typeof(TTarget) typeof(TTarget)
.GetMethods() .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(Helper.HasRightName) .Where(Helper.HasRightName)
.Where(Helper.HasRightParameters<TIn>) .Where(Helper.HasRightParameters<TIn>)
.Select(ActionDispatcherFactory.CreateActionHandler<TTarget>) .Select(ActionDispatcherFactory.CreateActionHandler<TTarget>)

2
src/Squidex.Infrastructure/Dispatching/FuncDispatcher.cs

@ -21,7 +21,7 @@ namespace Squidex.Infrastructure.Dispatching
{ {
Handlers = Handlers =
typeof(TTarget) typeof(TTarget)
.GetMethods() .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(Helper.HasRightName) .Where(Helper.HasRightName)
.Where(Helper.HasRightParameters<TIn>) .Where(Helper.HasRightParameters<TIn>)
.Where(Helper.HasRightReturnType<TOut>) .Where(Helper.HasRightReturnType<TOut>)

1
src/Squidex.Store.MongoDb/Apps/MongoAppRepository.cs

@ -7,7 +7,6 @@
// ========================================================================== // ==========================================================================
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using Squidex.Events.Apps; using Squidex.Events.Apps;

26
src/Squidex.Write/Apps/AppDomainObject.cs

@ -7,21 +7,21 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using Squidex.Core.Apps; using Squidex.Core.Apps;
using Squidex.Events.Apps; using Squidex.Events.Apps;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS; using Squidex.Infrastructure.CQRS;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.CQRS.Events; using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.Dispatching; using Squidex.Infrastructure.Dispatching;
using Squidex.Write.Apps.Commands;
using System.Collections.Generic;
using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Write.Apps.Commands;
// ReSharper disable InvertIf // ReSharper disable InvertIf
namespace Squidex.Write.Apps namespace Squidex.Write.Apps
{ {
public sealed class AppDomainObject : DomainObject public class AppDomainObject : DomainObject
{ {
private static readonly Language DefaultLanguage = Language.GetLanguage("en"); private static readonly Language DefaultLanguage = Language.GetLanguage("en");
private readonly AppContributors contributors = new AppContributors(); private readonly AppContributors contributors = new AppContributors();
@ -44,47 +44,47 @@ namespace Squidex.Write.Apps
{ {
} }
public void On(AppCreated @event) protected void On(AppCreated @event)
{ {
name = @event.Name; name = @event.Name;
} }
public void On(AppContributorAssigned @event) protected void On(AppContributorAssigned @event)
{ {
contributors.Assign(@event.ContributorId, @event.Permission); contributors.Assign(@event.ContributorId, @event.Permission);
} }
public void On(AppContributorRemoved @event) protected void On(AppContributorRemoved @event)
{ {
contributors.Remove(@event.ContributorId); contributors.Remove(@event.ContributorId);
} }
public void On(AppClientAttached @event) protected void On(AppClientAttached @event)
{ {
clients.Add(@event.Id, @event.Secret, @event.ExpiresUtc); clients.Add(@event.Id, @event.Secret, @event.ExpiresUtc);
} }
public void On(AppClientRenamed @event) protected void On(AppClientRenamed @event)
{ {
clients.Rename(@event.Id, @event.Name); clients.Rename(@event.Id, @event.Name);
} }
public void On(AppClientRevoked @event) protected void On(AppClientRevoked @event)
{ {
clients.Revoke(@event.Id); clients.Revoke(@event.Id);
} }
public void On(AppLanguageAdded @event) protected void On(AppLanguageAdded @event)
{ {
languages.Add(@event.Language); languages.Add(@event.Language);
} }
public void On(AppLanguageRemoved @event) protected void On(AppLanguageRemoved @event)
{ {
languages.Remove(@event.Language); languages.Remove(@event.Language);
} }
public void On(AppMasterLanguageSet @event) protected void On(AppMasterLanguageSet @event)
{ {
languages.SetMasterLanguage(@event.Language); languages.SetMasterLanguage(@event.Language);
} }

5
src/Squidex.Write/Apps/AppLanguages.cs

@ -18,11 +18,6 @@ namespace Squidex.Write.Apps
private readonly HashSet<Language> languages = new HashSet<Language>(); private readonly HashSet<Language> languages = new HashSet<Language>();
private Language masterLanguage; private Language masterLanguage;
public IReadOnlyCollection<Language> Languages
{
get { return languages; }
}
public void Add(Language language) public void Add(Language language)
{ {
Func<string> message = () => "Cannot add language"; Func<string> message = () => "Cannot add language";

26
src/Squidex.Write/Apps/Commands/ConfigureLanguages.cs

@ -1,26 +0,0 @@
// ==========================================================================
// ConfigureLanguages.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using Squidex.Infrastructure;
namespace Squidex.Write.Apps.Commands
{
public sealed class ConfigureLanguages : AppAggregateCommand, IValidatable
{
public List<Language> Languages { get; set; }
public void Validate(IList<ValidationError> errors)
{
if (Languages == null || Languages.Count == 0)
{
errors.Add(new ValidationError("Languages need at least one element.", nameof(Languages)));
}
}
}
}

18
src/Squidex.Write/Schemas/SchemaDomainObject.cs

@ -50,47 +50,47 @@ namespace Squidex.Write.Schemas
schema = schema.AddOrUpdateField(registry.CreateField(@event.FieldId, @event.Name, @event.Properties)); schema = schema.AddOrUpdateField(registry.CreateField(@event.FieldId, @event.Name, @event.Properties));
} }
public void On(SchemaCreated @event) protected void On(SchemaCreated @event)
{ {
schema = Schema.Create(@event.Name, @event.Properties); schema = Schema.Create(@event.Name, @event.Properties);
} }
public void On(FieldUpdated @event) protected void On(FieldUpdated @event)
{ {
schema = schema.UpdateField(@event.FieldId, @event.Properties); schema = schema.UpdateField(@event.FieldId, @event.Properties);
} }
public void On(FieldHidden @event) protected void On(FieldHidden @event)
{ {
schema = schema.HideField(@event.FieldId); schema = schema.HideField(@event.FieldId);
} }
public void On(FieldShown @event) protected void On(FieldShown @event)
{ {
schema = schema.ShowField(@event.FieldId); schema = schema.ShowField(@event.FieldId);
} }
public void On(FieldDisabled @event) protected void On(FieldDisabled @event)
{ {
schema = schema.DisableField(@event.FieldId); schema = schema.DisableField(@event.FieldId);
} }
public void On(FieldEnabled @event) protected void On(FieldEnabled @event)
{ {
schema = schema.EnableField(@event.FieldId); schema = schema.EnableField(@event.FieldId);
} }
public void On(SchemaUpdated @event) protected void On(SchemaUpdated @event)
{ {
schema = schema.Update(@event.Properties); schema = schema.Update(@event.Properties);
} }
public void On(FieldDeleted @event) protected void On(FieldDeleted @event)
{ {
schema = schema.DeleteField(@event.FieldId); schema = schema.DeleteField(@event.FieldId);
} }
public void On(SchemaDeleted @event) protected void On(SchemaDeleted @event)
{ {
isDeleted = true; isDeleted = true;
} }

10
src/Squidex/Controllers/Api/Apps/AppContributorsController.cs

@ -66,7 +66,7 @@ namespace Squidex.Controllers.Api.Apps
/// Assign contributor to app. /// Assign contributor to app.
/// </summary> /// </summary>
/// <param name="app">The name of the app.</param> /// <param name="app">The name of the app.</param>
/// <param name="model">Contributor object that needs to be added to the app.</param> /// <param name="request">Contributor object that needs to be added to the app.</param>
/// <returns> /// <returns>
/// 204 => User assigned to app. /// 204 => User assigned to app.
/// 400 => User is already assigned to the app or not found. /// 400 => User is already assigned to the app or not found.
@ -74,10 +74,10 @@ namespace Squidex.Controllers.Api.Apps
/// </returns> /// </returns>
[HttpPost] [HttpPost]
[Route("apps/{app}/contributors/")] [Route("apps/{app}/contributors/")]
[ProducesResponseType(typeof(ErrorDto[]), 400)] [ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> PostContributor(string app, [FromBody] AssignContributorDto model) public async Task<IActionResult> PostContributor(string app, [FromBody] AssignContributorDto request)
{ {
await CommandBus.PublishAsync(SimpleMapper.Map(model, new AssignContributor())); await CommandBus.PublishAsync(SimpleMapper.Map(request, new AssignContributor()));
return NoContent(); return NoContent();
} }
@ -93,7 +93,7 @@ namespace Squidex.Controllers.Api.Apps
/// </returns> /// </returns>
[HttpDelete] [HttpDelete]
[Route("apps/{app}/contributors/{id}/")] [Route("apps/{app}/contributors/{id}/")]
[ProducesResponseType(typeof(ErrorDto[]), 400)] [ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> DeleteContributor(string app, string id) public async Task<IActionResult> DeleteContributor(string app, string id)
{ {
await CommandBus.PublishAsync(new RemoveContributor { ContributorId = id }); await CommandBus.PublishAsync(new RemoveContributor { ContributorId = id });

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

@ -71,7 +71,7 @@ namespace Squidex.Controllers.Api.Apps
/// <summary> /// <summary>
/// Create a new app. /// Create a new app.
/// </summary> /// </summary>
/// <param name="model">The app object that needs to be added to squidex.</param> /// <param name="request">The app object that needs to be added to squidex.</param>
/// <returns> /// <returns>
/// 201 => App created. /// 201 => App created.
/// 400 => App object is not valid. /// 400 => App object is not valid.
@ -86,9 +86,9 @@ namespace Squidex.Controllers.Api.Apps
[ProducesResponseType(typeof(EntityCreatedDto), 201)] [ProducesResponseType(typeof(EntityCreatedDto), 201)]
[ProducesResponseType(typeof(ErrorDto), 400)] [ProducesResponseType(typeof(ErrorDto), 400)]
[ProducesResponseType(typeof(ErrorDto), 409)] [ProducesResponseType(typeof(ErrorDto), 409)]
public async Task<IActionResult> PostApp([FromBody] CreateAppDto model) public async Task<IActionResult> PostApp([FromBody] CreateAppDto request)
{ {
var command = SimpleMapper.Map(model, new CreateApp()); var command = SimpleMapper.Map(request, new CreateApp());
var context = await CommandBus.PublishAsync(command); var context = await CommandBus.PublishAsync(command);
var result = context.Result<Guid>(); var result = context.Result<Guid>();

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

@ -14,6 +14,7 @@ using NSwag.Annotations;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Controllers.Api.Apps.Models; using Squidex.Controllers.Api.Apps.Models;
using Squidex.Infrastructure;
using Squidex.Pipeline; using Squidex.Pipeline;
using Squidex.Read.Apps.Services; using Squidex.Read.Apps.Services;
using Squidex.Write.Apps.Commands; using Squidex.Write.Apps.Commands;
@ -63,26 +64,66 @@ namespace Squidex.Controllers.Api.Apps
} }
/// <summary> /// <summary>
/// Configure the app languages. /// Attaches an app language.
/// </summary> /// </summary>
/// <param name="app">The name of the app.</param> /// <param name="app">The name of the app.</param>
/// <param name="model">The language configuration for the app.</param> /// <param name="request">The language to add to the app.</param>
/// <returns> /// <returns>
/// 204 => App languages configured. /// 201 => App language created.
/// 400 => Language configuration is empty or contains an invalid language. /// 400 => Language is an invalid language.
/// 404 => App not found. /// 404 => App not found.
/// </returns> /// </returns>
/// <remarks>
/// The ordering of the languages matterns: When you retrieve a content with a localized content squidex tries
/// to resolve the correct language for these properties. When there is no value for a property in the specified language,
/// the previous languages from languages list is uses as a fallback.
/// </remarks>
[HttpPost] [HttpPost]
[Route("apps/{app}/languages/")] [Route("apps/{app}/languages/")]
[ProducesResponseType(typeof(ErrorDto[]), 400)] [ProducesResponseType(typeof(LanguageDto), 201)]
public async Task<IActionResult> PostLanguages(string app, [FromBody] ConfigureLanguagesDto model) [ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> PostLanguage(string app, [FromBody] AddLanguageDto request)
{ {
await CommandBus.PublishAsync(SimpleMapper.Map(model, new ConfigureLanguages())); await CommandBus.PublishAsync(SimpleMapper.Map(request, new AddLanguage()));
var response = SimpleMapper.Map(request.Language, new LanguageDto());
return StatusCode(201, response);
}
/// <summary>
/// Updates an app language.
/// </summary>
/// <param name="app">The name of the app.</param>
/// <param name="language">The language to delete from the app.</param>
/// <param name="model">The language properties.</param>
/// <returns>
/// 204 => App language updated.
/// 400 => Language is an invalid language.
/// 404 => App not found.
/// </returns>
[HttpPut]
[Route("apps/{app}/languages/{language}")]
public async Task<IActionResult> Update(string app, string language, [FromBody] SetMasterLanguageDto model)
{
if (model.IsMasterLanguage)
{
await CommandBus.PublishAsync(new SetMasterLanguage { Language = Language.GetLanguage(language) });
}
return NoContent();
}
/// <summary>
/// Deletes an app language.
/// </summary>
/// <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.
/// 400 => Language is an invalid language.
/// 404 => App not found.
/// </returns>
[HttpDelete]
[Route("apps/{app}/languages/{language}")]
public async Task<IActionResult> DeleteLanguage(string app, string language)
{
await CommandBus.PublishAsync(new RemoveLanguage { Language = Language.GetLanguage(language) });
return NoContent(); return NoContent();
} }

11
src/Squidex/Controllers/Api/Apps/Models/ConfigureLanguagesDto.cs → src/Squidex/Controllers/Api/Apps/Models/AddLanguageDto.cs

@ -1,21 +1,22 @@
// ========================================================================== // ==========================================================================
// ConfigureLanguagesDto.cs // AddLanguageDto.cs
// Squidex Headless CMS // Squidex Headless CMS
// ========================================================================== // ==========================================================================
// Copyright (c) Squidex Group // Copyright (c) Squidex Group
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System.Collections.Generic; using System.ComponentModel.DataAnnotations;
using Squidex.Infrastructure; using Squidex.Infrastructure;
namespace Squidex.Controllers.Api.Apps.Models namespace Squidex.Controllers.Api.Apps.Models
{ {
public sealed class ConfigureLanguagesDto public class AddLanguageDto
{ {
/// <summary> /// <summary>
/// The list of languages to configure the app. /// The language to add.
/// </summary> /// </summary>
public List<Language> Languages { get; set; } [Required]
public Language Language { get; set; }
} }
} }

18
src/Squidex/Controllers/Api/Apps/Models/SetMasterLanguageDto.cs

@ -0,0 +1,18 @@
// ==========================================================================
// SetMasterLanguageDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
namespace Squidex.Controllers.Api.Apps.Models
{
public class SetMasterLanguageDto
{
/// <summary>
/// Set the value to true to make the language to the master language.
/// </summary>
public bool IsMasterLanguage { get; set; }
}
}

32
src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs

@ -36,21 +36,21 @@ namespace Squidex.Controllers.Api.Schemas
/// </summary> /// </summary>
/// <param name="app">The name of the app.</param> /// <param name="app">The name of the app.</param>
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="model">The field object that needs to be added to the schema.</param> /// <param name="request">The field object that needs to be added to the schema.</param>
/// <returns> /// <returns>
/// 201 => Field created. /// 201 => Schema field created.
/// 409 => Field name already in use. /// 409 => Schema field name already in use.
/// 404 => App or schema not found. /// 404 => App or schema not found.
/// 404 => Field properties not valid. /// 404 => Schema field properties not valid.
/// </returns> /// </returns>
[HttpPost] [HttpPost]
[Route("apps/{app}/schemas/{name}/fields/")] [Route("apps/{app}/schemas/{name}/fields/")]
[ProducesResponseType(typeof(EntityCreatedDto), 201)] [ProducesResponseType(typeof(EntityCreatedDto), 201)]
[ProducesResponseType(typeof(ErrorDto), 409)] [ProducesResponseType(typeof(ErrorDto), 409)]
[ProducesResponseType(typeof(ErrorDto), 400)] [ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> PostField(string app, string name, [FromBody] AddFieldDto model) public async Task<IActionResult> PostField(string app, string name, [FromBody] AddFieldDto request)
{ {
var command = new AddField { Name = model.Name, Properties = model.Properties.ToProperties() }; var command = new AddField { Name = request.Name, Properties = request.Properties.ToProperties() };
var context = await CommandBus.PublishAsync(command); var context = await CommandBus.PublishAsync(command);
var result = context.Result<long>(); var result = context.Result<long>();
@ -63,20 +63,20 @@ namespace Squidex.Controllers.Api.Schemas
/// </summary> /// </summary>
/// <param name="app">The name of the app.</param> /// <param name="app">The name of the app.</param>
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="model">The field object that needs to be added to the schema.</param> /// <param name="request">The field object that needs to be added to the schema.</param>
/// <returns> /// <returns>
/// 204 => Field created. /// 204 => Schema field created.
/// 409 => Field name already in use. /// 409 => Schema field name already in use.
/// 404 => App, schema or field not found. /// 404 => App, schema or field not found.
/// 404 => Field properties not valid. /// 404 => Schema field properties not valid.
/// </returns> /// </returns>
[HttpPut] [HttpPut]
[Route("apps/{app}/schemas/{name}/fields/{id:long}/")] [Route("apps/{app}/schemas/{name}/fields/{id:long}/")]
[ProducesResponseType(typeof(ErrorDto), 409)] [ProducesResponseType(typeof(ErrorDto), 409)]
[ProducesResponseType(typeof(ErrorDto), 400)] [ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> PutField(string app, string name, long id, [FromBody] UpdateFieldDto model) public async Task<IActionResult> PutField(string app, string name, long id, [FromBody] UpdateFieldDto request)
{ {
var command = new UpdateField { FieldId = id, Properties = model.Properties.ToProperties() }; var command = new UpdateField { FieldId = id, Properties = request.Properties.ToProperties() };
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);
@ -90,7 +90,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="id">The id of the field to hide.</param> /// <param name="id">The id of the field to hide.</param>
/// <returns> /// <returns>
/// 400 => Field already hidden. /// 400 => Schema field already hidden.
/// 204 => Schema field hidden. /// 204 => Schema field hidden.
/// 404 => App, schema or field not found. /// 404 => App, schema or field not found.
/// </returns> /// </returns>
@ -116,7 +116,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="id">The id of the field to shows.</param> /// <param name="id">The id of the field to shows.</param>
/// <returns> /// <returns>
/// 400 => Field already visible. /// 400 => Schema field already visible.
/// 204 => Schema field shown. /// 204 => Schema field shown.
/// 404 => App, schema or field not found. /// 404 => App, schema or field not found.
/// </returns> /// </returns>
@ -142,7 +142,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="id">The id of the field to enable.</param> /// <param name="id">The id of the field to enable.</param>
/// <returns> /// <returns>
/// 400 => Field already enabled. /// 400 => Schema field already enabled.
/// 204 => Schema field enabled. /// 204 => Schema field enabled.
/// 404 => App, schema or field not found. /// 404 => App, schema or field not found.
/// </returns> /// </returns>
@ -169,7 +169,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="id">The id of the field to disable.</param> /// <param name="id">The id of the field to disable.</param>
/// <returns> /// <returns>
/// 400 => Field already disabled. /// 400 => Schema field already disabled.
/// 204 => Schema field disabled. /// 204 => Schema field disabled.
/// 404 => App, schema or field not found. /// 404 => App, schema or field not found.
/// </returns> /// </returns>

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

@ -85,7 +85,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <summary> /// <summary>
/// Create a new schema. /// Create a new schema.
/// </summary> /// </summary>
/// <param name="model">The schema object that needs to be added to the app.</param> /// <param name="request">The schema object that needs to be added to the app.</param>
/// <param name="app">The name of the app to create the schema to.</param> /// <param name="app">The name of the app to create the schema to.</param>
/// <returns> /// <returns>
/// 201 => Schema created. /// 201 => Schema created.
@ -97,13 +97,13 @@ namespace Squidex.Controllers.Api.Schemas
[ProducesResponseType(typeof(EntityCreatedDto), 201)] [ProducesResponseType(typeof(EntityCreatedDto), 201)]
[ProducesResponseType(typeof(ErrorDto), 400)] [ProducesResponseType(typeof(ErrorDto), 400)]
[ProducesResponseType(typeof(ErrorDto), 409)] [ProducesResponseType(typeof(ErrorDto), 409)]
public async Task<IActionResult> PostSchema(string app, [FromBody] CreateSchemaDto model) public async Task<IActionResult> PostSchema(string app, [FromBody] CreateSchemaDto request)
{ {
var command = SimpleMapper.Map(model, new CreateSchema { AggregateId = Guid.NewGuid() }); var command = SimpleMapper.Map(request, new CreateSchema { AggregateId = Guid.NewGuid() });
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);
return CreatedAtAction(nameof(GetSchema), new { name = model.Name }, new EntityCreatedDto { Id = command.Name }); return CreatedAtAction(nameof(GetSchema), new { name = request.Name }, new EntityCreatedDto { Id = command.Name });
} }
/// <summary> /// <summary>
@ -111,15 +111,15 @@ namespace Squidex.Controllers.Api.Schemas
/// </summary> /// </summary>
/// <param name="app">The app where the schema is a part of.</param> /// <param name="app">The app where the schema is a part of.</param>
/// <param name="name">The name of the schema.</param> /// <param name="name">The name of the schema.</param>
/// <param name="model">The schema object that needs to updated.</param> /// <param name="request">The schema object that needs to updated.</param>
/// <returns> /// <returns>
/// 204 => Schema updated. /// 204 => Schema updated.
/// </returns> /// </returns>
[HttpPut] [HttpPut]
[Route("apps/{app}/schemas/{name}/")] [Route("apps/{app}/schemas/{name}/")]
public async Task<IActionResult> PutSchema(string app, string name, [FromBody] UpdateSchemaDto model) public async Task<IActionResult> PutSchema(string app, string name, [FromBody] UpdateSchemaDto request)
{ {
var command = SimpleMapper.Map(model, new UpdateSchema()); var command = SimpleMapper.Map(request, new UpdateSchema());
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);

2
src/Squidex/Controllers/Api/Users/UsersController.cs

@ -61,7 +61,7 @@ namespace Squidex.Controllers.Api.Users
/// <param name="id">The id of the user (GUID).</param> /// <param name="id">The id of the user (GUID).</param>
/// <returns> /// <returns>
/// 200 => User found. /// 200 => User found.
/// 400 => User not found. /// 404 => User not found.
/// </returns> /// </returns>
[HttpGet] [HttpGet]
[Route("users/{id}/")] [Route("users/{id}/")]

1
tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs

@ -7,7 +7,6 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;

135
tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs

@ -164,7 +164,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AttachClient_should_throw_if_name_already_exists() public void AttachClient_should_throw_if_id_already_exists()
{ {
CreateApp(); CreateApp();
@ -191,7 +191,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RevokeKey_should_throw_if_not_created() public void RevokeClient_should_throw_if_not_created()
{ {
Assert.Throws<DomainException>(() => sut.RevokeClient(new RevokeClient { Id = "not-found" })); Assert.Throws<DomainException>(() => sut.RevokeClient(new RevokeClient { Id = "not-found" }));
} }
@ -230,7 +230,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RenameKey_should_throw_if_not_created() public void RenameClient_should_throw_if_not_created()
{ {
Assert.Throws<DomainException>(() => sut.RenameClient(new RenameClient { Id = "not-found", Name = clientNewName })); Assert.Throws<DomainException>(() => sut.RenameClient(new RenameClient { Id = "not-found", Name = clientNewName }));
} }
@ -268,6 +268,135 @@ namespace Squidex.Write.Apps
}); });
} }
[Fact]
public void AddLanguage_should_throw_if_not_created()
{
Assert.Throws<DomainException>(() => sut.AddLanguage(new AddLanguage { Language = Language.GetLanguage("de") }));
}
[Fact]
public void AddLanguage_should_throw_if_command_is_not_valid()
{
CreateApp();
Assert.Throws<ValidationException>(() => sut.AddLanguage(new AddLanguage()));
}
[Fact]
public void AddLanguage_should_throw_if_language_already_exists()
{
CreateApp();
Assert.Throws<ValidationException>(() => sut.AddLanguage(new AddLanguage { Language = Language.GetLanguage("en") }));
}
[Fact]
public void AddLanguage_should_create_events()
{
CreateApp();
sut.AddLanguage(new AddLanguage { Language = Language.GetLanguage("de") });
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray()
.ShouldBeEquivalentTo(
new IEvent[]
{
new AppLanguageAdded { Language = Language.GetLanguage("de") }
});
}
[Fact]
public void RemoveLanguage_should_throw_if_not_created()
{
Assert.Throws<DomainException>(() => sut.RemoveLanguage(new RemoveLanguage { Language = Language.GetLanguage("en") }));
}
[Fact]
public void RemoveLanguage_should_throw_if_command_is_not_valid()
{
CreateApp();
Assert.Throws<ValidationException>(() => sut.RemoveLanguage(new RemoveLanguage()));
}
[Fact]
public void RemoveLanguage_should_throw_if_language_not_found()
{
CreateApp();
Assert.Throws<DomainObjectNotFoundException>(() => sut.RemoveLanguage(new RemoveLanguage { Language = Language.GetLanguage("de") }));
}
[Fact]
public void RemoveLanguage_should_throw_if_master_language()
{
CreateApp();
Assert.Throws<ValidationException>(() => sut.RemoveLanguage(new RemoveLanguage { Language = Language.GetLanguage("en") }));
}
[Fact]
public void RemoveLanguage_should_create_events()
{
CreateApp();
sut.AddLanguage(new AddLanguage { Language = Language.GetLanguage("de") });
sut.RemoveLanguage(new RemoveLanguage { Language = Language.GetLanguage("de") });
sut.GetUncomittedEvents().Select(x => x.Payload).Skip(1).ToArray()
.ShouldBeEquivalentTo(
new IEvent[]
{
new AppLanguageRemoved { Language = Language.GetLanguage("de") }
});
}
[Fact]
public void SetMasterLanguage_should_throw_if_not_created()
{
Assert.Throws<DomainException>(() => sut.SetMasterLanguage(new SetMasterLanguage { Language = Language.GetLanguage("en") }));
}
[Fact]
public void SetMasterLanguage_should_throw_if_command_is_not_valid()
{
CreateApp();
Assert.Throws<ValidationException>(() => sut.SetMasterLanguage(new SetMasterLanguage()));
}
[Fact]
public void SetMasterLanguage_should_throw_if_language_not_found()
{
CreateApp();
Assert.Throws<DomainObjectNotFoundException>(() => sut.SetMasterLanguage(new SetMasterLanguage { Language = Language.GetLanguage("de") }));
}
[Fact]
public void SetMasterLanguage_should_throw_if_already_master_language()
{
CreateApp();
Assert.Throws<ValidationException>(() => sut.SetMasterLanguage(new SetMasterLanguage { Language = Language.GetLanguage("en") }));
}
[Fact]
public void SetMasterLanguage_should_create_events()
{
CreateApp();
sut.AddLanguage(new AddLanguage { Language = Language.GetLanguage("de") });
sut.SetMasterLanguage(new SetMasterLanguage { Language = Language.GetLanguage("de") });
sut.GetUncomittedEvents().Select(x => x.Payload).Skip(1).ToArray()
.ShouldBeEquivalentTo(
new IEvent[]
{
new AppMasterLanguageSet { Language = Language.GetLanguage("de") }
});
}
private void CreateApp() private void CreateApp()
{ {
sut.Create(new CreateApp { Name = TestName, User = user }); sut.Create(new CreateApp { Name = TestName, User = user });

Loading…
Cancel
Save