diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs index 54cc4b1499..cc755fa63f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs @@ -2,13 +2,21 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Admin.Tags; +using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Permissions; using Volo.CmsKit.Tags; namespace Volo.CmsKit.Admin.Tags { + [RequiresGlobalFeature(typeof(TagsFeature))] + [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] + [Area("cms-kit")] + [Authorize(CmsKitAdminPermissions.Tags.Default)] + [Route("api/cms-kit-admin/tags")] public class TagAdminController : CmsKitAdminController, ITagAdminAppService { protected ITagAdminAppService TagAdminAppService { get; } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index 5e823abf11..8e3b7160db 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -41,8 +41,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); b.ConfigureAbpUser(); - b.HasIndex(x => new {x.TenantId, x.UserName}); - b.HasIndex(x => new {x.TenantId, x.Email}); + b.HasIndex(x => new { x.TenantId, x.UserName }); + b.HasIndex(x => new { x.TenantId, x.Email }); }); } @@ -93,7 +93,7 @@ namespace Volo.CmsKit.EntityFrameworkCore r.Property(x => x.EntityType).IsRequired().HasMaxLength(RatingConsts.MaxEntityTypeLength); r.Property(x => x.EntityId).IsRequired().HasMaxLength(RatingConsts.MaxEntityIdLength); - r.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId, x.CreatorId}); + r.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.CreatorId }); }); } @@ -109,7 +109,7 @@ namespace Volo.CmsKit.EntityFrameworkCore b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); - b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId}); + b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); }); } @@ -124,7 +124,11 @@ namespace Volo.CmsKit.EntityFrameworkCore b.Property(x => x.EntityType).IsRequired().HasMaxLength(TagConsts.MaxEntityTypeLength); b.Property(x => x.Name).IsRequired().HasMaxLength(TagConsts.MaxNameLength); - b.HasIndex(x => new {x.TenantId, x.Name}); + b.HasIndex(x => new + { + x.TenantId, + x.Name + }); }); builder.Entity(b => @@ -133,12 +137,12 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new {x.EntityId, x.TagId}); + b.HasKey(x => new { x.EntityId, x.TagId }); b.Property(x => x.EntityId).IsRequired(); b.Property(x => x.TagId).IsRequired(); - b.HasIndex(x => new {x.TenantId, x.EntityId, x.TagId}); + b.HasIndex(x => new { x.TenantId, x.EntityId, x.TagId }); }); } @@ -154,7 +158,7 @@ namespace Volo.CmsKit.EntityFrameworkCore b.Property(x => x.Url).IsRequired().HasMaxLength(PageConsts.MaxUrlLength); b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength); - b.HasIndex(x => new {x.TenantId, x.Url}); + b.HasIndex(x => new { x.TenantId, x.Url }); }); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs deleted file mode 100644 index b8df8ec439..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Volo.CmsKit.Public.Tags -{ - public class GetRelatedTagsInput - { - [Required] - public string EntityType { get; set; } - - [Required] - public string EntityId { get; set; } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs index 29d786f086..34d54b9006 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs @@ -7,6 +7,6 @@ namespace Volo.CmsKit.Public.Tags { public interface ITagAppService : IApplicationService { - Task> GetAllRelatedTagsAsync(GetRelatedTagsInput input); + Task> GetAllRelatedTagsAsync(string entityType, string entityId); } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs index 8feaaa0130..593f011b02 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs @@ -9,28 +9,21 @@ namespace Volo.CmsKit.Public.Tags { public class TagAppService : CmsKitAppServiceBase, ITagAppService { - protected readonly ITagManager TagManager; protected readonly ITagRepository TagRepository; - protected readonly IEntityTagRepository EntityTagRepository; - public TagAppService( - ITagManager tagManager, - ITagRepository tagRepository, - IEntityTagRepository entityTagRepository) + public TagAppService(ITagRepository tagRepository) { - TagManager = tagManager; TagRepository = tagRepository; - EntityTagRepository = entityTagRepository; } - public virtual async Task> GetAllRelatedTagsAsync(GetRelatedTagsInput input) + public virtual async Task> GetAllRelatedTagsAsync(string entityType, string entityId) { var entities = await TagRepository.GetAllRelatedTagsAsync( - input.EntityType, - input.EntityId, - CurrentTenant.Id); + entityType, + entityId, + CurrentTenant.Id); return ObjectMapper.Map, List>(entities); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs deleted file mode 100644 index 307c5a4247..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.Abp; -using Volo.CmsKit.Tags; - -namespace Volo.CmsKit.Public.Tags -{ - [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] - [Area("cms-kit")] - [Route("api/cms-kit/tags")] - public class TagController : CmsKitPublicControllerBase, ITagAppService - { - protected readonly ITagAppService TagAppService; - - public TagController(ITagAppService tagAppService) - { - TagAppService = tagAppService; - } - - [HttpGet] - public Task> GetAllRelatedTagsAsync(GetRelatedTagsInput input) - { - return TagAppService.GetAllRelatedTagsAsync(input); - } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs new file mode 100644 index 0000000000..55041e5c6e --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.GlobalFeatures; +using Volo.CmsKit.GlobalFeatures; +using Volo.CmsKit.Tags; + +namespace Volo.CmsKit.Public.Tags +{ + [RequiresGlobalFeature(typeof(TagsFeature))] + [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] + [Area("cms-kit")] + [Route("api/cms-kit-public/tags")] + public class TagPublicController : CmsKitPublicControllerBase, ITagAppService + { + protected readonly ITagAppService TagAppService; + + public TagPublicController(ITagAppService tagAppService) + { + TagAppService = tagAppService; + } + + [HttpGet] + [Route("{entityType}/{entityId}")] + public Task> GetAllRelatedTagsAsync(string entityType, string entityId) + { + return TagAppService.GetAllRelatedTagsAsync(entityType, entityId); + } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs index 44deaad0ed..c40408117a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs @@ -24,11 +24,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags string entityType, string entityId) { - var tagDtos = await TagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityId = entityId, - EntityType = entityType - }); + var tagDtos = await TagAppService.GetAllRelatedTagsAsync(entityType, entityId); var viewModel = new TagViewModel { diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs index 6ad1136167..50eefd186b 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs @@ -2,9 +2,7 @@ using NSubstitute; using Shouldly; using System.Threading.Tasks; -using Volo.Abp.Clients; using Volo.Abp.Users; -using Volo.Abp.Validation; using Volo.CmsKit.Public.Tags; using Xunit; @@ -31,11 +29,8 @@ namespace Volo.CmsKit.Tags [Fact] public async Task GetAllRelatedTagsAsync() { - var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = _cmsKitTestData.Content_1_EntityType, - EntityId = _cmsKitTestData.EntityId1 - }); + var list = await _tagAppService.GetAllRelatedTagsAsync(_cmsKitTestData.Content_1_EntityType, + _cmsKitTestData.EntityId1); list.ShouldNotBeEmpty(); list.Count.ShouldBe(2); @@ -44,35 +39,9 @@ namespace Volo.CmsKit.Tags [Fact] public async Task ShouldntGet_GetAllRelatedTagsAsync() { - var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = "any_other_type", - EntityId = "1" - }); + var list = await _tagAppService.GetAllRelatedTagsAsync("any_other_type", "1"); list.ShouldBeEmpty(); } - - [Fact] - public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityType() - { - await Assert.ThrowsAsync(async () => - await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = null, - EntityId = _cmsKitTestData.EntityId1 - })); - } - - [Fact] - public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityId() - { - await Assert.ThrowsAsync(async () => - await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = null, - EntityId = _cmsKitTestData.EntityId1 - })); - } } -} +} \ No newline at end of file