Browse Source

Merge pull request #13722 from abpframework/Cms-kit-tag-deletion-13717

Cms kit tag deletion 13717
pull/13741/head
Gizem Mutu Kurt 4 years ago
committed by GitHub
parent
commit
d4ba317562
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/EntityTagManager.cs
  2. 10
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/IEntityTagRepository.cs
  3. 22
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs
  4. 22
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs
  5. 12
      modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/EntityTagRepository_Test.cs

8
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/EntityTagManager.cs

@ -1,9 +1,9 @@
using JetBrains.Annotations;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Services;
namespace Volo.CmsKit.Tags;
@ -62,7 +62,7 @@ public class EntityTagManager : DomainService
var deletedTags = existingTags.Where(x => !tags.Contains(x.Name)).ToList();
var addedTags = tags.Where(x => !existingTags.Any(a => a.Name == x));
await EntityTagRepository.DeleteManyAsync(deletedTags.Select(s => s.Id).ToArray());
await EntityTagRepository.DeleteManyAsync(deletedTags.Select(s => s.Id).ToArray(), entityId);
foreach (var addedTag in addedTags)
{
@ -85,6 +85,6 @@ public class EntityTagManager : DomainService
[CanBeNull] Guid? tenantId,
CancellationToken cancellationToken = default)
{
return await EntityTagRepository.GetEntityIdsFilteredByTagNameAsync(tagName, entityType,tenantId, cancellationToken);
return await EntityTagRepository.GetEntityIdsFilteredByTagNameAsync(tagName, entityType, tenantId, cancellationToken);
}
}

10
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/IEntityTagRepository.cs

@ -1,8 +1,8 @@
using JetBrains.Annotations;
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Repositories;
namespace Volo.CmsKit.Tags;
@ -15,7 +15,7 @@ public interface IEntityTagRepository : IBasicRepository<EntityTag>
[CanBeNull] Guid? tenantId,
CancellationToken cancellationToken = default);
Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default);
Task DeleteManyAsync(Guid[] tagIds, string entityId, CancellationToken cancellationToken = default);
Task<List<string>> GetEntityIdsFilteredByTagAsync(
[NotNull] Guid tagId,
@ -25,6 +25,6 @@ public interface IEntityTagRepository : IBasicRepository<EntityTag>
Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId=null,
CancellationToken cancellationToken=default);
[CanBeNull] Guid? tenantId = null,
CancellationToken cancellationToken = default);
}

22
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs

@ -1,9 +1,9 @@
using JetBrains.Annotations;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -19,11 +19,11 @@ public class EfCoreEntityTagRepository : EfCoreRepository<ICmsKitDbContext, Enti
{
}
public virtual async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default)
public virtual async Task DeleteManyAsync(Guid[] tagIds, string entityId, CancellationToken cancellationToken = default)
{
var dbContext = await GetDbContextAsync();
var dbSet = dbContext.Set<EntityTag>();
dbSet.RemoveRange(dbSet.Where(x => tagIds.Contains(x.TagId)));
dbSet.RemoveRange(dbSet.Where(x => tagIds.Contains(x.TagId) && x.EntityId == entityId));
await dbContext.SaveChangesAsync(GetCancellationToken(cancellationToken));
}
@ -56,18 +56,18 @@ public class EfCoreEntityTagRepository : EfCoreRepository<ICmsKitDbContext, Enti
public async Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId=null,
CancellationToken cancellationToken=default)
[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
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));
select et.EntityId;
return await result.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
}

22
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs

@ -1,15 +1,14 @@
using JetBrains.Annotations;
using MongoDB.Driver;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using MongoDB.Driver;
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;
@ -20,12 +19,19 @@ public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext,
{
}
public virtual async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default)
public virtual async Task DeleteManyAsync(Guid[] tagIds, string entityId, CancellationToken cancellationToken = default)
{
var token = GetCancellationToken(cancellationToken);
var collection = await GetCollectionAsync(token);
await collection.DeleteManyAsync(Builders<EntityTag>.Filter.In(x => x.TagId, tagIds), token);
var builder = Builders<EntityTag>.Filter;
var filter = builder.And(
builder.In(x => x.TagId, tagIds),
builder.Eq(x => x.EntityId, entityId)
);
await collection.DeleteManyAsync(filter, token);
}
public virtual Task<EntityTag> FindAsync(
@ -57,7 +63,7 @@ public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext,
public async Task<List<string>> GetEntityIdsFilteredByTagNameAsync(
[NotNull] string tagName,
[NotNull] string entityType,
[CanBeNull] Guid? tenantId=null,
[CanBeNull] Guid? tenantId = null,
CancellationToken cancellationToken = default)
{
var dbContext = await GetDbContextAsync();
@ -76,7 +82,7 @@ public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext,
&& x.tag.IsDeleted == false
)
.Select(s => s.entityTag.EntityId);
return await AsyncExecuter.ToListAsync(resultQueryable, GetCancellationToken(cancellationToken));
}
}

12
modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/EntityTagRepository_Test.cs

@ -9,11 +9,11 @@ namespace Volo.CmsKit.Tags;
public abstract class EntityTagRepository_Test<TStartupModule> : CmsKitTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private CmsKitTestData _cmsKitTestData;
private IEntityTagRepository _entityTagRepository;
private ITagRepository _tagRepository;
private readonly CmsKitTestData _cmsKitTestData;
private readonly IEntityTagRepository _entityTagRepository;
private readonly ITagRepository _tagRepository;
public EntityTagRepository_Test()
protected EntityTagRepository_Test()
{
_cmsKitTestData = GetRequiredService<CmsKitTestData>();
_entityTagRepository = GetRequiredService<IEntityTagRepository>();
@ -25,7 +25,7 @@ public abstract class EntityTagRepository_Test<TStartupModule> : CmsKitTestBase<
{
var relatedTags = await _tagRepository.GetAllRelatedTagsAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId);
await _entityTagRepository.DeleteManyAsync(relatedTags.Select(s => s.Id).ToArray());
await _entityTagRepository.DeleteManyAsync(relatedTags.Select(s => s.Id).ToArray(), _cmsKitTestData.Content_1_EntityId);
relatedTags = await _tagRepository.GetAllRelatedTagsAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId);
@ -35,7 +35,7 @@ public abstract class EntityTagRepository_Test<TStartupModule> : CmsKitTestBase<
[Fact]
public async Task GetEntityIdsFilteredByTagNameAsync_ShouldWorkProperly()
{
var entityIds = await _entityTagRepository.GetEntityIdsFilteredByTagNameAsync(_cmsKitTestData.TagName_1, _cmsKitTestData.EntityType1);
var entityIds = await _entityTagRepository.GetEntityIdsFilteredByTagNameAsync(_cmsKitTestData.TagName_1, _cmsKitTestData.EntityType1);
entityIds.ShouldNotBeNull();
entityIds.ShouldNotBeEmpty();

Loading…
Cancel
Save