-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Management API: Add bulk fetch endpoints for Document Types, Media Types, Member Types, and Data Types #21565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndyButland
wants to merge
3
commits into
main
Choose a base branch
from
v17/improvements/bulk-data-and-content-type-retrieval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Umbraco.Cms.Api.Management/Controllers/DataType/FetchDataTypesController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.ViewModels; | ||
| using Umbraco.Cms.Api.Management.ViewModels.DataType; | ||
| using Umbraco.Cms.Core.Mapping; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.DataType; | ||
|
|
||
| /// <summary> | ||
| /// Provides an API controller for retrieving the full details for multiple data types by key. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class FetchDataTypesController : DataTypeControllerBase | ||
| { | ||
| private readonly IDataTypeService _dataTypeService; | ||
| private readonly IUmbracoMapper _umbracoMapper; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="FetchDataTypesController"/> class. | ||
| /// </summary> | ||
| /// <param name="dataTypeService">The data type service.</param> | ||
| /// <param name="umbracoMapper">The presentation model mapper.</param> | ||
| public FetchDataTypesController(IDataTypeService dataTypeService, IUmbracoMapper umbracoMapper) | ||
| { | ||
| _dataTypeService = dataTypeService; | ||
| _umbracoMapper = umbracoMapper; | ||
| } | ||
|
|
||
| [HttpGet("fetch")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(FetchResponseModel<DataTypeResponseModel>), StatusCodes.Status200OK)] | ||
| public async Task<IActionResult> Fetch( | ||
| CancellationToken cancellationToken, | ||
| [FromQuery(Name = "id")] Guid[] ids) | ||
| { | ||
| Guid[] requestedIds = [.. ids.Distinct()]; | ||
|
|
||
| if (requestedIds.Length == 0) | ||
| { | ||
| return Ok(new FetchResponseModel<DataTypeResponseModel>()); | ||
| } | ||
|
|
||
| IEnumerable<IDataType> dataTypes = await _dataTypeService.GetAllAsync(requestedIds); | ||
|
|
||
| List<IDataType> ordered = OrderByRequestedIds(dataTypes, requestedIds); | ||
|
|
||
| var responseModels = ordered.Select(dt => _umbracoMapper.Map<DataTypeResponseModel>(dt)!).ToList(); | ||
|
|
||
| return Ok(new FetchResponseModel<DataTypeResponseModel> | ||
| { | ||
| Total = responseModels.Count, | ||
| Items = responseModels, | ||
| }); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/Umbraco.Cms.Api.Management/Controllers/DocumentType/FetchDocumentTypesController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.ViewModels; | ||
| using Umbraco.Cms.Api.Management.ViewModels.DocumentType; | ||
| using Umbraco.Cms.Core.Mapping; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.DocumentType; | ||
|
|
||
| /// <summary> | ||
| /// Provides an API controller for retrieving the full details for multiple document types by key. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class FetchDocumentTypesController : DocumentTypeControllerBase | ||
| { | ||
| private readonly IContentTypeService _contentTypeService; | ||
| private readonly IUmbracoMapper _umbracoMapper; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="FetchDocumentTypesController"/> class. | ||
| /// </summary> | ||
| /// <param name="contentTypeService">The content type service.</param> | ||
| /// <param name="umbracoMapper">The presentation model mapper.</param> | ||
| public FetchDocumentTypesController(IContentTypeService contentTypeService, IUmbracoMapper umbracoMapper) | ||
| { | ||
| _contentTypeService = contentTypeService; | ||
| _umbracoMapper = umbracoMapper; | ||
| } | ||
|
|
||
| [HttpGet("fetch")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(FetchResponseModel<DocumentTypeResponseModel>), StatusCodes.Status200OK)] | ||
| public async Task<IActionResult> Fetch( | ||
| CancellationToken cancellationToken, | ||
| [FromQuery(Name = "id")] Guid[] ids) | ||
| { | ||
| Guid[] requestedIds = [.. ids.Distinct()]; | ||
|
|
||
| if (requestedIds.Length == 0) | ||
| { | ||
| return Ok(new FetchResponseModel<DocumentTypeResponseModel>()); | ||
| } | ||
|
|
||
| IEnumerable<IContentType> contentTypes = _contentTypeService.GetMany(requestedIds); | ||
|
|
||
| List<IContentType> ordered = OrderByRequestedIds(contentTypes, requestedIds); | ||
|
|
||
| var responseModels = ordered.Select(ct => _umbracoMapper.Map<DocumentTypeResponseModel>(ct)!).ToList(); | ||
|
|
||
| return Ok(new FetchResponseModel<DocumentTypeResponseModel> | ||
| { | ||
| Total = responseModels.Count, | ||
| Items = responseModels, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Umbraco.Cms.Api.Management/Controllers/MediaType/FetchMediaTypesController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.ViewModels; | ||
| using Umbraco.Cms.Api.Management.ViewModels.MediaType; | ||
| using Umbraco.Cms.Core.Mapping; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.MediaType; | ||
|
|
||
| /// <summary> | ||
| /// Provides an API controller for retrieving the full details for multiple media types by key. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class FetchMediaTypesController : MediaTypeControllerBase | ||
| { | ||
| private readonly IMediaTypeService _mediaTypeService; | ||
| private readonly IUmbracoMapper _umbracoMapper; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="FetchMediaTypesController"/> class. | ||
| /// </summary> | ||
| /// <param name="mediaTypeService">The media type service.</param> | ||
| /// <param name="umbracoMapper">The presentation model mapper.</param> | ||
| public FetchMediaTypesController(IMediaTypeService mediaTypeService, IUmbracoMapper umbracoMapper) | ||
| { | ||
| _mediaTypeService = mediaTypeService; | ||
| _umbracoMapper = umbracoMapper; | ||
| } | ||
|
|
||
| [HttpGet("fetch")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(FetchResponseModel<MediaTypeResponseModel>), StatusCodes.Status200OK)] | ||
| public async Task<IActionResult> Fetch( | ||
| CancellationToken cancellationToken, | ||
| [FromQuery(Name = "id")] Guid[] ids) | ||
| { | ||
| Guid[] requestedIds = [.. ids.Distinct()]; | ||
|
|
||
| if (requestedIds.Length == 0) | ||
| { | ||
| return Ok(new FetchResponseModel<MediaTypeResponseModel>()); | ||
| } | ||
|
|
||
| IEnumerable<IMediaType> mediaTypes = _mediaTypeService.GetMany(requestedIds); | ||
|
|
||
| List<IMediaType> ordered = OrderByRequestedIds(mediaTypes, requestedIds); | ||
|
|
||
| var responseModels = ordered.Select(mt => _umbracoMapper.Map<MediaTypeResponseModel>(mt)!).ToList(); | ||
|
|
||
| return Ok(new FetchResponseModel<MediaTypeResponseModel> | ||
| { | ||
| Total = responseModels.Count, | ||
| Items = responseModels, | ||
| }); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
src/Umbraco.Cms.Api.Management/Controllers/MemberType/ByKeyMemberTypeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Umbraco.Cms.Api.Management/Controllers/MemberType/FetchMemberTypesController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.Factories; | ||
| using Umbraco.Cms.Api.Management.ViewModels; | ||
| using Umbraco.Cms.Api.Management.ViewModels.MemberType; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.MemberType; | ||
|
|
||
| /// <summary> | ||
| /// Provides an API controller for retrieving the full details for multiple member types by key. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class FetchMemberTypesController : MemberTypeControllerBase | ||
| { | ||
| private readonly IMemberTypeService _memberTypeService; | ||
| private readonly IMemberTypePresentationFactory _memberTypePresentationFactory; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="FetchMemberTypesController"/> class. | ||
| /// </summary> | ||
| /// <param name="memberTypeService">The member type service.</param> | ||
| /// <param name="memberTypePresentationFactory">The member type presentation factory.</param> | ||
| public FetchMemberTypesController(IMemberTypeService memberTypeService, IMemberTypePresentationFactory memberTypePresentationFactory) | ||
| { | ||
| _memberTypeService = memberTypeService; | ||
| _memberTypePresentationFactory = memberTypePresentationFactory; | ||
| } | ||
|
|
||
| [HttpGet("fetch")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(FetchResponseModel<MemberTypeResponseModel>), StatusCodes.Status200OK)] | ||
| public async Task<IActionResult> Fetch( | ||
| CancellationToken cancellationToken, | ||
| [FromQuery(Name = "id")] Guid[] ids) | ||
| { | ||
| Guid[] requestedIds = [.. ids.Distinct()]; | ||
|
|
||
| if (requestedIds.Length == 0) | ||
| { | ||
| return Ok(new FetchResponseModel<MemberTypeResponseModel>()); | ||
| } | ||
|
|
||
| IEnumerable<IMemberType> memberTypes = _memberTypeService.GetMany(requestedIds); | ||
|
|
||
| List<IMemberType> ordered = OrderByRequestedIds(memberTypes, requestedIds); | ||
|
|
||
| // Member type mapping is async via factory. | ||
| IEnumerable<Task<MemberTypeResponseModel>> mappingTasks = ordered.Select(mt => _memberTypePresentationFactory.CreateResponseModelAsync(mt)); | ||
| MemberTypeResponseModel[] responseModels = await Task.WhenAll(mappingTasks); | ||
|
|
||
| return Ok(new FetchResponseModel<MemberTypeResponseModel> | ||
| { | ||
| Total = responseModels.Length, | ||
| Items = responseModels, | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.