CmsKit - Refactor TagDefinitionStore

pull/7483/head
enisn 5 years ago
parent 7339efd02a
commit aa34547aa8

@ -1,5 +1,6 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -17,24 +18,41 @@ namespace Volo.CmsKit.Tags
this.options = options.Value;
}
/// <summary>
/// Gets single <see cref="TagEntityTypeDefiniton"/> by entityType.
/// </summary>
/// <param name="entityType">EntityType to get definition.</param>
/// <exception cref="EntityNotTaggableException">Thrown when EntityType is not configured as taggable.</exception>
/// <exception cref="InvalidOperationException">More than one element satisfies the condition in predicate.</exception>
public virtual Task<TagEntityTypeDefiniton> GetTagEntityTypeDefinitionsAsync([NotNull] string entityType)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
var result = options.EntityTypes.FirstOrDefault(x => x.EntityType == entityType) ?? throw new EntityNotTaggableException(entityType);
var result = options.EntityTypes.SingleOrDefault(x => x.EntityType == entityType) ?? throw new EntityNotTaggableException(entityType);
return Task.FromResult(result);
}
public virtual Task<List<TagEntityTypeDefiniton>> GetTagDefinitionsAsync()
/// <summary>
/// Gets all defined <see cref="TagEntityTypeDefiniton"/> elements.
/// </summary>
public virtual Task<List<TagEntityTypeDefiniton>> GetTagEntityTypeDefinitionListAsync()
{
return Task.FromResult(options.EntityTypes.ToList());
}
/// <summary>
/// Checks if EntityType defined as taggable.
/// </summary>
/// <param name="entityType">EntityType to check.</param>
/// <exception cref="InvalidOperationException">More than one element satisfies the condition in predicate.</exception>"
public virtual Task<bool> IsDefinedAsync([NotNull] string entityType)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
return Task.FromResult(options.EntityTypes.Any(a => a.EntityType == entityType));
var definition = options.EntityTypes.SingleOrDefault(x => x.EntityType == entityType);
return Task.FromResult(definition != null);
}
}
}

@ -6,7 +6,7 @@ namespace Volo.CmsKit.Tags
{
public interface ITagDefinitionStore
{
Task<List<TagEntityTypeDefiniton>> GetTagDefinitionsAsync();
Task<List<TagEntityTypeDefiniton>> GetTagEntityTypeDefinitionListAsync();
Task<TagEntityTypeDefiniton> GetTagEntityTypeDefinitionsAsync([NotNull] string entityType);

@ -85,7 +85,7 @@ namespace Volo.CmsKit.Tags
public Task<List<TagEntityTypeDefiniton>> GetTagDefinitionsAsync(CancellationToken cancellationToken = default)
{
return _tagDefinitionStore.GetTagDefinitionsAsync();
return _tagDefinitionStore.GetTagEntityTypeDefinitionListAsync();
}
}
}
Loading…
Cancel
Save