Merge pull request #7024 from abpframework/tag-refactoring

CMS Kit - Tag Refactoring
pull/6926/head^2
Ahmet Çotur 5 years ago committed by GitHub
commit 6c474a2609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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; }

@ -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<EntityTag>(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 });
});
}
}

@ -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; }
}
}

@ -7,6 +7,6 @@ namespace Volo.CmsKit.Public.Tags
{
public interface ITagAppService : IApplicationService
{
Task<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input);
Task<List<TagDto>> GetAllRelatedTagsAsync(string entityType, string entityId);
}
}
}

@ -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<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input)
public virtual async Task<List<TagDto>> GetAllRelatedTagsAsync(string entityType, string entityId)
{
var entities = await TagRepository.GetAllRelatedTagsAsync(
input.EntityType,
input.EntityId,
CurrentTenant.Id);
entityType,
entityId,
CurrentTenant.Id);
return ObjectMapper.Map<List<Tag>, List<TagDto>>(entities);
}
}
}
}

@ -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<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input)
{
return TagAppService.GetAllRelatedTagsAsync(input);
}
}
}

@ -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<List<TagDto>> GetAllRelatedTagsAsync(string entityType, string entityId)
{
return TagAppService.GetAllRelatedTagsAsync(entityType, entityId);
}
}
}

@ -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
{

@ -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<AbpValidationException>(async () =>
await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput
{
EntityType = null,
EntityId = _cmsKitTestData.EntityId1
}));
}
[Fact]
public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityId()
{
await Assert.ThrowsAsync<AbpValidationException>(async () =>
await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput
{
EntityType = null,
EntityId = _cmsKitTestData.EntityId1
}));
}
}
}
}
Loading…
Cancel
Save