Merge pull request #13560 from abpframework/auto-merge/rel-6-0/1245

Merge branch dev with rel-6.0
pull/13566/head
Salih 3 years ago committed by GitHub
commit 6b178abadf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,30 @@ 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 dbContext = await GetDbContextAsync();
var entityTagQueryable = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken));
var tagQueryable = dbContext.Tags.AsQueryable();
var resultQueryable = entityTagQueryable
.Join(
tagQueryable,
o => o.TagId,
i => i.Id,
(entityTag, tag) => new { entityTag, tag })
.Where(x => x.tag.EntityType == entityType
&& x.entityTag.TenantId == tenantId
&& x.tag.TenantId == tenantId
&& x.tag.IsDeleted == false
)
.Select(s => s.entityTag.EntityId);
return await AsyncExecuter.ToListAsync(resultQueryable, GetCancellationToken(cancellationToken));
}
}

@ -1,9 +1,6 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Modularity;
using Xunit;
@ -34,4 +31,15 @@ public abstract class EntityTagRepository_Test<TStartupModule> : CmsKitTestBase<
relatedTags.ShouldBeEmpty();
}
[Fact]
public async Task GetEntityIdsFilteredByTagNameAsync_ShouldWorkProperly()
{
var entityIds = await _entityTagRepository.GetEntityIdsFilteredByTagNameAsync(_cmsKitTestData.TagName_1, _cmsKitTestData.EntityType1);
entityIds.ShouldNotBeNull();
entityIds.ShouldNotBeEmpty();
entityIds.Count.ShouldBe(1);
}
}

Loading…
Cancel
Save