Rename management API from Umbraco.Cms.ManagementApi to Umbraco.Cms.Api.Management (#13512)

This commit is contained in:
Kenn Jacobsen
2022-12-02 11:33:02 +01:00
committed by GitHub
parent 0b95d5e1e5
commit bc94b2e16c
232 changed files with 480 additions and 478 deletions

View File

@@ -0,0 +1,52 @@
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.New.Cms.Web.Common.Routing;
namespace Umbraco.Cms.Api.Management.Controllers.Dictionary.Tree;
[ApiVersion("1.0")]
[ApiController]
[VersionedApiBackOfficeRoute($"{Constants.Web.RoutePath.Tree}/dictionary")]
[ApiExplorerSettings(GroupName = "Dictionary")]
// 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<EntityTreeItemViewModel>
{
public DictionaryTreeControllerBase(IEntityService entityService, ILocalizationService localizationService)
: base(entityService) =>
LocalizationService = localizationService;
// dictionary items do not currently have a known UmbracoObjectType, so we'll settle with Unknown for now
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.Unknown;
protected ILocalizationService LocalizationService { get; }
protected EntityTreeItemViewModel[] MapTreeItemViewModels(Guid? parentKey, IDictionaryItem[] dictionaryItems)
=> dictionaryItems.Select(dictionaryItem => new EntityTreeItemViewModel
{
Icon = Constants.Icons.RelationType,
Name = dictionaryItem.ItemKey,
Key = dictionaryItem.Key,
Type = Constants.UdiEntityType.DictionaryItem,
HasChildren = false,
IsContainer = LocalizationService.GetDictionaryItemChildren(dictionaryItem.Key).Any(),
ParentKey = parentKey
}).ToArray();
// localization service does not (yet) allow pagination of dictionary items, we have to do it in memory for now
protected IDictionaryItem[] PaginatedDictionaryItems(long pageNumber, int pageSize, IEnumerable<IDictionaryItem> allDictionaryItems, out long totalItems)
{
IDictionaryItem[] allDictionaryItemsAsArray = allDictionaryItems.ToArray();
totalItems = allDictionaryItemsAsArray.Length;
return allDictionaryItemsAsArray
.OrderBy(item => item.ItemKey)
.Skip((int)pageNumber * pageSize)
.Take(pageSize)
.ToArray();
}
}