Files
Umbraco-CMS/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/Tree/ChildrenDictionaryTreeController.cs
Nikolaj Geisle 5107375cd8 V13/feature/rename viewmodels to request response (#13952)
* Rename DocumentType/ContentType models

* Rename all viewmodels

* Rename factories

* Update OpenApi.json

---------

Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-03-13 10:49:21 +01:00

40 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Api.Management.Services.Paging;
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
using Umbraco.Cms.Api.Management.ViewModels.Tree;
namespace Umbraco.Cms.Api.Management.Controllers.Dictionary.Tree;
public class ChildrenDictionaryTreeController : DictionaryTreeControllerBase
{
public ChildrenDictionaryTreeController(IEntityService entityService, IDictionaryItemService dictionaryItemService)
: base(entityService, dictionaryItemService)
{
}
[HttpGet("children")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(PagedViewModel<EntityTreeItemResponseModel>), StatusCodes.Status200OK)]
public async Task<ActionResult<PagedViewModel<EntityTreeItemResponseModel>>> Children(Guid parentKey, int skip = 0, int take = 100)
{
if (PaginationService.ConvertSkipTakeToPaging(skip, take, out var pageNumber, out var pageSize, out ProblemDetails? error) == false)
{
return BadRequest(error);
}
IDictionaryItem[] dictionaryItems = PaginatedDictionaryItems(
pageNumber,
pageSize,
await DictionaryItemService.GetChildrenAsync(parentKey),
out var totalItems);
EntityTreeItemResponseModel[] viewModels = await MapTreeItemViewModels(null, dictionaryItems);
PagedViewModel<EntityTreeItemResponseModel> result = PagedViewModel(viewModels, totalItems);
return await Task.FromResult(Ok(result));
}
}