CmsKit - Move single BlogFeature checking services to common

pull/7745/head
enisn 5 years ago
parent fa0aa17de4
commit 0c7f38b9ae

@ -1,13 +0,0 @@
using JetBrains.Annotations;
using System;
using Volo.Abp.Application.Dtos;
namespace Volo.CmsKit.Admin.Blogs
{
public class BlogFeatureDto : EntityDto<Guid>
{
[NotNull]
public string FeatureName { get; set; }
public bool Enabled { get; set; }
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.CmsKit.Blogs;
namespace Volo.CmsKit.Admin.Blogs
{

@ -2,11 +2,10 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Permissions;

@ -1,7 +1,7 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Volo.CmsKit.Public.Blogs
namespace Volo.CmsKit.Blogs
{
public class BlogFeatureDto : EntityDto<Guid>
{

@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.CmsKit.Public.Blogs
namespace Volo.CmsKit.Blogs
{
public interface IBlogFeaturePublicAppService
public interface IBlogFeatureAppService
{
Task<BlogFeatureDto> GetOrDefaultAsync(Guid blogId, string featureName);
}

@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\..\common.props" />
<Import Project="..\..\..\..\configureawait.props" />
<Import Project="..\..\..\..\common.props" />
<Import Project="..\..\..\..\configureawait.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" />
<ProjectReference Include="..\Volo.CmsKit.Common.Application.Contracts\Volo.CmsKit.Common.Application.Contracts.csproj" />
<ProjectReference Include="..\Volo.CmsKit.Domain\Volo.CmsKit.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" />
<ProjectReference Include="..\Volo.CmsKit.Common.Application.Contracts\Volo.CmsKit.Common.Application.Contracts.csproj" />
<ProjectReference Include="..\Volo.CmsKit.Domain\Volo.CmsKit.Domain.csproj" />
</ItemGroup>
</Project>

@ -1,20 +1,16 @@
using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.CmsKit.Blogs;
namespace Volo.CmsKit.Public.Blogs
namespace Volo.CmsKit.Blogs
{
public class BlogFeaturePublicAppService : CmsKitPublicAppServiceBase, IBlogFeaturePublicAppService
public class BlogFeatureAppService : CmsKitAppServiceBase, IBlogFeatureAppService
{
protected IBlogFeatureRepository BlogFeatureRepository { get; }
protected IDistributedCache<BlogFeatureDto> Cache { get; }
public BlogFeaturePublicAppService(
public BlogFeatureAppService(
IBlogFeatureRepository blogFeatureRepository,
IDistributedCache<BlogFeatureDto> cache)
{

@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
namespace Volo.CmsKit.Blogs
{
[RequiresGlobalFeature(typeof(BlogsFeature))]
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")]
[Route("api/cms-kit/blogs/{blogId}/features")]
public class BlogFeatureController : CmsKitControllerBase, IBlogFeatureAppService
{
protected IBlogFeatureAppService BlogFeatureAppService { get; }
public BlogFeatureController(IBlogFeatureAppService blogFeatureAppService)
{
BlogFeatureAppService = blogFeatureAppService;
}
[HttpGet]
[Route("{featureName}")]
public Task<BlogFeatureDto> GetOrDefaultAsync(Guid blogId, string featureName)
{
return BlogFeatureAppService.GetOrDefaultAsync(blogId, featureName);
}
}
}

@ -11,7 +11,6 @@
<ItemGroup>
<ProjectReference Include="..\Volo.CmsKit.Common.Application\Volo.CmsKit.Common.Application.csproj" />
<ProjectReference Include="..\Volo.CmsKit.Public.Application.Contracts\Volo.CmsKit.Public.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" />
</ItemGroup>
</Project>

@ -1,27 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.CmsKit.Public.Blogs;
namespace Volo.CmsKit.Public.HttpApi.Volo.CmsKit.Public.Blogs
{
public class BlogFeaturePublicController : CmsKitPublicControllerBase, IBlogFeaturePublicAppService
{
protected IBlogFeaturePublicAppService BlogFeaturePublicAppService { get; }
public BlogFeaturePublicController(IBlogFeaturePublicAppService blogFeaturePublicAppService)
{
BlogFeaturePublicAppService = blogFeaturePublicAppService;
}
[HttpGet]
[Route("{blogId}/{featureName}")]
public Task<BlogFeatureDto> GetOrDefaultAsync(Guid blogId, string featureName)
{
return BlogFeaturePublicAppService.GetOrDefaultAsync(blogId, featureName);
}
}
}

@ -30,14 +30,14 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Blogs
protected IBlogPostPublicAppService BlogPostPublicAppService { get; }
protected IBlogFeaturePublicAppService BlogFeaturePublicAppService { get; }
protected IBlogFeatureAppService BlogFeatureAppService { get; }
public BlogPostModel(
IBlogPostPublicAppService blogPostPublicAppService,
IBlogFeaturePublicAppService blogFeaturePublicAppService)
IBlogFeatureAppService blogFeaturePublicAppService)
{
BlogPostPublicAppService = blogPostPublicAppService;
BlogFeaturePublicAppService = blogFeaturePublicAppService;
BlogFeatureAppService = blogFeaturePublicAppService;
}
public virtual async Task OnGetAsync()
@ -46,17 +46,17 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Blogs
if (GlobalFeatureManager.Instance.IsEnabled<CommentsFeature>())
{
CommentsFeature = await BlogFeaturePublicAppService.GetOrDefaultAsync(BlogPost.BlogId, BlogPostConsts.CommentsFeatureName);
CommentsFeature = await BlogFeatureAppService.GetOrDefaultAsync(BlogPost.BlogId, BlogPostConsts.CommentsFeatureName);
}
if (GlobalFeatureManager.Instance.IsEnabled<ReactionsFeature>())
{
ReactionsFeature = await BlogFeaturePublicAppService.GetOrDefaultAsync(BlogPost.BlogId, BlogPostConsts.ReactionsFeatureName);
ReactionsFeature = await BlogFeatureAppService.GetOrDefaultAsync(BlogPost.BlogId, BlogPostConsts.ReactionsFeatureName);
}
if (GlobalFeatureManager.Instance.IsEnabled<RatingsFeature>())
{
RatingsFeature = await BlogFeaturePublicAppService.GetOrDefaultAsync(BlogPost.BlogId, BlogPostConsts.RatingsFeatureName);
RatingsFeature = await BlogFeatureAppService.GetOrDefaultAsync(BlogPost.BlogId, BlogPostConsts.RatingsFeatureName);
}
}
}

@ -12,18 +12,18 @@ namespace Volo.CmsKit.Blogs
public class BlogFeaturePublicAppService_Test : CmsKitApplicationTestBase
{
private readonly CmsKitTestData testData;
private readonly IBlogFeaturePublicAppService blogFeaturePublicAppService;
private readonly IBlogFeatureAppService blogFeatureAppService;
public BlogFeaturePublicAppService_Test()
{
testData = GetRequiredService<CmsKitTestData>();
blogFeaturePublicAppService = GetRequiredService<IBlogFeaturePublicAppService>();
blogFeatureAppService = GetRequiredService<IBlogFeatureAppService>();
}
[Fact]
public async Task GetAsync_ShouldWorkProperly_WithExistingFeatureName()
{
var result = await blogFeaturePublicAppService.GetOrDefaultAsync(testData.Blog_Id, testData.BlogFeature_1_FeatureName);
var result = await blogFeatureAppService.GetOrDefaultAsync(testData.Blog_Id, testData.BlogFeature_1_FeatureName);
result.ShouldNotBeNull();
result.FeatureName.ShouldBe(testData.BlogFeature_1_FeatureName);
@ -33,7 +33,7 @@ namespace Volo.CmsKit.Blogs
public async Task GetAsync_ShouldReturnDefault_WithNonExistingFeatureName()
{
var nonExistingFeatureName = "AnyOtherFeature";
var result = await blogFeaturePublicAppService.GetOrDefaultAsync(testData.Blog_Id, nonExistingFeatureName);
var result = await blogFeatureAppService.GetOrDefaultAsync(testData.Blog_Id, nonExistingFeatureName);
var defaultFeature = new BlogFeature(Guid.Empty, nonExistingFeatureName);
result.ShouldNotBeNull();

Loading…
Cancel
Save