2023-05-09 08:38:07 +02:00
|
|
|
|
using Asp.Versioning;
|
2023-12-11 08:25:29 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-05-09 08:38:07 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
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.Security;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|
|
|
|
|
|
2023-05-09 08:38:07 +02:00
|
|
|
|
[ApiVersion("1.0")]
|
2024-01-31 10:40:58 +01:00
|
|
|
|
public class UpdateDocumentController : UpdateDocumentControllerBase
|
2023-02-20 11:08:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
private readonly IContentEditingService _contentEditingService;
|
2023-03-13 10:49:21 +01:00
|
|
|
|
private readonly IDocumentEditingPresentationFactory _documentEditingPresentationFactory;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
public UpdateDocumentController(
|
2023-12-11 08:25:29 +01:00
|
|
|
|
IAuthorizationService authorizationService,
|
2023-02-20 11:08:22 +01:00
|
|
|
|
IContentEditingService contentEditingService,
|
2023-03-13 10:49:21 +01:00
|
|
|
|
IDocumentEditingPresentationFactory documentEditingPresentationFactory,
|
2023-02-20 11:08:22 +01:00
|
|
|
|
IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
|
2024-03-01 10:45:19 +01:00
|
|
|
|
: base(authorizationService)
|
2023-02-20 11:08:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
_contentEditingService = contentEditingService;
|
2023-03-13 10:49:21 +01:00
|
|
|
|
_documentEditingPresentationFactory = documentEditingPresentationFactory;
|
2023-02-20 11:08:22 +01:00
|
|
|
|
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-04 13:20:29 +02:00
|
|
|
|
[HttpPut("{id:guid}")]
|
2023-02-20 11:08:22 +01:00
|
|
|
|
[MapToApiVersion("1.0")]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2024-01-31 10:40:58 +01:00
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
2023-08-04 10:51:20 +02:00
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
2023-04-04 13:20:29 +02:00
|
|
|
|
public async Task<IActionResult> Update(Guid id, UpdateDocumentRequestModel requestModel)
|
2024-03-01 10:45:19 +01:00
|
|
|
|
=> await HandleRequest(id, requestModel, async () =>
|
2023-02-20 11:08:22 +01:00
|
|
|
|
{
|
2024-01-31 10:40:58 +01:00
|
|
|
|
ContentUpdateModel model = _documentEditingPresentationFactory.MapUpdateModel(requestModel);
|
|
|
|
|
|
Attempt<ContentUpdateResult, ContentEditingOperationStatus> result =
|
2024-03-01 10:45:19 +01:00
|
|
|
|
await _contentEditingService.UpdateAsync(id, model, CurrentUserKey(_backOfficeSecurityAccessor));
|
2024-01-31 10:40:58 +01:00
|
|
|
|
|
|
|
|
|
|
return result.Success
|
|
|
|
|
|
? Ok()
|
|
|
|
|
|
: ContentEditingOperationStatusResult(result.Status);
|
|
|
|
|
|
});
|
2023-02-20 11:08:22 +01:00
|
|
|
|
}
|