From c2ffc861c37e37444bc42819c90b395d7163cd43 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 24 Feb 2021 17:07:53 +0300 Subject: [PATCH] CmsKit - Refactoring TagManager --- .../Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs | 2 +- .../Volo/CmsKit/Admin/Tags/TagAdminAppService.cs | 8 +++++--- .../Volo/CmsKit/Tags/TagAppService.cs | 3 +-- .../Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs | 5 ----- .../Volo/CmsKit/Tags/EfCoreTagRepository.cs | 4 +--- .../Tags/TagAdminAppService_Tests.cs | 10 ++++++++++ .../Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs | 10 ---------- 7 files changed, 18 insertions(+), 24 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs index 3bfe8f2df8..3725923138 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/EntityTagAdminAppService.cs @@ -62,7 +62,7 @@ namespace Volo.CmsKit.Admin.Tags await CheckPolicyAsync(definition.UpdatePolicy); var existingTags = - await TagRepository.GetAllRelatedTagsAsync(input.EntityType, input.EntityId, CurrentTenant?.Id); + await TagRepository.GetAllRelatedTagsAsync(input.EntityType, input.EntityId); var deletedTags = existingTags.Where(x => !input.Tags.Contains(x.Name)).ToList(); var addedTags = input.Tags.Where(x => !existingTags.Any(a => a.Name == x)); diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs index b128ab182c..6316a44d04 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs @@ -23,16 +23,18 @@ namespace Volo.CmsKit.Admin.Tags ITagAdminAppService { protected TagManager TagManager { get; } - + protected ITagDefinitionStore TagDefinitionStore { get; } protected IStringLocalizerFactory StringLocalizerFactory { get; } public TagAdminAppService( IRepository repository, TagManager tagManager, + ITagDefinitionStore tagDefinitionStore, IStringLocalizerFactory stringLocalizerFactory) : base(repository) { TagManager = tagManager; - StringLocalizerFactory = stringLocalizerFactory; + TagDefinitionStore = tagDefinitionStore; + StringLocalizerFactory = stringLocalizerFactory; GetListPolicyName = CmsKitAdminPermissions.Tags.Default; GetPolicyName = CmsKitAdminPermissions.Tags.Default; @@ -73,7 +75,7 @@ namespace Volo.CmsKit.Admin.Tags public virtual async Task> GetTagDefinitionsAsync() { - var definitions = await TagManager.GetTagDefinitionsAsync(); + var definitions = await TagDefinitionStore.GetTagEntityTypeDefinitionListAsync(); return definitions .Select(s => diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs index 61dfb15571..191eeb4999 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs @@ -20,8 +20,7 @@ namespace Volo.CmsKit.Tags { var entities = await TagRepository.GetAllRelatedTagsAsync( entityType, - entityId, - CurrentTenant.Id); + entityId); return ObjectMapper.Map, List>(entities); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs index 5b675a0db9..d0a97b7331 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs @@ -60,10 +60,5 @@ namespace Volo.CmsKit.Tags return await TagRepository.UpdateAsync(entity); } - - public virtual Task> GetTagDefinitionsAsync() - { - return TagDefinitionStore.GetTagEntityTypeDefinitionListAsync(); - } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs index a57a7af53f..bc33e4f660 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs @@ -63,20 +63,18 @@ namespace Volo.CmsKit.Tags public virtual async Task> GetAllRelatedTagsAsync( [NotNull] string entityType, [NotNull] string entityId, - Guid? tenantId = null, CancellationToken cancellationToken = default) { Check.NotNullOrEmpty(entityType, nameof(entityType)); Check.NotNullOrEmpty(entityId, nameof(entityId)); var entityTagIds = await (await GetDbContextAsync()).Set() - .Where(q => q.EntityId == entityId && q.TenantId == tenantId) + .Where(q => q.EntityId == entityId) .Select(q => q.TagId) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); var query = (await GetDbSetAsync()) .Where(x => x.EntityType == entityType && - x.TenantId == tenantId && entityTagIds.Contains(x.Id)); return await query.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs index b2128bb385..e621e87caa 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs @@ -48,5 +48,15 @@ namespace Volo.CmsKit.Tags Name = _cmsKitTestData.Content_1_Tags[0], })); } + + public async Task GetTagDefinitionsAsync_ShouldWorkProperly_WithoutParameters() + { + var definitions = await _tagAdminAppService.GetTagDefinitionsAsync(); + + definitions.ShouldNotBeNull(); + definitions.ShouldNotBeEmpty(); + definitions.Count.ShouldBeGreaterThan(1); + definitions.ShouldContain(x => x.EntityType == _cmsKitTestData.TagDefinition_1_EntityType); + } } } diff --git a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs index 7d7416c8ce..2eadaa55fb 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs @@ -112,15 +112,5 @@ namespace Volo.CmsKit.Tags Should.Throw(async () => await _tagManager.UpdateAsync(tag.Id, newName)); } - - [Fact] - public async Task ShouldGetTagDefinitionsProperly_WithoutParameter() - { - var definitions = await _tagManager.GetTagDefinitionsAsync(); - - definitions.ShouldNotBeNull(); - definitions.Count.ShouldBeGreaterThan(1); - definitions.ShouldContain(x => x.EntityType == _cmsKitTestData.TagDefinition_1_EntityType); - } } } \ No newline at end of file