Skip to content

Commit 67f7d99

Browse files
Allow fetching multiple content and media by Guid and Udi (#15289)
* Allow fetching content by Guid and Udi * Get media by Guid and Udi ids * Fix array parameters Co-authored-by: Ronald Barendse <[email protected]> --------- Co-authored-by: Ronald Barendse <[email protected]>
1 parent 27e3184 commit 67f7d99

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Umbraco.Web.BackOffice/Controllers/ContentController.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers;
4444
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
4545
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocuments)]
4646
[ParameterSwapControllerActionSelector(nameof(GetById), "id", typeof(int), typeof(Guid), typeof(Udi))]
47+
[ParameterSwapControllerActionSelector(nameof(GetByIds), "ids", typeof(int[]), typeof(Guid[]), typeof(Udi[]))]
4748
[ParameterSwapControllerActionSelector(nameof(GetNiceUrl), "id", typeof(int), typeof(Guid), typeof(Udi))]
4849
public class ContentController : ContentControllerBase
4950
{
@@ -247,6 +248,30 @@ public IEnumerable<ContentItemDisplay> GetByIds([FromQuery] int[] ids)
247248
return foundContent.Select(MapToDisplay).WhereNotNull();
248249
}
249250

251+
/// <summary>
252+
/// Return content for the specified ids
253+
/// </summary>
254+
/// <param name="ids"></param>
255+
/// <returns></returns>
256+
[FilterAllowedOutgoingContent(typeof(IEnumerable<ContentItemDisplay>))]
257+
public IEnumerable<ContentItemDisplay> GetByIds([FromQuery] Guid[] ids)
258+
{
259+
IEnumerable<IContent> foundContent = _contentService.GetByIds(ids);
260+
return foundContent.Select(MapToDisplay).WhereNotNull();
261+
}
262+
263+
/// <summary>
264+
/// Return content for the specified ids
265+
/// </summary>
266+
/// <param name="ids"></param>
267+
/// <returns></returns>
268+
[FilterAllowedOutgoingContent(typeof(IEnumerable<ContentItemDisplay>))]
269+
public IEnumerable<ContentItemDisplay> GetByIds([FromQuery] Udi[] ids)
270+
{
271+
IEnumerable<IContent> foundContent = _contentService.GetByIds(ids)!;
272+
return foundContent.Select(MapToDisplay).WhereNotNull();
273+
}
274+
250275
/// <summary>
251276
/// Updates the permissions for a content item for a particular user group
252277
/// </summary>

src/Umbraco.Web.BackOffice/Controllers/MediaController.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers;
4747
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
4848
[Authorize(Policy = AuthorizationPolicies.SectionAccessMedia)]
4949
[ParameterSwapControllerActionSelector(nameof(GetById), "id", typeof(int), typeof(Guid), typeof(Udi))]
50+
[ParameterSwapControllerActionSelector(nameof(GetByIds), "ids", typeof(int[]), typeof(Guid[]), typeof(Udi[]))]
5051
[ParameterSwapControllerActionSelector(nameof(GetChildren), "id", typeof(int), typeof(Guid), typeof(Udi))]
5152
public class MediaController : ContentControllerBase
5253
{
@@ -296,6 +297,30 @@ public MediaItemDisplay GetRecycleBin()
296297
return foundMedia.Select(media => _umbracoMapper.Map<MediaItemDisplay>(media));
297298
}
298299

300+
/// <summary>
301+
/// Return media for the specified ids
302+
/// </summary>
303+
/// <param name="ids"></param>
304+
/// <returns></returns>
305+
[FilterAllowedOutgoingMedia(typeof(IEnumerable<MediaItemDisplay>))]
306+
public IEnumerable<MediaItemDisplay?> GetByIds([FromQuery] Guid[] ids)
307+
{
308+
IEnumerable<IMedia> foundMedia = _mediaService.GetByIds(ids);
309+
return foundMedia.Select(media => _umbracoMapper.Map<MediaItemDisplay>(media));
310+
}
311+
312+
/// <summary>
313+
/// Return media for the specified ids
314+
/// </summary>
315+
/// <param name="ids"></param>
316+
/// <returns></returns>
317+
[FilterAllowedOutgoingMedia(typeof(IEnumerable<MediaItemDisplay>))]
318+
public IEnumerable<MediaItemDisplay?> GetByIds([FromQuery] Udi[] ids)
319+
{
320+
IEnumerable<IMedia> foundMedia = _mediaService.GetByIds(ids);
321+
return foundMedia.Select(media => _umbracoMapper.Map<MediaItemDisplay>(media));
322+
}
323+
299324
/// <summary>
300325
/// Returns a paged result of media items known to be of a "Folder" type
301326
/// </summary>

0 commit comments

Comments
 (0)