mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.8 KiB
87 lines
2.8 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using Squidex.Domain.Apps.Core.Contents;
|
|
using Squidex.Domain.Apps.Entities;
|
|
using Squidex.Domain.Apps.Entities.Contents;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Shared;
|
|
using Squidex.Web;
|
|
|
|
namespace Squidex.Areas.Api.Controllers.Contents.Models
|
|
{
|
|
public sealed class ContentsDto : Resource
|
|
{
|
|
/// <summary>
|
|
/// The total number of content items.
|
|
/// </summary>
|
|
public long Total { get; set; }
|
|
|
|
/// <summary>
|
|
/// The content items.
|
|
/// </summary>
|
|
[Required]
|
|
public ContentDto[] Items { get; set; }
|
|
|
|
/// <summary>
|
|
/// The possible statuses.
|
|
/// </summary>
|
|
[Required]
|
|
public string[] Statuses { get; set; }
|
|
|
|
public string ToEtag()
|
|
{
|
|
return Items.ToManyEtag(Total);
|
|
}
|
|
|
|
public string ToSurrogateKeys()
|
|
{
|
|
return Items.ToSurrogateKeys();
|
|
}
|
|
|
|
public static ContentsDto FromContents(long total, IEnumerable<IContentEntity> contents, QueryContext context,
|
|
ApiController controller,
|
|
string app,
|
|
string schema)
|
|
{
|
|
var result = new ContentsDto
|
|
{
|
|
Total = total,
|
|
Items = contents.Select(x => ContentDto.FromContent(x, context, controller, app, schema)).ToArray(),
|
|
};
|
|
|
|
result.Statuses = new string[] { "Archived", "Draft", "Published" };
|
|
|
|
return result.CreateLinks(controller, app, schema);
|
|
}
|
|
|
|
private ContentsDto CreateLinks(ApiController controller, string app, string schema)
|
|
{
|
|
if (schema != null)
|
|
{
|
|
var values = new { app, name = schema };
|
|
|
|
AddSelfLink(controller.Url<ContentsController>(x => nameof(x.GetContents), values));
|
|
|
|
if (controller.HasPermission(Permissions.AppContentsCreate, app, schema))
|
|
{
|
|
AddPostLink("create", controller.Url<ContentsController>(x => nameof(x.PostContent), values));
|
|
|
|
if (controller.HasPermission(Helper.StatusPermission(app, schema, Status.Published)))
|
|
{
|
|
AddPostLink("create/publish", controller.Url<ContentsController>(x => nameof(x.PostContent), values) + "?publish=true");
|
|
}
|
|
}
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|
|
}
|
|
|