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.
49 lines
1.6 KiB
49 lines
1.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using MongoDB.Driver;
|
|
using Squidex.Domain.Apps.Core.Contents;
|
|
using Squidex.Domain.Apps.Entities.Contents;
|
|
using Squidex.Domain.Apps.Entities.Schemas;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.Json;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations
|
|
{
|
|
internal sealed class QueryContent : OperationBase
|
|
{
|
|
private readonly IJsonSerializer serializer;
|
|
|
|
public QueryContent(IJsonSerializer serializer)
|
|
{
|
|
this.serializer = serializer;
|
|
}
|
|
|
|
public async Task<IContentEntity?> DoAsync(ISchemaEntity schema, Guid id, Status[]? status, bool includeDraft)
|
|
{
|
|
Guard.NotNull(schema);
|
|
|
|
var find = Collection.Find(x => x.Id == id).WithoutDraft(includeDraft);
|
|
|
|
var contentEntity = await find.FirstOrDefaultAsync();
|
|
|
|
if (contentEntity != null)
|
|
{
|
|
if (contentEntity.IndexedSchemaId != schema.Id || !contentEntity.HasStatus(status))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
contentEntity?.ParseData(schema.SchemaDef, serializer);
|
|
}
|
|
|
|
return contentEntity;
|
|
}
|
|
}
|
|
}
|
|
|