2023-02-01 15:35:38 +01:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-02-04 13:21:34 +01:00
|
|
|
|
using Umbraco.Cms.Api.Management.Factories;
|
2023-02-01 15:35:38 +01:00
|
|
|
|
using Umbraco.Cms.Api.Management.ViewModels.Document;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|
|
|
|
|
|
|
|
|
|
|
public class ByKeyDocumentController : DocumentControllerBase
|
|
|
|
|
|
{
|
2023-02-21 09:46:23 +01:00
|
|
|
|
private readonly IContentEditingService _contentEditingService;
|
2023-02-04 13:21:34 +01:00
|
|
|
|
private readonly IDocumentViewModelFactory _documentViewModelFactory;
|
2023-02-01 15:35:38 +01:00
|
|
|
|
|
2023-02-21 09:46:23 +01:00
|
|
|
|
public ByKeyDocumentController(IContentEditingService contentEditingService, IDocumentViewModelFactory documentViewModelFactory)
|
2023-02-01 15:35:38 +01:00
|
|
|
|
{
|
2023-02-21 09:46:23 +01:00
|
|
|
|
_contentEditingService = contentEditingService;
|
2023-02-04 13:21:34 +01:00
|
|
|
|
_documentViewModelFactory = documentViewModelFactory;
|
2023-02-01 15:35:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("{key:guid}")]
|
|
|
|
|
|
[MapToApiVersion("1.0")]
|
|
|
|
|
|
[ProducesResponseType(typeof(DocumentViewModel), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-02-21 09:22:00 +01:00
|
|
|
|
public async Task<IActionResult> ByKey(Guid key)
|
2023-02-01 15:35:38 +01:00
|
|
|
|
{
|
2023-02-21 09:46:23 +01:00
|
|
|
|
IContent? content = await _contentEditingService.GetAsync(key);
|
2023-02-01 15:35:38 +01:00
|
|
|
|
if (content == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-04 13:21:34 +01:00
|
|
|
|
DocumentViewModel model = await _documentViewModelFactory.CreateViewModelAsync(content);
|
|
|
|
|
|
return Ok(model);
|
2023-02-01 15:35:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|