// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.ComponentModel.DataAnnotations;
using NodaTime;
using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Areas.Api.Controllers.Schemas.Models
{
public sealed class SchemaDto
{
///
/// The id of the schema.
///
public Guid Id { get; set; }
///
/// The name of the schema. Unique within the app.
///
[Required]
[RegularExpression("^[a-z0-9]+(\\-[a-z0-9]+)*$")]
public string Name { get; set; }
///
/// The name of the category.
///
public string Category { get; set; }
///
/// The schema properties.
///
[Required]
public SchemaPropertiesDto Properties { get; set; }
///
/// Indicates if the schema is published.
///
public bool IsPublished { get; set; }
///
/// The user that has created the schema.
///
[Required]
public RefToken CreatedBy { get; set; }
///
/// The user that has updated the schema.
///
[Required]
public RefToken LastModifiedBy { get; set; }
///
/// The date and time when the schema has been created.
///
public Instant Created { get; set; }
///
/// The date and time when the schema has been modified last.
///
public Instant LastModified { get; set; }
///
/// The version of the schema.
///
public int Version { get; set; }
public static SchemaDto FromSchema(ISchemaEntity schema)
{
var response = new SchemaDto { Properties = new SchemaPropertiesDto() };
SimpleMapper.Map(schema, response);
SimpleMapper.Map(schema.SchemaDef, response);
SimpleMapper.Map(schema.SchemaDef.Properties, response.Properties);
return response;
}
}
}