Browse Source

CmsKit - BlogFeature public implementation

pull/7745/head
enisn 6 years ago
parent
commit
e71051b15c
  1. 6
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs
  2. 8
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeature.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogFeatureRepository.cs
  4. 7
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogFeatureRepository.cs
  5. 7
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs
  6. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogFeatureDto.cs
  7. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/GetBlogFeatureInput.cs
  8. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogFeaturePublicAppService.cs
  9. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo.CmsKit.Public.Application.csproj
  10. 61
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogFeaturePublicAppService.cs
  11. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/CmsKitPublicApplicationModule.cs
  12. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs
  13. 34
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogFeaturePublicController.cs
  14. 34
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Blogs/BlogPost.cshtml
  15. 34
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Blogs/BlogPost.cshtml.cs

6
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs

@ -11,5 +11,11 @@
public static int MaxShortDescriptionLength { get; set; } = 256;
public const string EntityType = "BlogPost";
public const string CommentsFeatureName = "Comments";
public const string ReactionsFeatureName = "Reactions";
public const string RatingsFeatureName = "Ratings";
}
}

8
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogFeature.cs

@ -1,4 +1,6 @@
using System;
using JetBrains.Annotations;
using System;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
namespace Volo.CmsKit.Blogs
@ -9,10 +11,10 @@ namespace Volo.CmsKit.Blogs
{
}
public BlogFeature(Guid blogId, string featureName, bool enabled = true)
public BlogFeature(Guid blogId, [NotNull] string featureName, bool enabled = true)
{
BlogId = blogId;
FeatureName = featureName;
FeatureName = Check.NotNullOrWhiteSpace(featureName, nameof(featureName));
Enabled = enabled;
}

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogFeatureRepository.cs

@ -11,6 +11,8 @@ namespace Volo.CmsKit.Blogs
{
Task<List<BlogFeature>> GetListAsync(Guid blogId);
Task<List<BlogFeature>> GetListAsync(Guid blogId, string[] featureNames);
Task<BlogFeature> FindAsync(Guid blogId, string featureName);
}
}

7
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogFeatureRepository.cs

@ -26,5 +26,12 @@ namespace Volo.CmsKit.Blogs
.Where(x => x.BlogId == blogId)
.ToListAsync();
}
public async Task<List<BlogFeature>> GetListAsync(Guid blogId, string[] featureNames)
{
return await (await GetQueryableAsync())
.Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName))
.ToListAsync();
}
}
}

7
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogFeatureRepository.cs

@ -28,5 +28,12 @@ namespace Volo.CmsKit.MongoDB.Blogs
.Where(x => x.BlogId == blogId)
.ToListAsync();
}
public async Task<List<BlogFeature>> GetListAsync(Guid blogId, string[] featureNames)
{
return await (await GetMongoQueryableAsync())
.Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName))
.ToListAsync();
}
}
}

11
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogFeatureDto.cs

@ -0,0 +1,11 @@
using System;
using Volo.Abp.Application.Dtos;
namespace Volo.CmsKit.Public.Blogs
{
public class BlogFeatureDto : EntityDto<Guid>
{
public string FeatureName { get; set; }
public bool Enabled { get; set; }
}
}

13
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/GetBlogFeatureInput.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Volo.CmsKit.Public.Blogs
{
public class GetBlogFeatureInput
{
public string[] FeatureNames { get; set; }
}
}

13
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogFeaturePublicAppService.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.CmsKit.Public.Blogs
{
public interface IBlogFeaturePublicAppService
{
Task<BlogFeatureDto> GetAsync(Guid blogId, string featureName);
Task<List<BlogFeatureDto>> GetManyAsync(Guid blogId, GetBlogFeatureInput input);
}
}

1
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo.CmsKit.Public.Application.csproj

@ -11,6 +11,7 @@
<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>

61
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogFeaturePublicAppService.cs

@ -0,0 +1,61 @@
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
{
public class BlogFeaturePublicAppService : CmsKitPublicAppServiceBase, IBlogFeaturePublicAppService
{
protected IBlogFeatureRepository BlogFeatureRepository { get; }
protected IDistributedCache<BlogFeatureDto> Cache { get; }
public BlogFeaturePublicAppService(
IBlogFeatureRepository blogFeatureRepository,
IDistributedCache<BlogFeatureDto> cache)
{
BlogFeatureRepository = blogFeatureRepository;
Cache = cache;
}
public async Task<BlogFeatureDto> GetAsync(Guid blogId, string featureName)
{
return await Cache.GetOrAddAsync(
$"{blogId}_{featureName}",
() => GetFromDatabaseAsync(blogId, featureName),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1)
});
}
private async Task<BlogFeatureDto> GetFromDatabaseAsync(Guid blogId, string featureName)
{
var feature = await BlogFeatureRepository.FindAsync(blogId, featureName);
if (feature == null)
{
feature = new BlogFeature(blogId, featureName);
}
return ObjectMapper.Map<BlogFeature, BlogFeatureDto>(feature);
}
public async Task<List<BlogFeatureDto>> GetManyAsync(Guid blogId, GetBlogFeatureInput input)
{
var features = await BlogFeatureRepository.GetListAsync(blogId);
var nonExistingFeatures = input.FeatureNames.Where(x => !features.Any(a => a.FeatureName == x));
foreach (var featureName in nonExistingFeatures)
{
features.Add(new BlogFeature(blogId, featureName));
}
return ObjectMapper.Map<List<BlogFeature>, List<BlogFeatureDto>>(features);
}
}
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/CmsKitPublicApplicationModule.cs

@ -1,12 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Modularity;
namespace Volo.CmsKit.Public
{
[DependsOn(
typeof(CmsKitCommonApplicationModule),
typeof(CmsKitPublicApplicationContractsModule)
typeof(CmsKitPublicApplicationContractsModule),
typeof(AbpCachingModule)
)]
public class CmsKitPublicApplicationModule : AbpModule
{

2
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/PublicApplicationAutoMapperProfile.cs

@ -34,6 +34,8 @@ namespace Volo.CmsKit.Public
CreateMap<Page, PageDto>();
CreateMap<BlogPost, BlogPostPublicDto>(MemberList.None);
CreateMap<BlogFeature, BlogFeatureDto>();
}
}
}

34
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogFeaturePublicController.cs

@ -0,0 +1,34 @@
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> GetAsync(Guid blogId, string featureName)
{
return BlogFeaturePublicAppService.GetAsync(blogId, featureName);
}
[HttpGet]
[Route("{blogId}")]
public Task<List<BlogFeatureDto>> GetManyAsync(Guid blogId, GetBlogFeatureInput input)
{
return BlogFeaturePublicAppService.GetManyAsync(blogId, input);
}
}
}

34
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Blogs/BlogPost.cshtml

@ -35,29 +35,39 @@
@if (GlobalFeatureManager.Instance.IsEnabled<ReactionsFeature>())
{
@await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new
if (Model.ReactionsFeature?.Enabled == true)
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString()
})
@await Component.InvokeAsync(typeof(ReactionSelectionViewComponent), new
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString()
})
}
}
@if (GlobalFeatureManager.Instance.IsEnabled<RatingsFeature>())
{
@await Component.InvokeAsync(typeof(RatingViewComponent), new
if (Model.RatingsFeature?.Enabled == true)
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString()
})
@await Component.InvokeAsync(typeof(RatingViewComponent), new
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString()
})
}
}
<hr />
@if (GlobalFeatureManager.Instance.IsEnabled<CommentsFeature>())
{
@await Component.InvokeAsync(typeof(DefaultBlogPostCommentViewComponent), new
if (Model.CommentsFeature?.Enabled == true)
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString()
})
@await Component.InvokeAsync(typeof(DefaultBlogPostCommentViewComponent), new
{
entityType = Volo.CmsKit.Blogs.BlogPostConsts.EntityType,
entityId = Model.BlogPost.Id.ToString()
})
}
}

34
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Blogs/BlogPost.cshtml.cs

@ -2,8 +2,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Public.Blogs;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Blogs
@ -18,16 +22,42 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Blogs
public BlogPostPublicDto BlogPost { get; private set; }
public BlogFeatureDto CommentsFeature { get; private set; }
public BlogFeatureDto ReactionsFeature { get; private set; }
public BlogFeatureDto RatingsFeature { get; private set; }
protected IBlogPostPublicAppService BlogPostPublicAppService { get; }
public BlogPostModel(IBlogPostPublicAppService blogPostPublicAppService)
protected IBlogFeaturePublicAppService BlogFeaturePublicAppService { get; }
public BlogPostModel(
IBlogPostPublicAppService blogPostPublicAppService,
IBlogFeaturePublicAppService blogFeaturePublicAppService)
{
BlogPostPublicAppService = blogPostPublicAppService;
BlogFeaturePublicAppService = blogFeaturePublicAppService;
}
public async Task OnGetAsync()
public virtual async Task OnGetAsync()
{
BlogPost = await BlogPostPublicAppService.GetAsync(BlogSlug, BlogPostSlug);
if (GlobalFeatureManager.Instance.IsEnabled<CommentsFeature>())
{
CommentsFeature = await BlogFeaturePublicAppService.GetAsync(BlogPost.Id, BlogPostConsts.CommentsFeatureName);
}
if (GlobalFeatureManager.Instance.IsEnabled<ReactionsFeature>())
{
ReactionsFeature = await BlogFeaturePublicAppService.GetAsync(BlogPost.Id, BlogPostConsts.ReactionsFeatureName);
}
if (GlobalFeatureManager.Instance.IsEnabled<RatingsFeature>())
{
RatingsFeature = await BlogFeaturePublicAppService.GetAsync(BlogPost.Id, BlogPostConsts.RatingsFeatureName);
}
}
}
}

Loading…
Cancel
Save