Add async get method to content editing service

This commit is contained in:
kjac
2023-02-21 09:46:23 +01:00
parent 9b63d33b33
commit ff90e2a865
3 changed files with 12 additions and 5 deletions

View File

@@ -9,12 +9,12 @@ namespace Umbraco.Cms.Api.Management.Controllers.Document;
public class ByKeyDocumentController : DocumentControllerBase
{
private readonly IContentService _contentService;
private readonly IContentEditingService _contentEditingService;
private readonly IDocumentViewModelFactory _documentViewModelFactory;
public ByKeyDocumentController(IContentService contentService, IDocumentViewModelFactory documentViewModelFactory)
public ByKeyDocumentController(IContentEditingService contentEditingService, IDocumentViewModelFactory documentViewModelFactory)
{
_contentService = contentService;
_contentEditingService = contentEditingService;
_documentViewModelFactory = documentViewModelFactory;
}
@@ -24,8 +24,7 @@ public class ByKeyDocumentController : DocumentControllerBase
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> ByKey(Guid key)
{
// FIXME: create and use an async get method here.
IContent? content = _contentService.GetById(key);
IContent? content = await _contentEditingService.GetAsync(key);
if (content == null)
{
return NotFound();

View File

@@ -29,6 +29,12 @@ internal sealed class ContentEditingService
_scopeProvider = scopeProvider;
}
public async Task<IContent?> GetAsync(Guid id)
{
IContent? content = ContentService.GetById(id);
return await Task.FromResult(content);
}
public async Task<Attempt<IContent?, ContentEditingOperationStatus>> CreateAsync(ContentCreateModel createModel, int userId)
{
Attempt<IContent?, ContentEditingOperationStatus> result = await MapCreate(createModel);

View File

@@ -6,6 +6,8 @@ namespace Umbraco.Cms.Core.Services;
public interface IContentEditingService
{
Task<IContent?> GetAsync(Guid id);
Task<Attempt<IContent?, ContentEditingOperationStatus>> CreateAsync(ContentCreateModel createModel, int userId);
Task<Attempt<IContent, ContentEditingOperationStatus>> UpdateAsync(IContent content, ContentUpdateModel updateMode, int userId);