Skip to content
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

Add GetAllAsync overload without parameter simplify getting all or by keys #16264

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Controllers.Tree;
using Umbraco.Cms.Api.Management.Routing;
Expand Down Expand Up @@ -40,11 +40,9 @@ protected override Ordering ItemOrdering

protected override DataTypeTreeItemResponseModel[] MapTreeItemViewModels(Guid? parentId, IEntitySlim[] entities)
{
Dictionary<int, IDataType> dataTypes = entities.Any()
? _dataTypeService
.GetAllAsync(entities.Select(entity => entity.Key).ToArray()).GetAwaiter().GetResult()
.ToDictionary(contentType => contentType.Id)
: new Dictionary<int, IDataType>();
var dataTypes = _dataTypeService
.GetAllAsync(entities.Select(entity => entity.Key).ToArray()).GetAwaiter().GetResult()
.ToDictionary(contentType => contentType.Id);

return entities.Select(entity =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentTypeEditing;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services.OperationStatus;
Expand Down Expand Up @@ -658,12 +658,7 @@ private Guid[] GetDataTypeKeys(ContentTypeEditingModelBase<TPropertyTypeModel, T
=> model.Properties.Select(property => property.DataTypeKey).Distinct().ToArray();

private async Task<IDataType[]> GetDataTypesAsync(ContentTypeEditingModelBase<TPropertyTypeModel, TPropertyTypeContainer> model)
{
Guid[] dataTypeKeys = GetDataTypeKeys(model);
return dataTypeKeys.Any()
? (await _dataTypeService.GetAllAsync(GetDataTypeKeys(model))).ToArray()
: Array.Empty<IDataType>();
}
=> (await _dataTypeService.GetAllAsync(GetDataTypeKeys(model))).ToArray();

private int? GetParentId(ContentTypeEditingModelBase<TPropertyTypeModel, TPropertyTypeContainer> model, Guid? containerKey)
{
Expand Down
17 changes: 10 additions & 7 deletions src/Umbraco.Core/Services/DataTypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,20 @@ public IEnumerable<EntityContainer> GetContainers(int[] containerIds)
}

/// <inheritdoc />
public Task<IEnumerable<IDataType>> GetAllAsync(params Guid[] keys)
public Task<IEnumerable<IDataType>> GetAllAsync()
{
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
IDataType[] dataTypes = _dataTypeRepository.GetMany().ToArray();
ConvertMissingEditorsOfDataTypesToLabels(dataTypes);

IQuery<IDataType> query = Query<IDataType>();
if (keys.Length > 0)
{
query = query.Where(x => keys.Contains(x.Key));
}
return Task.FromResult<IEnumerable<IDataType>>(dataTypes);
}

IDataType[] dataTypes = _dataTypeRepository.Get(query).ToArray();
/// <inheritdoc />
public Task<IEnumerable<IDataType>> GetAllAsync(params Guid[] keys)
{
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
IDataType[] dataTypes = _dataTypeRepository.Get(Query<IDataType>().Where(x => keys.Contains(x.Key))).ToArray();
ConvertMissingEditorsOfDataTypesToLabels(dataTypes);

return Task.FromResult<IEnumerable<IDataType>>(dataTypes);
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/Services/IDataTypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,17 @@ public interface IDataTypeService : IService
/// </returns>
Task<IDataType?> GetAsync(Guid id);

/// <summary>
/// Gets all <see cref="IDataType"/> objects.
/// </summary>
/// <returns>All data types.</returns>
Task<IEnumerable<IDataType>> GetAllAsync();

/// <summary>
/// Gets multiple <see cref="IDataType"/> objects by their unique keys.
/// </summary>
/// <param name="keys">The keys to get datatypes by.</param>
/// <returns>An attempt with the requested data types.</returns>
/// <returns>The data types with the specified keys.</returns>
Task<IEnumerable<IDataType>> GetAllAsync(params Guid[] keys);

/// <summary>
Expand Down
Loading