Browse Source

1) Remove model validation because we validate at the command level.

2) Option to publish schema in one api call.
pull/248/head
Sebastian Stehle 8 years ago
parent
commit
2f25c6b27a
  1. 13
      src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateBlogCommandMiddleware.cs
  2. 2
      src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchema.cs
  3. 5
      src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs
  4. 2
      src/Squidex.Domain.Apps.Events/Schemas/SchemaCreated.cs
  5. 5
      src/Squidex/Areas/Api/Controllers/Schemas/Models/CreateSchemaDto.cs
  6. 23
      src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs

13
src/Squidex.Domain.Apps.Entities/Apps/Templates/CreateBlogCommandMiddleware.cs

@ -105,6 +105,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
var command = new CreateSchema var command = new CreateSchema
{ {
Name = "posts", Name = "posts",
Publish = true,
Properties = new SchemaProperties Properties = new SchemaProperties
{ {
Label = "Posts" Label = "Posts"
@ -136,8 +137,9 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
IsListField = true, IsListField = true,
MaxLength = 100, MaxLength = 100,
MinLength = 0, MinLength = 0,
Label = "Slug" Label = "Slug (Autogenerated)"
} },
IsDisabled = true
}, },
new CreateSchemaField new CreateSchemaField
{ {
@ -158,7 +160,6 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
var schemaId = new NamedId<Guid>(command.SchemaId, command.Name); var schemaId = new NamedId<Guid>(command.SchemaId, command.Name);
await publishAsync(new PublishSchema { SchemaId = schemaId });
await publishAsync(new ConfigureScripts await publishAsync(new ConfigureScripts
{ {
SchemaId = schemaId, SchemaId = schemaId,
@ -205,8 +206,9 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
IsListField = true, IsListField = true,
MaxLength = 100, MaxLength = 100,
MinLength = 0, MinLength = 0,
Label = "Slug" Label = "Slug (Autogenerated)"
} },
IsDisabled = true
}, },
new CreateSchemaField new CreateSchemaField
{ {
@ -227,7 +229,6 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
var schemaId = new NamedId<Guid>(command.SchemaId, command.Name); var schemaId = new NamedId<Guid>(command.SchemaId, command.Name);
await publishAsync(new PublishSchema { SchemaId = schemaId });
await publishAsync(new ConfigureScripts await publishAsync(new ConfigureScripts
{ {
SchemaId = schemaId, SchemaId = schemaId,

2
src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchema.cs

@ -20,6 +20,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Commands
public SchemaProperties Properties { get; set; } public SchemaProperties Properties { get; set; }
public bool Publish { get; set; }
public string Name { get; set; } public string Name { get; set; }
Guid IAggregateCommand.AggregateId Guid IAggregateCommand.AggregateId

5
src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs

@ -70,6 +70,11 @@ namespace Squidex.Domain.Apps.Entities.Schemas.State
schema = schema.Update(@event.Properties); schema = schema.Update(@event.Properties);
} }
if (@event.Publish)
{
schema = schema.Publish();
}
if (@event.Fields != null) if (@event.Fields != null)
{ {
foreach (var eventField in @event.Fields) foreach (var eventField in @event.Fields)

2
src/Squidex.Domain.Apps.Events/Schemas/SchemaCreated.cs

@ -19,5 +19,7 @@ namespace Squidex.Domain.Apps.Events.Schemas
public SchemaFields Fields { get; set; } public SchemaFields Fields { get; set; }
public SchemaProperties Properties { get; set; } public SchemaProperties Properties { get; set; }
public bool Publish { get; set; }
} }
} }

5
src/Squidex/Areas/Api/Controllers/Schemas/Models/CreateSchemaDto.cs

@ -28,5 +28,10 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models
/// Optional fields. /// Optional fields.
/// </summary> /// </summary>
public List<CreateSchemaFieldDto> Fields { get; set; } public List<CreateSchemaFieldDto> Fields { get; set; }
/// <summary>
/// Set it to true to autopublish the schema.
/// </summary>
public bool Publish { get; set; }
} }
} }

23
src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs

@ -62,28 +62,7 @@ namespace Squidex.Pipeline
error.StatusCode = statusCode; error.StatusCode = statusCode;
return new ObjectResult(error) { StatusCode = statusCode }; return new ObjectResult(error) { StatusCode = statusCode };
} }+
public override void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
var errors = new List<ValidationError>();
foreach (var m in context.ModelState)
{
foreach (var e in m.Value.Errors)
{
if (!string.IsNullOrWhiteSpace(e.ErrorMessage))
{
errors.Add(new ValidationError(e.ErrorMessage, m.Key));
}
}
}
throw new ValidationException("The model is not valid.", errors);
}
}
public void OnException(ExceptionContext context) public void OnException(ExceptionContext context)
{ {

Loading…
Cancel
Save