Files
mixtape/zero.Api/Endpoints/Media/Indexes/zero_Api_Media_ChildCounts.cs
T

32 lines
830 B
C#
Raw Normal View History

2021-12-16 13:55:09 +01:00
using Raven.Client.Documents.Indexes;
namespace zero.Api.Endpoints.Media;
public class zero_Api_Media_ChildCounts : ZeroIndex<zero.Media.Media, zero_Api_Media_ChildCounts.Result>
{
public class Result : ZeroIdEntity
{
public int ChildCount { get; set; }
2021-12-16 16:59:27 +01:00
public int ChildFolderCount { get; set; }
2021-12-16 13:55:09 +01:00
}
protected override void Create()
{
Map = items => items.Where(x => x.ParentId != null).Select(item => new Result
{
Id = item.ParentId,
2021-12-16 16:59:27 +01:00
ChildCount = 1,
ChildFolderCount = item.IsFolder ? 1 : 0
2021-12-16 13:55:09 +01:00
});
Reduce = results => results.GroupBy(x => new { x.Id }).Select(group => new Result()
{
Id = group.Key.Id,
2021-12-16 16:59:27 +01:00
ChildCount = group.Sum(x => x.ChildCount),
ChildFolderCount = group.Sum(x => x.ChildFolderCount)
2021-12-16 13:55:09 +01:00
});
StoreAllFields(FieldStorage.Yes);
}
}