2023-05-09 08:38:07 +02:00
|
|
|
|
using Asp.Versioning;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2023-02-10 08:32:24 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Umbraco.Cms.Api.Management.ViewModels.Dictionary;
|
|
|
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Dictionary;
|
|
|
|
|
|
|
2023-05-09 08:38:07 +02:00
|
|
|
|
[ApiVersion("1.0")]
|
2023-02-10 08:32:24 +01:00
|
|
|
|
public class MoveDictionaryController : DictionaryControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IDictionaryItemService _dictionaryItemService;
|
|
|
|
|
|
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
public MoveDictionaryController(IDictionaryItemService dictionaryItemService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
|
|
|
|
|
|
{
|
|
|
|
|
|
_dictionaryItemService = dictionaryItemService;
|
|
|
|
|
|
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-12 08:59:21 +01:00
|
|
|
|
[HttpPut("{id:guid}/move")]
|
2023-02-10 08:32:24 +01:00
|
|
|
|
[MapToApiVersion("1.0")]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
|
[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> Move(Guid id, MoveDictionaryRequestModel moveDictionaryRequestModel)
|
2023-02-10 08:32:24 +01:00
|
|
|
|
{
|
2023-04-04 13:20:29 +02:00
|
|
|
|
IDictionaryItem? source = await _dictionaryItemService.GetAsync(id);
|
2023-02-10 08:32:24 +01:00
|
|
|
|
if (source == null)
|
|
|
|
|
|
{
|
2024-02-22 15:17:06 +01:00
|
|
|
|
return DictionaryItemNotFound();
|
2023-02-10 08:32:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Attempt<IDictionaryItem, DictionaryItemOperationStatus> result = await _dictionaryItemService.MoveAsync(
|
|
|
|
|
|
source,
|
2024-02-06 13:19:30 +01:00
|
|
|
|
moveDictionaryRequestModel.Target?.Id,
|
2023-03-21 12:41:20 +01:00
|
|
|
|
CurrentUserKey(_backOfficeSecurityAccessor));
|
2023-02-10 08:32:24 +01:00
|
|
|
|
|
|
|
|
|
|
return result.Success
|
|
|
|
|
|
? Ok()
|
|
|
|
|
|
: DictionaryItemOperationStatusResult(result.Status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|