Browse Source

tag methods refactoring.

Renamed controllers.
Changed method signatures.
pull/7024/head
Ilkay Ilknur 6 years ago
parent
commit
1153d72ffa
  1. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs
  2. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs
  3. 19
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs
  4. 27
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs
  5. 31
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs
  6. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs
  7. 39
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs

13
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs

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

4
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<List<TagDto>> GetAllRelatedTagsAsync(GetRelatedTagsInput input);
Task<List<TagDto>> GetAllRelatedTagsAsync(string entityType, string entityId);
}
}
}

19
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<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);
}
}
}
}

27
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs

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

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

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

39
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<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