mirror of https://github.com/abpframework/abp.git
15 changed files with 219 additions and 18 deletions
@ -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; } |
|||
} |
|||
} |
|||
@ -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; } |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue