46 lines
2.0 KiB
C#
46 lines
2.0 KiB
C#
|
|
using Asp.Versioning;
|
|||
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
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;
|
|||
|
|
using Umbraco.Cms.Core.Models.ContentEditing;
|
|||
|
|
using Umbraco.Cms.Core.Services;
|
|||
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
|||
|
|
|
|||
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|||
|
|
|
|||
|
|
[ApiVersion("1.0")]
|
|||
|
|
public class ValidateUpdateDocumentController : UpdateDocumentControllerBase
|
|||
|
|
{
|
|||
|
|
private readonly IContentEditingService _contentEditingService;
|
|||
|
|
private readonly IDocumentEditingPresentationFactory _documentEditingPresentationFactory;
|
|||
|
|
|
|||
|
|
public ValidateUpdateDocumentController(
|
|||
|
|
IAuthorizationService authorizationService,
|
|||
|
|
IContentEditingService contentEditingService,
|
|||
|
|
IDocumentEditingPresentationFactory documentEditingPresentationFactory)
|
|||
|
|
: base(authorizationService, contentEditingService)
|
|||
|
|
{
|
|||
|
|
_contentEditingService = contentEditingService;
|
|||
|
|
_documentEditingPresentationFactory = documentEditingPresentationFactory;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPut("{id:guid}/validate")]
|
|||
|
|
[MapToApiVersion("1.0")]
|
|||
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|||
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|||
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|||
|
|
public async Task<IActionResult> Validate(Guid id, UpdateDocumentRequestModel requestModel)
|
|||
|
|
=> await HandleRequest(id, requestModel, async content =>
|
|||
|
|
{
|
|||
|
|
ContentUpdateModel model = _documentEditingPresentationFactory.MapUpdateModel(requestModel);
|
|||
|
|
Attempt<ContentValidationResult, ContentEditingOperationStatus> result = await _contentEditingService.ValidateUpdateAsync(content, model);
|
|||
|
|
|
|||
|
|
return result.Success
|
|||
|
|
? Ok()
|
|||
|
|
: DocumentEditingOperationStatusResult(result.Status, requestModel, result.Result);
|
|||
|
|
});
|
|||
|
|
}
|