mirror of https://github.com/Squidex/squidex.git
8 changed files with 158 additions and 33 deletions
@ -0,0 +1,27 @@ |
|||
// ==========================================================================
|
|||
// PartitioningExtensions.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Squidex.Core |
|||
{ |
|||
public static class PartitioningExtensions |
|||
{ |
|||
private static readonly HashSet<string> AllowedPartitions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) |
|||
{ |
|||
Partitioning.Language.Key, |
|||
Partitioning.Invariant.Key |
|||
}; |
|||
|
|||
public static bool IsValidPartitioning(this string value) |
|||
{ |
|||
return value == null || AllowedPartitions.Contains(value); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
// ==========================================================================
|
|||
// SchemaCreatedField.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Core.Schemas; |
|||
|
|||
namespace Squidex.Events.Schemas |
|||
{ |
|||
public sealed class SchemaCreatedField |
|||
{ |
|||
public string Partitioning { get; set; } |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public bool IsHidden { get; set; } |
|||
|
|||
public bool IsDisabled { get; set; } |
|||
|
|||
public FieldProperties Properties { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// ==========================================================================
|
|||
// CreateSchemaField.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using Squidex.Core; |
|||
using Squidex.Core.Schemas; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Write.Schemas.Commands |
|||
{ |
|||
public sealed class CreateSchemaField |
|||
{ |
|||
public string Partitioning { get; set; } |
|||
|
|||
public string Name { get; set; } |
|||
|
|||
public bool IsHidden { get; set; } |
|||
|
|||
public bool IsDisabled { get; set; } |
|||
|
|||
public FieldProperties Properties { get; set; } |
|||
|
|||
public void Validate(int index, IList<ValidationError> errors) |
|||
{ |
|||
var prefix = $"Fields.{index}"; |
|||
|
|||
if (!Partitioning.IsValidPartitioning()) |
|||
{ |
|||
errors.Add(new ValidationError("Partitioning is not valid.", $"{prefix}.{nameof(Partitioning)}")); |
|||
} |
|||
|
|||
if (!Name.IsPropertyName()) |
|||
{ |
|||
errors.Add(new ValidationError("Name must be a valid property name", $"{prefix}.{nameof(Name)}")); |
|||
} |
|||
|
|||
if (Properties == null) |
|||
{ |
|||
errors.Add(new ValidationError("Properties must be defined.", $"{prefix}.{nameof(Properties)}")); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue