V15: Add information to item endpoints (#17623)
* Add information to item response model * Update OpenApi.json
This commit is contained in:
@@ -22,19 +22,22 @@ internal sealed class DocumentPresentationFactory : IDocumentPresentationFactory
|
||||
private readonly ITemplateService _templateService;
|
||||
private readonly IPublicAccessService _publicAccessService;
|
||||
private readonly TimeProvider _timeProvider;
|
||||
private readonly IIdKeyMap _idKeyMap;
|
||||
|
||||
public DocumentPresentationFactory(
|
||||
IUmbracoMapper umbracoMapper,
|
||||
IDocumentUrlFactory documentUrlFactory,
|
||||
ITemplateService templateService,
|
||||
IPublicAccessService publicAccessService,
|
||||
TimeProvider timeProvider)
|
||||
TimeProvider timeProvider,
|
||||
IIdKeyMap idKeyMap)
|
||||
{
|
||||
_umbracoMapper = umbracoMapper;
|
||||
_documentUrlFactory = documentUrlFactory;
|
||||
_templateService = templateService;
|
||||
_publicAccessService = publicAccessService;
|
||||
_timeProvider = timeProvider;
|
||||
_idKeyMap = idKeyMap;
|
||||
}
|
||||
|
||||
public async Task<DocumentResponseModel> CreateResponseModelAsync(IContent content)
|
||||
@@ -73,10 +76,14 @@ internal sealed class DocumentPresentationFactory : IDocumentPresentationFactory
|
||||
|
||||
public DocumentItemResponseModel CreateItemResponseModel(IDocumentEntitySlim entity)
|
||||
{
|
||||
Attempt<Guid> parentKeyAttempt = _idKeyMap.GetKeyForId(entity.ParentId, UmbracoObjectTypes.Document);
|
||||
|
||||
var responseModel = new DocumentItemResponseModel
|
||||
{
|
||||
Id = entity.Key,
|
||||
IsTrashed = entity.Trashed
|
||||
IsTrashed = entity.Trashed,
|
||||
Parent = parentKeyAttempt.Success ? new ReferenceByIdModel { Id = parentKeyAttempt.Result } : null,
|
||||
HasChildren = entity.HasChildren,
|
||||
};
|
||||
|
||||
responseModel.IsProtected = _publicAccessService.IsProtected(entity.Path);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Content;
|
||||
using Umbraco.Cms.Api.Management.ViewModels;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Content;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Media;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.Media.Item;
|
||||
using Umbraco.Cms.Api.Management.ViewModels.MediaType;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Mapping;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Api.Management.Factories;
|
||||
|
||||
@@ -12,13 +15,16 @@ internal sealed class MediaPresentationFactory : IMediaPresentationFactory
|
||||
{
|
||||
private readonly IUmbracoMapper _umbracoMapper;
|
||||
private readonly IMediaUrlFactory _mediaUrlFactory;
|
||||
private readonly IIdKeyMap _idKeyMap;
|
||||
|
||||
public MediaPresentationFactory(
|
||||
IUmbracoMapper umbracoMapper,
|
||||
IMediaUrlFactory mediaUrlFactory)
|
||||
IMediaUrlFactory mediaUrlFactory,
|
||||
IIdKeyMap idKeyMap)
|
||||
{
|
||||
_umbracoMapper = umbracoMapper;
|
||||
_mediaUrlFactory = mediaUrlFactory;
|
||||
_idKeyMap = idKeyMap;
|
||||
}
|
||||
|
||||
public MediaResponseModel CreateResponseModel(IMedia media)
|
||||
@@ -32,10 +38,14 @@ internal sealed class MediaPresentationFactory : IMediaPresentationFactory
|
||||
|
||||
public MediaItemResponseModel CreateItemResponseModel(IMediaEntitySlim entity)
|
||||
{
|
||||
Attempt<Guid> parentKeyAttempt = _idKeyMap.GetKeyForId(entity.ParentId, UmbracoObjectTypes.Media);
|
||||
|
||||
var responseModel = new MediaItemResponseModel
|
||||
{
|
||||
Id = entity.Key,
|
||||
IsTrashed = entity.Trashed
|
||||
IsTrashed = entity.Trashed,
|
||||
Parent = parentKeyAttempt.Success ? new ReferenceByIdModel { Id = parentKeyAttempt.Result } : null,
|
||||
HasChildren = entity.HasChildren,
|
||||
};
|
||||
|
||||
responseModel.MediaType = _umbracoMapper.Map<MediaTypeReferenceResponseModel>(entity)!;
|
||||
|
||||
@@ -36738,6 +36738,7 @@
|
||||
"DocumentItemResponseModel": {
|
||||
"required": [
|
||||
"documentType",
|
||||
"hasChildren",
|
||||
"id",
|
||||
"isProtected",
|
||||
"isTrashed",
|
||||
@@ -36755,6 +36756,17 @@
|
||||
"isProtected": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"parent": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/ReferenceByIdModel"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"hasChildren": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"documentType": {
|
||||
"oneOf": [
|
||||
{
|
||||
@@ -38895,6 +38907,7 @@
|
||||
},
|
||||
"MediaItemResponseModel": {
|
||||
"required": [
|
||||
"hasChildren",
|
||||
"id",
|
||||
"isTrashed",
|
||||
"mediaType",
|
||||
@@ -38909,6 +38922,17 @@
|
||||
"isTrashed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"parent": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/ReferenceByIdModel"
|
||||
}
|
||||
],
|
||||
"nullable": true
|
||||
},
|
||||
"hasChildren": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"mediaType": {
|
||||
"oneOf": [
|
||||
{
|
||||
|
||||
@@ -10,6 +10,10 @@ public class DocumentItemResponseModel : ItemResponseModelBase
|
||||
|
||||
public bool IsProtected { get; set; }
|
||||
|
||||
public ReferenceByIdModel? Parent { get; set; }
|
||||
|
||||
public bool HasChildren { get; set; }
|
||||
|
||||
public DocumentTypeReferenceResponseModel DocumentType { get; set; } = new();
|
||||
|
||||
public IEnumerable<DocumentVariantItemResponseModel> Variants { get; set; } = Enumerable.Empty<DocumentVariantItemResponseModel>();
|
||||
|
||||
@@ -8,6 +8,10 @@ public class MediaItemResponseModel : ItemResponseModelBase
|
||||
{
|
||||
public bool IsTrashed { get; set; }
|
||||
|
||||
public ReferenceByIdModel? Parent { get; set; }
|
||||
|
||||
public bool HasChildren { get; set; }
|
||||
|
||||
public MediaTypeReferenceResponseModel MediaType { get; set; } = new();
|
||||
|
||||
public IEnumerable<VariantItemResponseModel> Variants { get; set; } = Enumerable.Empty<VariantItemResponseModel>();
|
||||
|
||||
Reference in New Issue
Block a user