Browse Source

Small bugs fixes

pull/1/head
Sebastian 9 years ago
parent
commit
5e0a31d977
  1. 3
      Squidex.sln.DotSettings
  2. 2
      src/Squidex.Events/Schemas/FieldDeleted.cs
  3. 2
      src/Squidex.Events/Schemas/SchemaDeleted.cs
  4. 2
      src/Squidex.Events/Schemas/SchemaUpdated.cs
  5. 2
      src/Squidex.Store.MongoDb/Schemas/MongoSchemaEntity.cs
  6. 4
      src/Squidex.Store.MongoDb/Schemas/MongoSchemaRepository.cs
  7. 15
      src/Squidex.Write/Schemas/Commands/AddField.cs
  8. 8
      src/Squidex.Write/Schemas/Commands/UpdateField.cs
  9. 71
      src/Squidex.Write/Schemas/SchemaCommandHandler.cs
  10. 12
      src/Squidex.Write/Schemas/SchemaDomainObject.cs
  11. 8
      src/Squidex/Config/Domain/WriteModule.cs
  12. 6
      src/Squidex/Config/EventStore/EventStoreModule.cs
  13. 2
      src/Squidex/Controllers/Api/Apps/Models/AssignContributorDto.cs
  14. 2
      src/Squidex/Controllers/Api/Apps/Models/AttachClientDto.cs
  15. 2
      src/Squidex/Controllers/Api/Apps/Models/ConfigureLanguagesDto.cs
  16. 28
      src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs
  17. 36
      src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs
  18. 2
      src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs
  19. 32
      src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs
  20. 48
      src/Squidex/Controllers/Api/Schemas/Models/FieldPropertiesDto.cs
  21. 2
      src/Squidex/Controllers/Api/Schemas/Models/Fields/NumberField.cs
  22. 2
      src/Squidex/Controllers/Api/Schemas/Models/Fields/StringField.cs
  23. 15
      src/Squidex/Controllers/Api/Schemas/Models/UpdateFieldDto.cs
  24. 17
      src/Squidex/Controllers/Api/Schemas/SchemaFieldsController.cs
  25. 2
      src/Squidex/Controllers/Api/Schemas/SchemasController.cs
  26. 2
      src/Squidex/appsettings.json
  27. 2
      src/Squidex/project.json
  28. 6
      src/Squidex/web.config

3
Squidex.sln.DotSettings

@ -91,5 +91,8 @@
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/CodeStyle/TypeScriptCodeStyle/ExplicitPublicModifier/@EntryValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeStyle/TypeScriptCodeStyle/ExplicitPublicModifier/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

2
src/Squidex.Events/Schemas/FieldDeleted.cs

@ -11,7 +11,7 @@ using Squidex.Infrastructure.CQRS.Events;
namespace Squidex.Events.Schemas namespace Squidex.Events.Schemas
{ {
[TypeName("FieldDeleted")] [TypeName("FieldDeletedEvent")]
public class FieldDeleted : IEvent public class FieldDeleted : IEvent
{ {
public long FieldId { get; set; } public long FieldId { get; set; }

2
src/Squidex.Events/Schemas/SchemaDeleted.cs

@ -11,7 +11,7 @@ using Squidex.Infrastructure.CQRS.Events;
namespace Squidex.Events.Schemas namespace Squidex.Events.Schemas
{ {
[TypeName("SchemaDeleted")] [TypeName("SchemaDeletedEvent")]
public class SchemaDeleted : IEvent public class SchemaDeleted : IEvent
{ {
} }

2
src/Squidex.Events/Schemas/SchemaUpdated.cs

@ -12,7 +12,7 @@ using Squidex.Infrastructure.CQRS.Events;
namespace Squidex.Events.Schemas namespace Squidex.Events.Schemas
{ {
[TypeName("SchemaUpdated")] [TypeName("SchemaUpdatedEvent")]
public class SchemaUpdated : IEvent public class SchemaUpdated : IEvent
{ {
public SchemaProperties Properties { get; set; } public SchemaProperties Properties { get; set; }

2
src/Squidex.Store.MongoDb/Schemas/MongoSchemaEntity.cs

@ -43,7 +43,7 @@ namespace Squidex.Store.MongoDb.Schemas
public Lazy<Schema> DeserializeSchema(SchemaJsonSerializer serializer) public Lazy<Schema> DeserializeSchema(SchemaJsonSerializer serializer)
{ {
schema = new Lazy<Schema>(() => schema != null ? null : serializer.Deserialize(Schema.ToJToken())); schema = new Lazy<Schema>(() => Schema != null ? serializer.Deserialize(Schema.ToJToken()) : null);
return schema; return schema;
} }

4
src/Squidex.Store.MongoDb/Schemas/MongoSchemaRepository.cs

@ -137,7 +137,9 @@ namespace Squidex.Store.MongoDb.Schemas
public Task On(SchemaCreated @event, EnvelopeHeaders headers) public Task On(SchemaCreated @event, EnvelopeHeaders headers)
{ {
return Collection.CreateAsync(headers, s => SimpleMapper.Map(@event, s)); var schema = Schema.Create(@event.Name, @event.Properties);
return Collection.CreateAsync(headers, s => { Serialize(s, schema); SimpleMapper.Map(@event, s); });
} }
public Task On(Envelope<IEvent> @event) public Task On(Envelope<IEvent> @event)

15
src/Squidex.Write/Schemas/Commands/AddField.cs

@ -7,7 +7,7 @@
// ========================================================================== // ==========================================================================
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json.Linq; using Squidex.Core.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
namespace Squidex.Write.Schemas.Commands namespace Squidex.Write.Schemas.Commands
@ -16,9 +16,7 @@ namespace Squidex.Write.Schemas.Commands
{ {
public string Name { get; set; } public string Name { get; set; }
public string Type { get; set; } public FieldProperties Properties { get; set; }
public JToken Properties { get; set; }
public void Validate(IList<ValidationError> errors) public void Validate(IList<ValidationError> errors)
{ {
@ -27,14 +25,9 @@ namespace Squidex.Write.Schemas.Commands
errors.Add(new ValidationError("DisplayName must be a valid slug", nameof(Name))); errors.Add(new ValidationError("DisplayName must be a valid slug", nameof(Name)));
} }
if (string.IsNullOrWhiteSpace(Type)) if (Properties == null)
{
errors.Add(new ValidationError("Type must be specified", nameof(Type)));
}
if (Properties != null && !(Properties is JObject))
{ {
errors.Add(new ValidationError("Properties must be a object or null.", nameof(Properties))); errors.Add(new ValidationError("Properties must be defined.", nameof(Properties)));
} }
} }
} }

8
src/Squidex.Write/Schemas/Commands/UpdateField.cs

@ -7,7 +7,7 @@
// ========================================================================== // ==========================================================================
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json.Linq; using Squidex.Core.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
namespace Squidex.Write.Schemas.Commands namespace Squidex.Write.Schemas.Commands
@ -16,13 +16,13 @@ namespace Squidex.Write.Schemas.Commands
{ {
public long FieldId { get; set; } public long FieldId { get; set; }
public JToken Properties { get; set; } public FieldProperties Properties { get; set; }
public void Validate(IList<ValidationError> errors) public void Validate(IList<ValidationError> errors)
{ {
if (!(Properties is JObject)) if (Properties == null)
{ {
errors.Add(new ValidationError("Properties must be a object.", nameof(Properties))); errors.Add(new ValidationError("Properties must be defined.", nameof(Properties)));
} }
} }
} }

71
src/Squidex.Write/Schemas/SchemaCommandHandler.cs

@ -6,11 +6,8 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Squidex.Core.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Infrastructure.Dispatching; using Squidex.Infrastructure.Dispatching;
@ -21,29 +18,18 @@ namespace Squidex.Write.Schemas
{ {
public class SchemaCommandHandler : CommandHandler<SchemaDomainObject> public class SchemaCommandHandler : CommandHandler<SchemaDomainObject>
{ {
private readonly FieldRegistry registry;
private readonly ISchemaProvider schemaProvider; private readonly ISchemaProvider schemaProvider;
private readonly JsonSerializer serializer;
public SchemaCommandHandler( public SchemaCommandHandler(
FieldRegistry registry,
ISchemaProvider schemaProvider, ISchemaProvider schemaProvider,
IDomainObjectFactory domainObjectFactory, IDomainObjectFactory domainObjectFactory,
IDomainObjectRepository domainObjectRepository, IDomainObjectRepository domainObjectRepository)
JsonSerializer serializer)
: base(domainObjectFactory, domainObjectRepository) : base(domainObjectFactory, domainObjectRepository)
{ {
this.registry = registry;
this.serializer = serializer;
this.schemaProvider = schemaProvider; this.schemaProvider = schemaProvider;
} }
public override Task<bool> HandleAsync(CommandContext context) public async Task On(CreateSchema command, CommandContext context)
{
return context.IsHandled ? Task.FromResult(false) : this.DispatchActionAsync(context.Command);
}
public async Task On(CreateSchema command)
{ {
if (await schemaProvider.FindSchemaIdByNameAsync(command.AppId, command.Name) != null) if (await schemaProvider.FindSchemaIdByNameAsync(command.AppId, command.Name) != null)
{ {
@ -54,70 +40,59 @@ namespace Squidex.Write.Schemas
await CreateAsync(command, s => s.Create(command)); await CreateAsync(command, s => s.Create(command));
} }
public Task On(DeleteSchema command) public Task On(AddField command, CommandContext context)
{
return UpdateAsync(command, s =>
{
s.AddField(command);
context.Succeed(s.Schema.Fields.Values.First(x => x.Name == command.Name).Id);
});
}
public Task On(DeleteSchema command, CommandContext context)
{ {
return UpdateAsync(command, s => s.Delete()); return UpdateAsync(command, s => s.Delete());
} }
public Task On(DeleteField command) public Task On(DeleteField command, CommandContext context)
{ {
return UpdateAsync(command, s => s.DeleteField(command.FieldId)); return UpdateAsync(command, s => s.DeleteField(command.FieldId));
} }
public Task On(DisableField command) public Task On(DisableField command, CommandContext context)
{ {
return UpdateAsync(command, s => s.DisableField(command.FieldId)); return UpdateAsync(command, s => s.DisableField(command.FieldId));
} }
public Task On(EnableField command) public Task On(EnableField command, CommandContext context)
{ {
return UpdateAsync(command, s => s.EnableField(command.FieldId)); return UpdateAsync(command, s => s.EnableField(command.FieldId));
} }
public Task On(HideField command) public Task On(HideField command, CommandContext context)
{ {
return UpdateAsync(command, s => s.HideField(command.FieldId)); return UpdateAsync(command, s => s.HideField(command.FieldId));
} }
public Task On(ShowField command) public Task On(ShowField command, CommandContext context)
{ {
return UpdateAsync(command, s => s.ShowField(command.FieldId)); return UpdateAsync(command, s => s.ShowField(command.FieldId));
} }
public Task On(UpdateSchema command) public Task On(UpdateSchema command, CommandContext context)
{ {
return UpdateAsync(command, s => s.Update(command)); return UpdateAsync(command, s => s.Update(command));
} }
public Task On(AddField command)
{
var propertiesType = registry.FindByTypeName(command.Type).PropertiesType;
var propertiesValue = CreateProperties(command.Properties, propertiesType);
return UpdateAsync(command, s => s.AddField(command, propertiesValue));
}
public Task On(UpdateField command) public Task On(UpdateField command)
{ {
return UpdateAsync(command, s => return UpdateAsync(command, s => { s.UpdateField(command); });
{
var field = s.Schema.Fields.GetOrDefault(command.FieldId);
if (field == null)
{
throw new DomainObjectNotFoundException(command.FieldId.ToString(), typeof(Field));
}
var propertiesType = registry.FindByPropertiesType(field.RawProperties.GetType()).PropertiesType;
var propertiesValue = CreateProperties(command.Properties, propertiesType);
s.UpdateField(command, propertiesValue);
});
} }
private FieldProperties CreateProperties(JToken token, Type type) public override Task<bool> HandleAsync(CommandContext context)
{ {
return (FieldProperties)token.ToObject(type, serializer); return context.IsHandled ? Task.FromResult(false) : this.DispatchActionAsync(context.Command, context);
} }
} }
} }

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

@ -103,26 +103,24 @@ namespace Squidex.Write.Schemas
isDeleted = true; isDeleted = true;
} }
public SchemaDomainObject AddField(AddField command, FieldProperties properties) public SchemaDomainObject AddField(AddField command)
{ {
Guard.Valid(command, nameof(command), () => $"Cannot add field to schema {Id}"); Guard.Valid(command, nameof(command), () => $"Cannot add field to schema {Id}");
Guard.NotNull(properties, nameof(properties));
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new FieldAdded { FieldId = ++totalFields, Name = command.Name, Properties = properties }); RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = ++totalFields }));
return this; return this;
} }
public SchemaDomainObject UpdateField(UpdateField command, FieldProperties properties) public SchemaDomainObject UpdateField(UpdateField command)
{ {
Guard.Valid(command, nameof(command), () => $"Cannot update schema '{schema.Name} ({Id})'"); Guard.Valid(command, nameof(command), () => $"Cannot update schema '{schema.Name} ({Id})'");
Guard.NotNull(properties, nameof(properties));
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(new FieldUpdated { FieldId = command.FieldId, Properties = properties }); RaiseEvent(SimpleMapper.Map(command, new FieldUpdated()));
return this; return this;
} }

8
src/Squidex/Config/Domain/WriteModule.cs

@ -18,10 +18,6 @@ namespace Squidex.Config.Domain
{ {
protected override void Load(ContainerBuilder builder) protected override void Load(ContainerBuilder builder)
{ {
builder.RegisterType<EnrichWithSchemaAggregateIdHandler>()
.As<ICommandHandler>()
.SingleInstance();
builder.RegisterType<EnrichWithAppIdHandler>() builder.RegisterType<EnrichWithAppIdHandler>()
.As<ICommandHandler>() .As<ICommandHandler>()
.SingleInstance(); .SingleInstance();
@ -34,6 +30,10 @@ namespace Squidex.Config.Domain
.As<ICommandHandler>() .As<ICommandHandler>()
.SingleInstance(); .SingleInstance();
builder.RegisterType<EnrichWithSchemaAggregateIdHandler>()
.As<ICommandHandler>()
.SingleInstance();
builder.RegisterType<AppCommandHandler>() builder.RegisterType<AppCommandHandler>()
.As<ICommandHandler>() .As<ICommandHandler>()
.SingleInstance(); .SingleInstance();

6
src/Squidex/Config/EventStore/EventStoreModule.cs

@ -49,11 +49,7 @@ namespace Squidex.Config.EventStore
var options = context.Resolve<IOptions<MyEventStoreOptions>>().Value; var options = context.Resolve<IOptions<MyEventStoreOptions>>().Value;
return new DefaultNameResolver(options.Prefix); return new DefaultNameResolver(options.Prefix);
}).SingleInstance(); }).As<IStreamNameResolver>().SingleInstance();
builder.Register(c => new DefaultNameResolver("squidex"))
.As<IStreamNameResolver>()
.SingleInstance();
} }
} }
} }

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

@ -13,7 +13,7 @@ using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Apps.Models namespace Squidex.Controllers.Api.Apps.Models
{ {
public class AssignContributorDto public sealed class AssignContributorDto
{ {
/// <summary> /// <summary>
/// The id of the user to add to the app (GUID). /// The id of the user to add to the app (GUID).

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

@ -10,7 +10,7 @@ using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Apps.Models namespace Squidex.Controllers.Api.Apps.Models
{ {
public class AttachClientDto public sealed class AttachClientDto
{ {
/// <summary> /// <summary>
/// The name of the client. /// The name of the client.

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

@ -11,7 +11,7 @@ using Squidex.Infrastructure;
namespace Squidex.Controllers.Api.Apps.Models namespace Squidex.Controllers.Api.Apps.Models
{ {
public class ConfigureLanguagesDto public sealed class ConfigureLanguagesDto
{ {
/// <summary> /// <summary>
/// The list of languages to configure the app. /// The list of languages to configure the app.

28
src/Squidex/Controllers/Api/Schemas/Models/AddFieldDto.cs

@ -0,0 +1,28 @@
// ==========================================================================
// AddFieldDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Schemas.Models
{
public sealed class AddFieldDto
{
/// <summary>
/// The name of the field. Must be unique within the schema.
/// </summary>
[Required]
[RegularExpression("^[a-z0-9]+(\\-[a-z0-9]+)*$")]
public string Name { get; set; }
/// <summary>
/// The field properties.
/// </summary>
[Required]
public FieldPropertiesDto Properties { get; set; }
}
}

36
src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs

@ -17,31 +17,15 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters
{ {
public static class SchemaConverter public static class SchemaConverter
{ {
private static readonly Dictionary<Type, Func<Field, FieldDto>> Factories = new Dictionary<Type, Func<Field, FieldDto>> private static readonly Dictionary<Type, Func<FieldProperties, FieldPropertiesDto>> Factories = new Dictionary<Type, Func<FieldProperties, FieldPropertiesDto>>
{ {
{ {
typeof(NumberField), typeof(NumberFieldProperties),
field => p => SimpleMapper.Map((NumberFieldProperties)p, new Dtos.NumberField())
{
var dto = new Dtos.NumberField();
SimpleMapper.Map(field, dto);
SimpleMapper.Map((NumberFieldProperties)field.RawProperties, dto);
return dto;
}
}, },
{ {
typeof(StringField), typeof(StringFieldProperties),
field => p => SimpleMapper.Map((StringFieldProperties)p, new Dtos.StringField())
{
var dto = new Dtos.StringField();
SimpleMapper.Map(field, dto);
SimpleMapper.Map((StringFieldProperties)field.RawProperties, dto);
return dto;
}
} }
}; };
@ -57,7 +41,15 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters
foreach (var field in entity.Schema.Fields.Values) foreach (var field in entity.Schema.Fields.Values)
{ {
var fieldDto = Factories[field.RawProperties.GetType()](field); var fieldPropertiesDto = Factories[field.RawProperties.GetType()](field.RawProperties);
var fieldDto = new FieldDto
{
Name = field.Name,
IsHidden = field.IsHidden,
IsDisabled = field.IsDisabled,
Properties = fieldPropertiesDto
};
dto.Fields.Add(fieldDto); dto.Fields.Add(fieldDto);
} }

2
src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs

@ -10,7 +10,7 @@ using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Schemas.Models namespace Squidex.Controllers.Api.Schemas.Models
{ {
public class CreateSchemaDto public sealed class CreateSchemaDto
{ {
/// <summary> /// <summary>
/// The name of the schema. /// The name of the schema.

32
src/Squidex/Controllers/Api/Schemas/Models/FieldDto.cs

@ -7,17 +7,10 @@
// ========================================================================== // ==========================================================================
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using NJsonSchema.Converters;
using Squidex.Core.Schemas;
namespace Squidex.Controllers.Api.Schemas.Models namespace Squidex.Controllers.Api.Schemas.Models
{ {
[JsonConverter(typeof(JsonInheritanceConverter), "$type")] public sealed class FieldDto
[KnownType(typeof(NumberField))]
[KnownType(typeof(StringField))]
public abstract class FieldDto
{ {
/// <summary> /// <summary>
/// The name of the field. Must be unique within the schema. /// The name of the field. Must be unique within the schema.
@ -27,28 +20,19 @@ namespace Squidex.Controllers.Api.Schemas.Models
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// Optional label for the editor. /// Defines if the field is hidden.
/// </summary> /// </summary>
[StringLength(100)] public bool IsHidden { get; set; }
public string Label { get; set; }
/// <summary> /// <summary>
/// Hints to describe the schema. /// Defines if the field is disabled.
/// </summary> /// </summary>
[StringLength(1000)] public bool IsDisabled { get; set; }
public string Hints { get; set; }
/// <summary> /// <summary>
/// Placeholder to show when no value has been entered. /// The field properties.
/// </summary> /// </summary>
[StringLength(100)] [Required]
public string Placeholder { get; set; } public FieldPropertiesDto Properties { get; set; }
/// <summary>
/// Indicates if the field is required.
/// </summary>
public bool IsRequired { get; set; }
public abstract FieldProperties ToProperties();
} }
} }

48
src/Squidex/Controllers/Api/Schemas/Models/FieldPropertiesDto.cs

@ -0,0 +1,48 @@
// ==========================================================================
// FieldDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using NJsonSchema.Converters;
using Squidex.Core.Schemas;
using Dtos = Squidex.Controllers.Api.Schemas.Models.Fields;
namespace Squidex.Controllers.Api.Schemas.Models
{
[JsonConverter(typeof(JsonInheritanceConverter), "fieldType")]
[KnownType(typeof(Dtos.NumberField))]
[KnownType(typeof(Dtos.StringField))]
public abstract class FieldPropertiesDto
{
/// <summary>
/// Optional label for the editor.
/// </summary>
[StringLength(100)]
public string Label { get; set; }
/// <summary>
/// Hints to describe the schema.
/// </summary>
[StringLength(1000)]
public string Hints { get; set; }
/// <summary>
/// Placeholder to show when no value has been entered.
/// </summary>
[StringLength(100)]
public string Placeholder { get; set; }
/// <summary>
/// Indicates if the field is required.
/// </summary>
public bool IsRequired { get; set; }
public abstract FieldProperties ToProperties();
}
}

2
src/Squidex/Controllers/Api/Schemas/Models/Fields/NumberField.cs

@ -11,7 +11,7 @@ using Squidex.Infrastructure.Reflection;
namespace Squidex.Controllers.Api.Schemas.Models.Fields namespace Squidex.Controllers.Api.Schemas.Models.Fields
{ {
public class NumberField : FieldDto public sealed class NumberField : FieldPropertiesDto
{ {
/// <summary> /// <summary>
/// The default value for the field value. /// The default value for the field value.

2
src/Squidex/Controllers/Api/Schemas/Models/Fields/StringField.cs

@ -11,7 +11,7 @@ using Squidex.Infrastructure.Reflection;
namespace Squidex.Controllers.Api.Schemas.Models.Fields namespace Squidex.Controllers.Api.Schemas.Models.Fields
{ {
public sealed class StringField : FieldDto public sealed class StringField : FieldPropertiesDto
{ {
/// <summary> /// <summary>
/// The default value for the field value. /// The default value for the field value.

15
src/Squidex/Controllers/Api/Schemas/Models/UpdateFieldDto.cs

@ -0,0 +1,15 @@
// ==========================================================================
// UpdateFieldDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
namespace Squidex.Controllers.Api.Schemas.Models
{
public class UpdateFieldDto
{
public FieldPropertiesDto Properties { get; set; }
}
}

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

@ -9,11 +9,9 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using NSwag.Annotations; using NSwag.Annotations;
using Squidex.Infrastructure.CQRS.Commands; using Squidex.Infrastructure.CQRS.Commands;
using Squidex.Controllers.Api.Schemas.Models; using Squidex.Controllers.Api.Schemas.Models;
using Squidex.Infrastructure;
using Squidex.Pipeline; using Squidex.Pipeline;
using Squidex.Write.Schemas.Commands; using Squidex.Write.Schemas.Commands;
@ -22,7 +20,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <summary> /// <summary>
/// Manages and retrieves information about schemas. /// Manages and retrieves information about schemas.
/// </summary> /// </summary>
[Authorize("app-owner,app-developer")] [Authorize(Roles = "app-owner,app-developer")]
[ApiExceptionFilter] [ApiExceptionFilter]
[ServiceFilter(typeof(AppFilterAttribute))] [ServiceFilter(typeof(AppFilterAttribute))]
[SwaggerTag("Schemas")] [SwaggerTag("Schemas")]
@ -50,14 +48,9 @@ namespace Squidex.Controllers.Api.Schemas
[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] FieldDto model) public async Task<IActionResult> PostField(string app, string name, [FromBody] AddFieldDto model)
{ {
var properties = model.ToProperties(); var command = new AddField { Name = model.Name, Properties = model.Properties.ToProperties() };
var fieldName = model.Name;
var fieldType = TypeNameRegistry.GetName(properties.GetType());
var command = new AddField { Name = fieldName, Type = fieldType, Properties = JToken.FromObject(properties) };
var context = await CommandBus.PublishAsync(command); var context = await CommandBus.PublishAsync(command);
var result = context.Result<long>(); var result = context.Result<long>();
@ -81,9 +74,9 @@ namespace Squidex.Controllers.Api.Schemas
[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] FieldDto model) public async Task<IActionResult> PutField(string app, string name, long id, [FromBody] UpdateFieldDto model)
{ {
var command = new UpdateField { FieldId = id, Properties = JToken.FromObject(model) }; var command = new UpdateField { FieldId = id, Properties = model.Properties.ToProperties() };
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);

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

@ -25,7 +25,7 @@ namespace Squidex.Controllers.Api.Schemas
/// <summary> /// <summary>
/// Manages and retrieves information about schemas. /// Manages and retrieves information about schemas.
/// </summary> /// </summary>
[Authorize("app-owner,app-developer")] [Authorize(Roles = "app-owner,app-developer")]
[ApiExceptionFilter] [ApiExceptionFilter]
[ServiceFilter(typeof(AppFilterAttribute))] [ServiceFilter(typeof(AppFilterAttribute))]
[SwaggerTag("Schemas")] [SwaggerTag("Schemas")]

2
src/Squidex/appsettings.json

@ -10,7 +10,7 @@
"eventStore": { "eventStore": {
"ipAddress": "127.0.0.1", "ipAddress": "127.0.0.1",
"port": 1113, "port": 1113,
"prefix": "squidex", "prefix": "squidex_v2",
"username": "admin", "username": "admin",
"password": "changeit" "password": "changeit"
} }

2
src/Squidex/project.json

@ -62,7 +62,7 @@
"nowarn": [ "1591", "1573", "1572" ], "nowarn": [ "1591", "1573", "1572" ],
"embed": { "embed": {
"include": [ "include": [
"Configurations/Identity/Cert/*.*" "Config/Identity/Cert/*.*"
] ]
} }
}, },

6
src/Squidex/web.config

@ -2,8 +2,8 @@
<configuration> <configuration>
<system.webServer> <system.webServer>
<handlers> <handlers>
<add client="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers> </handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile="C:\\Logs\squidex\stdout" forwardWindowsAuthToken="false"/> <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile="C:\\Logs\squidex\stdout" forwardWindowsAuthToken="false" />
</system.webServer> </system.webServer>
</configuration> </configuration>
Loading…
Cancel
Save