Added tag search by tag name

pull/13558/head
Salih 3 years ago
parent 9c15abe803
commit 0e6fb3a202

@ -4,7 +4,7 @@ namespace Volo.CmsKit.Tags;
public static class TagConsts
{
public static int MaxEntityTypeLength { get; set; } = CmsEntityConsts.MaxEntityTypeLength;
public static int MaxEntityTypeLength = CmsEntityConsts.MaxEntityTypeLength;
public static int MaxNameLength { get; set; } = 32;
public const int MaxNameLength = 32;
}

@ -79,4 +79,12 @@ public class EntityTagManager : DomainService
{
return await EntityTagRepository.GetEntityIdsFilteredByTagAsync(tagId, tenantId, cancellationToken);
}
public async Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId,
CancellationToken cancellationToken = default)
{
return await EntityTagRepository.GetEntityIdsFilteredByTagNameAsync(tagName, entityType,tenantId, cancellationToken);
}
}

@ -21,4 +21,10 @@ public interface IEntityTagRepository : IBasicRepository<EntityTag>
[NotNull] Guid tagId,
[CanBeNull] Guid? tenantId,
CancellationToken cancellationToken = default);
Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId=null,
CancellationToken cancellationToken=default);
}

@ -52,4 +52,22 @@ public class EfCoreEntityTagRepository : EfCoreRepository<ICmsKitDbContext, Enti
.Select(q => q.EntityId)
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
public async Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId=null,
CancellationToken cancellationToken=default)
{
var dbContext = await GetDbContextAsync();
var result = from et in dbContext.Set<EntityTag>()
join t in dbContext.Set<Tag>() on et.TagId equals t.Id
where t.Name == tagName
&& t.EntityType == entityType
&& et.TenantId == tenantId
&& t.TenantId == tenantId
&& !t.IsDeleted
select et.EntityId;
return await result.ToListAsync(cancellationToken:GetCancellationToken(cancellationToken));
}
}

@ -9,6 +9,7 @@ using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
using Volo.CmsKit.Tags;
using Tag = Volo.CmsKit.Tags.Tag;
namespace Volo.CmsKit.MongoDB.Tags;
@ -52,4 +53,23 @@ public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext,
return await AsyncExecuter.ToListAsync(blogPostQueryable, GetCancellationToken(cancellationToken));
}
public async Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId=null,
CancellationToken cancellationToken = default)
{
var entityTagQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken));
var tagQueryable = await GetMongoQueryableAsync<Tag>(GetCancellationToken(cancellationToken));
var resultQueryable = from et in entityTagQueryable
join t in tagQueryable on et.TagId equals t.Id
where t.Name == tagName
&& t.EntityType == entityType
&& et.TenantId == tenantId
&& t.TenantId == tenantId
&& !t.IsDeleted
select et.EntityId;
return await AsyncExecuter.ToListAsync(resultQueryable, GetCancellationToken(cancellationToken));
}
}

Loading…
Cancel
Save