Files
Umbraco-CMS/src/Umbraco.Cms.Api.Management/Controllers/DocumentBlueprint/ByKeyDocumentBlueprintController.cs
Mole 187d45860a V14: Add cancellation tokens to all endpoints (#15984)
* Add CancellationToken to controllers

* Fix GetManagementApiUrl

* Forgotten Item and Tree controllers

* Document Blueprint and Version endpoints

* Fix merge conflict

* Cleanup

---------

Co-authored-by: Elitsa <elm@umbraco.dk>
2024-04-09 08:18:45 +02:00

41 lines
1.5 KiB
C#

using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.DocumentBlueprint;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint;
[ApiVersion("1.0")]
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentsOrDocumentTypes)]
public class ByKeyDocumentBlueprintController : DocumentBlueprintControllerBase
{
private readonly IContentBlueprintEditingService _contentBlueprintEditingService;
private readonly IUmbracoMapper _umbracoMapper;
public ByKeyDocumentBlueprintController(IContentBlueprintEditingService contentBlueprintEditingService, IUmbracoMapper umbracoMapper)
{
_contentBlueprintEditingService = contentBlueprintEditingService;
_umbracoMapper = umbracoMapper;
}
[HttpGet("{id:guid}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(DocumentBlueprintResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> ByKey(CancellationToken cancellationToken, Guid id)
{
IContent? blueprint = await _contentBlueprintEditingService.GetAsync(id);
if (blueprint == null)
{
return DocumentBlueprintNotFound();
}
return Ok(_umbracoMapper.Map<DocumentBlueprintResponseModel>(blueprint));
}
}