diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs index ca88721460..1d5a089da4 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs @@ -1,4 +1,5 @@ using JetBrains.Annotations; +using MongoDB.Driver; using MongoDB.Driver.Linq; using System; using System.Collections.Generic; @@ -10,7 +11,7 @@ using Volo.CmsKit.Tags; namespace Volo.CmsKit.MongoDB.Tags { - public class MongoTagRepository : MongoDbRepository, ITagRepository + public class MongoTagRepository : MongoDbRepository, ITagRepository { public MongoTagRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { @@ -30,7 +31,7 @@ namespace Volo.CmsKit.MongoDB.Tags cancellationToken); } - public Task GetAsync( + public Task GetAsync( [NotNull] string entityType, [NotNull] string name, Guid? tenantId, @@ -43,7 +44,7 @@ namespace Volo.CmsKit.MongoDB.Tags cancellationToken: cancellationToken); } - public Task FindAsync( + public Task FindAsync( [NotNull] string entityType, [NotNull] string name, Guid? tenantId, @@ -56,9 +57,24 @@ namespace Volo.CmsKit.MongoDB.Tags cancellationToken: cancellationToken); } - public Task> GetAllRelatedTagsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public virtual async Task> GetAllRelatedTagsAsync( + [NotNull] string entityType, + [NotNull] string entityId, + Guid? tenantId = null, + CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + var entityTagIds = await DbContext.EntityTags.AsQueryable() + .Where(q => q.EntityId == entityId) + .Select(q => q.EntityId) + .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); + + var query = GetMongoQueryable() + .Where(x => x.EntityType == entityType && + x.TenantId == tenantId && + entityTagIds.Contains(x.Id.ToString())); + + var result = await query.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); + return result; } } }