* Allow Tree endpoints that query entities to return count without entity data * Apply count by take 0 in FileSystem Endpoints * Apply count by take 0 in Dictionary Endpoints * Apply count by take 0 in RootRelationType Endpoints * Revert PaginationService takeZero flag as it only guards against things that already blow up * Mark PagedResult as Obsolete as we want to step away from classic pagination system to skip/take * Pushed management api RelationType pagination and async preperation down to the service layer * Scope fix and allocation optimizations * Pushed management api dictionary pagination and down to the service layer Also did some nice allocation optimizations * PR feedback + related strange count behaviour * Moved count by pagesize logic from EntryController to service * A tiny bit of formatting and comments * Fix bad count filter logic * Added integration tests for creating datatypes in a folder * Added tests for count testing on TreeControllers - ChildrenDataType - RootDataType - ChildrenDictionary - RootDictionary - ChildrenDocument - RootDocument - RootBluePrint - RootDocumentType - ChildrenDocumentType * Revert "Added tests for count testing on TreeControllers", should be on services This reverts commit ee2501fe620a584bba13ecd4fdce8142133fd82b. This reverts commit 808d5b276fad267a645e474ead3278d4bb79d0c4. --------- Co-authored-by: Sven Geusens <sge@umbraco.dk> Co-authored-by: kjac <kja@umbraco.dk> Co-authored-by: Andreas Zerbst <andr317c@live.dk>
49 lines
2.2 KiB
C#
49 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Api.Management.Controllers.Tree;
|
|
using Umbraco.Cms.Api.Management.ViewModels.Tree;
|
|
using Umbraco.Cms.Api.Management.Routing;
|
|
using Umbraco.Cms.Web.Common.Authorization;
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Dictionary.Tree;
|
|
|
|
[ApiController]
|
|
[VersionedApiBackOfficeRoute($"{Constants.Web.RoutePath.Tree}/dictionary")]
|
|
[ApiExplorerSettings(GroupName = "Dictionary")]
|
|
[Authorize(Policy = "New" + AuthorizationPolicies.TreeAccessDictionaryOrTemplates)]
|
|
// NOTE: at the moment dictionary items (renamed to dictionary tree) aren't supported by EntityService, so we have little use of the
|
|
// tree controller base. We'll keep it though, in the hope that we can mend EntityService.
|
|
public class DictionaryTreeControllerBase : EntityTreeControllerBase<EntityTreeItemResponseModel>
|
|
{
|
|
public DictionaryTreeControllerBase(IEntityService entityService, IDictionaryItemService dictionaryItemService)
|
|
: base(entityService) =>
|
|
DictionaryItemService = dictionaryItemService;
|
|
|
|
// dictionary items do not currently have a known UmbracoObjectType, so we'll settle with Unknown for now
|
|
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Unknown;
|
|
|
|
protected IDictionaryItemService DictionaryItemService { get; }
|
|
|
|
protected async Task<IEnumerable<EntityTreeItemResponseModel>> MapTreeItemViewModels(Guid? parentKey, IEnumerable<IDictionaryItem> dictionaryItems)
|
|
{
|
|
async Task<EntityTreeItemResponseModel> CreateEntityTreeItemViewModelAsync(IDictionaryItem dictionaryItem)
|
|
{
|
|
var hasChildren = await DictionaryItemService.CountChildrenAsync(dictionaryItem.Key) > 0;
|
|
return new EntityTreeItemResponseModel
|
|
{
|
|
Name = dictionaryItem.ItemKey,
|
|
Id = dictionaryItem.Key,
|
|
Type = Constants.UdiEntityType.DictionaryItem,
|
|
HasChildren = hasChildren,
|
|
IsContainer = false,
|
|
ParentId = parentKey
|
|
};
|
|
}
|
|
|
|
return await Task.WhenAll(dictionaryItems.Select(CreateEntityTreeItemViewModelAsync));
|
|
}
|
|
}
|