Rename ViewModel to ResponseModel + rename ViewModel factory to Presentation factory
This commit is contained in:
@@ -10,17 +10,17 @@ namespace Umbraco.Cms.Api.Management.Controllers.Document;
|
|||||||
public class ByKeyDocumentController : DocumentControllerBase
|
public class ByKeyDocumentController : DocumentControllerBase
|
||||||
{
|
{
|
||||||
private readonly IContentEditingService _contentEditingService;
|
private readonly IContentEditingService _contentEditingService;
|
||||||
private readonly IDocumentViewModelFactory _documentViewModelFactory;
|
private readonly IDocumentPresentationModelFactory _documentPresentationModelFactory;
|
||||||
|
|
||||||
public ByKeyDocumentController(IContentEditingService contentEditingService, IDocumentViewModelFactory documentViewModelFactory)
|
public ByKeyDocumentController(IContentEditingService contentEditingService, IDocumentPresentationModelFactory documentPresentationModelFactory)
|
||||||
{
|
{
|
||||||
_contentEditingService = contentEditingService;
|
_contentEditingService = contentEditingService;
|
||||||
_documentViewModelFactory = documentViewModelFactory;
|
_documentPresentationModelFactory = documentPresentationModelFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{key:guid}")]
|
[HttpGet("{key:guid}")]
|
||||||
[MapToApiVersion("1.0")]
|
[MapToApiVersion("1.0")]
|
||||||
[ProducesResponseType(typeof(DocumentViewModel), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(DocumentResponseModel), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public async Task<IActionResult> ByKey(Guid key)
|
public async Task<IActionResult> ByKey(Guid key)
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ public class ByKeyDocumentController : DocumentControllerBase
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentViewModel model = await _documentViewModelFactory.CreateViewModelAsync(content);
|
DocumentResponseModel model = await _documentPresentationModelFactory.CreateResponseModelAsync(content);
|
||||||
return Ok(model);
|
return Ok(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ internal static class DocumentBuilderExtensions
|
|||||||
{
|
{
|
||||||
internal static IUmbracoBuilder AddDocuments(this IUmbracoBuilder builder)
|
internal static IUmbracoBuilder AddDocuments(this IUmbracoBuilder builder)
|
||||||
{
|
{
|
||||||
builder.Services.AddTransient<IDocumentViewModelFactory, DocumentViewModelFactory>();
|
builder.Services.AddTransient<IDocumentPresentationModelFactory, DocumentPresentationModelFactory>();
|
||||||
builder.Services.AddTransient<IContentUrlFactory, ContentUrlFactory>();
|
builder.Services.AddTransient<IContentUrlFactory, ContentUrlFactory>();
|
||||||
builder.Services.AddTransient<IDocumentEditingFactory, DocumentEditingFactory>();
|
builder.Services.AddTransient<IDocumentEditingFactory, DocumentEditingFactory>();
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ using Umbraco.Cms.Core.Services;
|
|||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.Factories;
|
namespace Umbraco.Cms.Api.Management.Factories;
|
||||||
|
|
||||||
public class DocumentViewModelFactory : IDocumentViewModelFactory
|
public class DocumentPresentationModelFactory : IDocumentPresentationModelFactory
|
||||||
{
|
{
|
||||||
private readonly IUmbracoMapper _umbracoMapper;
|
private readonly IUmbracoMapper _umbracoMapper;
|
||||||
private readonly IContentUrlFactory _contentUrlFactory;
|
private readonly IContentUrlFactory _contentUrlFactory;
|
||||||
private readonly IFileService _fileService;
|
private readonly IFileService _fileService;
|
||||||
|
|
||||||
public DocumentViewModelFactory(
|
public DocumentPresentationModelFactory(
|
||||||
IUmbracoMapper umbracoMapper,
|
IUmbracoMapper umbracoMapper,
|
||||||
IContentUrlFactory contentUrlFactory,
|
IContentUrlFactory contentUrlFactory,
|
||||||
IFileService fileService)
|
IFileService fileService)
|
||||||
@@ -21,16 +21,16 @@ public class DocumentViewModelFactory : IDocumentViewModelFactory
|
|||||||
_fileService = fileService;
|
_fileService = fileService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DocumentViewModel> CreateViewModelAsync(IContent content)
|
public async Task<DocumentResponseModel> CreateResponseModelAsync(IContent content)
|
||||||
{
|
{
|
||||||
DocumentViewModel viewModel = _umbracoMapper.Map<DocumentViewModel>(content)!;
|
DocumentResponseModel responseModel = _umbracoMapper.Map<DocumentResponseModel>(content)!;
|
||||||
|
|
||||||
viewModel.Urls = await _contentUrlFactory.GetUrlsAsync(content);
|
responseModel.Urls = await _contentUrlFactory.GetUrlsAsync(content);
|
||||||
|
|
||||||
viewModel.TemplateKey = content.TemplateId.HasValue
|
responseModel.TemplateKey = content.TemplateId.HasValue
|
||||||
? _fileService.GetTemplate(content.TemplateId.Value)?.Key
|
? _fileService.GetTemplate(content.TemplateId.Value)?.Key
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return viewModel;
|
return responseModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ using Umbraco.Cms.Core.Models;
|
|||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.Factories;
|
namespace Umbraco.Cms.Api.Management.Factories;
|
||||||
|
|
||||||
public interface IDocumentViewModelFactory
|
public interface IDocumentPresentationModelFactory
|
||||||
{
|
{
|
||||||
Task<DocumentViewModel> CreateViewModelAsync(IContent content);
|
Task<DocumentResponseModel> CreateResponseModelAsync(IContent content);
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace Umbraco.Cms.Api.Management.Mapping.Content;
|
|||||||
public abstract class ContentMapDefinition<TContent, TValueViewModel, TVariantViewModel>
|
public abstract class ContentMapDefinition<TContent, TValueViewModel, TVariantViewModel>
|
||||||
where TContent : IContentBase
|
where TContent : IContentBase
|
||||||
where TValueViewModel : ValueModelBase, new()
|
where TValueViewModel : ValueModelBase, new()
|
||||||
where TVariantViewModel : VariantViewModelBase, new()
|
where TVariantViewModel : VariantResponseModelBase, new()
|
||||||
{
|
{
|
||||||
private readonly PropertyEditorCollection _propertyEditorCollection;
|
private readonly PropertyEditorCollection _propertyEditorCollection;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using Umbraco.Cms.Core.PropertyEditors;
|
|||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.Mapping.Document;
|
namespace Umbraco.Cms.Api.Management.Mapping.Document;
|
||||||
|
|
||||||
public class DocumentMapDefinition : ContentMapDefinition<IContent, DocumentValueModel, DocumentVariantViewModel>, IMapDefinition
|
public class DocumentMapDefinition : ContentMapDefinition<IContent, DocumentValueModel, DocumentVariantResponseModel>, IMapDefinition
|
||||||
{
|
{
|
||||||
public DocumentMapDefinition(PropertyEditorCollection propertyEditorCollection)
|
public DocumentMapDefinition(PropertyEditorCollection propertyEditorCollection)
|
||||||
: base(propertyEditorCollection)
|
: base(propertyEditorCollection)
|
||||||
@@ -15,10 +15,10 @@ public class DocumentMapDefinition : ContentMapDefinition<IContent, DocumentValu
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DefineMaps(IUmbracoMapper mapper)
|
public void DefineMaps(IUmbracoMapper mapper)
|
||||||
=> mapper.Define<IContent, DocumentViewModel>((_, _) => new DocumentViewModel(), Map);
|
=> mapper.Define<IContent, DocumentResponseModel>((_, _) => new DocumentResponseModel(), Map);
|
||||||
|
|
||||||
// Umbraco.Code.MapAll -Urls -TemplateKey
|
// Umbraco.Code.MapAll -Urls -TemplateKey
|
||||||
private void Map(IContent source, DocumentViewModel target, MapperContext context)
|
private void Map(IContent source, DocumentResponseModel target, MapperContext context)
|
||||||
{
|
{
|
||||||
target.Key = source.Key;
|
target.Key = source.Key;
|
||||||
target.ContentTypeKey = source.ContentType.Key;
|
target.ContentTypeKey = source.ContentType.Key;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Umbraco.Cms.Api.Management.ViewModels.Content;
|
||||||
|
|
||||||
|
public abstract class ContentResponseModelBase<TValueResponseModelBase, TVariantResponseModel>
|
||||||
|
: ContentModelBase<TValueResponseModelBase, TVariantResponseModel>
|
||||||
|
where TValueResponseModelBase : ValueModelBase
|
||||||
|
where TVariantResponseModel : VariantResponseModelBase
|
||||||
|
{
|
||||||
|
public Guid Key { get; set; }
|
||||||
|
|
||||||
|
public Guid ContentTypeKey { get; set; }
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
namespace Umbraco.Cms.Api.Management.ViewModels.Content;
|
|
||||||
|
|
||||||
public abstract class ContentViewModelBase<TValueViewModelBase, TVariantViewModel>
|
|
||||||
: ContentModelBase<TValueViewModelBase, TVariantViewModel>
|
|
||||||
where TValueViewModelBase : ValueModelBase
|
|
||||||
where TVariantViewModel : VariantViewModelBase
|
|
||||||
{
|
|
||||||
public Guid Key { get; set; }
|
|
||||||
|
|
||||||
public Guid ContentTypeKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Umbraco.Cms.Api.Management.ViewModels.Content;
|
namespace Umbraco.Cms.Api.Management.ViewModels.Content;
|
||||||
|
|
||||||
public abstract class VariantViewModelBase : VariantModelBase
|
public abstract class VariantResponseModelBase : VariantModelBase
|
||||||
{
|
{
|
||||||
public DateTime CreateDate { get; set; }
|
public DateTime CreateDate { get; set; }
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.ViewModels.Document;
|
namespace Umbraco.Cms.Api.Management.ViewModels.Document;
|
||||||
|
|
||||||
public class DocumentViewModel : ContentViewModelBase<DocumentValueModel, DocumentVariantViewModel>
|
public class DocumentResponseModel : ContentResponseModelBase<DocumentValueModel, DocumentVariantResponseModel>
|
||||||
{
|
{
|
||||||
public IEnumerable<ContentUrlInfo> Urls { get; set; } = Array.Empty<ContentUrlInfo>();
|
public IEnumerable<ContentUrlInfo> Urls { get; set; } = Array.Empty<ContentUrlInfo>();
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Umbraco.Cms.Api.Management.ViewModels.Document;
|
namespace Umbraco.Cms.Api.Management.ViewModels.Document;
|
||||||
|
|
||||||
public class DocumentVariantViewModel : VariantViewModelBase
|
public class DocumentVariantResponseModel : VariantResponseModelBase
|
||||||
{
|
{
|
||||||
public ContentState State { get; set; }
|
public ContentState State { get; set; }
|
||||||
|
|
||||||
Reference in New Issue
Block a user