2023-05-09 08:38:07 +02:00
|
|
|
|
using Asp.Versioning;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2023-02-01 15:35:38 +01:00
|
|
|
|
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;
|
|
|
|
|
|
|
2023-05-09 08:38:07 +02:00
|
|
|
|
[ApiVersion("1.0")]
|
2023-02-01 15:35:38 +01:00
|
|
|
|
public class ByKeyDocumentController : DocumentControllerBase
|
|
|
|
|
|
{
|
2023-02-21 09:46:23 +01:00
|
|
|
|
private readonly IContentEditingService _contentEditingService;
|
2023-03-13 10:49:21 +01:00
|
|
|
|
private readonly IDocumentPresentationFactory _documentPresentationFactory;
|
2023-02-01 15:35:38 +01:00
|
|
|
|
|
2023-03-13 10:49:21 +01:00
|
|
|
|
public ByKeyDocumentController(IContentEditingService contentEditingService, IDocumentPresentationFactory documentPresentationFactory)
|
2023-02-01 15:35:38 +01:00
|
|
|
|
{
|
2023-02-21 09:46:23 +01:00
|
|
|
|
_contentEditingService = contentEditingService;
|
2023-03-13 10:49:21 +01:00
|
|
|
|
_documentPresentationFactory = documentPresentationFactory;
|
2023-02-01 15:35:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-04 13:20:29 +02:00
|
|
|
|
[HttpGet("{id:guid}")]
|
2023-02-01 15:35:38 +01:00
|
|
|
|
[MapToApiVersion("1.0")]
|
2023-02-27 11:27:26 +01:00
|
|
|
|
[ProducesResponseType(typeof(DocumentResponseModel), StatusCodes.Status200OK)]
|
2023-02-01 15:35:38 +01:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2023-04-04 13:20:29 +02:00
|
|
|
|
public async Task<IActionResult> ByKey(Guid id)
|
2023-02-01 15:35:38 +01:00
|
|
|
|
{
|
2023-04-04 13:20:29 +02:00
|
|
|
|
IContent? content = await _contentEditingService.GetAsync(id);
|
2023-02-01 15:35:38 +01:00
|
|
|
|
if (content == null)
|
|
|
|
|
|
{
|
2023-03-13 15:02:30 +01:00
|
|
|
|
return DocumentNotFound();
|
2023-02-01 15:35:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-13 10:49:21 +01:00
|
|
|
|
DocumentResponseModel model = await _documentPresentationFactory.CreateResponseModelAsync(content);
|
2023-02-04 13:21:34 +01:00
|
|
|
|
return Ok(model);
|
2023-02-01 15:35:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|