* CRUD API for media + get by ID for media types * A little housekeeping for documents (align with media) * Update Open API json * Add messages to NotFound results (both content and media) * Review changes; use same model for content and media URLs + return bad request when trying to move something to trash that is already in trash * Fix bad merge + rename base (response) classes appropriately between both media and content types
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Umbraco.Cms.Api.Management.Factories;
|
|
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
|
|
{
|
|
private readonly IContentEditingService _contentEditingService;
|
|
private readonly IDocumentPresentationFactory _documentPresentationFactory;
|
|
|
|
public ByKeyDocumentController(IContentEditingService contentEditingService, IDocumentPresentationFactory documentPresentationFactory)
|
|
{
|
|
_contentEditingService = contentEditingService;
|
|
_documentPresentationFactory = documentPresentationFactory;
|
|
}
|
|
|
|
[HttpGet("{key:guid}")]
|
|
[MapToApiVersion("1.0")]
|
|
[ProducesResponseType(typeof(DocumentResponseModel), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> ByKey(Guid key)
|
|
{
|
|
IContent? content = await _contentEditingService.GetAsync(key);
|
|
if (content == null)
|
|
{
|
|
return DocumentNotFound();
|
|
}
|
|
|
|
DocumentResponseModel model = await _documentPresentationFactory.CreateResponseModelAsync(content);
|
|
return Ok(model);
|
|
}
|
|
}
|