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.
90 lines
2.7 KiB
90 lines
2.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.MongoDb.Queries;
|
|
using Squidex.Infrastructure.Queries;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.MongoDb.Assets.Visitors
|
|
{
|
|
public static class FindExtensions
|
|
{
|
|
private static readonly FilterDefinitionBuilder<MongoAssetEntity> Filter = Builders<MongoAssetEntity>.Filter;
|
|
|
|
public static ClrQuery AdjustToModel(this ClrQuery query)
|
|
{
|
|
if (query.Filter != null)
|
|
{
|
|
query.Filter = FirstPascalPathConverter<ClrValue>.Transform(query.Filter);
|
|
}
|
|
|
|
query.Sort = query.Sort
|
|
.Select(x =>
|
|
new SortNode(
|
|
x.Path.ToFirstPascalCase(),
|
|
x.Order))
|
|
.ToList();
|
|
|
|
return query;
|
|
}
|
|
|
|
public static FilterDefinition<MongoAssetEntity> BuildFilter(this ClrQuery query, DomainId appId, DomainId? parentId)
|
|
{
|
|
var filters = new List<FilterDefinition<MongoAssetEntity>>
|
|
{
|
|
Filter.Eq(x => x.IndexedAppId, appId),
|
|
Filter.Eq(x => x.IsDeleted, false)
|
|
};
|
|
|
|
if (parentId.HasValue)
|
|
{
|
|
if (parentId.Value == DomainId.Empty)
|
|
{
|
|
filters.Add(
|
|
Filter.Or(
|
|
Filter.Exists(x => x.ParentId, false),
|
|
Filter.Eq(x => x.ParentId, DomainId.Empty)));
|
|
}
|
|
else
|
|
{
|
|
filters.Add(Filter.Eq(x => x.ParentId, parentId.Value));
|
|
}
|
|
}
|
|
|
|
var (filter, last) = query.BuildFilter<MongoAssetEntity>(false);
|
|
|
|
if (filter != null)
|
|
{
|
|
if (last)
|
|
{
|
|
filters.Add(filter);
|
|
}
|
|
else
|
|
{
|
|
filters.Insert(0, filter);
|
|
}
|
|
}
|
|
|
|
if (filters.Count > 1)
|
|
{
|
|
return Filter.And(filters);
|
|
}
|
|
else if (filters.Count == 1)
|
|
{
|
|
return filters[0];
|
|
}
|
|
else
|
|
{
|
|
return new BsonDocument();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|