Browse Source

Merge pull request #7763 from abpframework/cms-kit/blogs-refactoring

Cms Kit - Blogs Refactoring
pull/7807/head
İlkay İlknur 6 years ago
committed by GitHub
parent
commit
2807ea62a6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Blogs/IBlogAdminAppService.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Blogs/BlogAdminController.cs
  3. 12
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs
  4. 19
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPost.cs
  5. 31
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostManager.cs
  6. 7
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostSlugAlreadyExistException.cs
  7. 4
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostManager.cs
  8. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs
  9. 5
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs
  10. 9
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs
  11. 10
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs
  12. 7
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs
  13. 9
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs
  14. 10
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Blogs/IBlogAdminAppService.cs

@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
namespace Volo.CmsKit.Admin.Blogs namespace Volo.CmsKit.Admin.Blogs

2
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Blogs/BlogAdminController.cs

@ -17,7 +17,7 @@ namespace Volo.CmsKit.Admin.Blogs
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")] [Area("cms-kit")]
[Authorize(CmsKitAdminPermissions.Blogs.Default)] [Authorize(CmsKitAdminPermissions.Blogs.Default)]
[Route("api/cms-kit-admin/blogs/blogs")] [Route("api/cms-kit-admin/blogs")]
public class BlogAdminController : CmsKitAdminController, IBlogAdminAppService public class BlogAdminController : CmsKitAdminController, IBlogAdminAppService
{ {
protected IBlogAdminAppService BlogAdminAppService { get; } protected IBlogAdminAppService BlogAdminAppService { get; }

12
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs

@ -20,18 +20,20 @@ namespace Volo.CmsKit.Blogs
TenantId = tenantId; TenantId = tenantId;
} }
public string Name { get; protected set; } [NotNull]
public virtual string Name { get; protected set; }
public string Slug { get; protected set; } [NotNull]
public virtual string Slug { get; protected set; }
public Guid? TenantId { get; protected set; } public virtual Guid? TenantId { get; protected set; }
public void SetName(string name) public virtual void SetName(string name)
{ {
Name = Check.NotNullOrWhiteSpace(name, nameof(name), maxLength: BlogConsts.MaxNameLength); Name = Check.NotNullOrWhiteSpace(name, nameof(name), maxLength: BlogConsts.MaxNameLength);
} }
public void SetSlug(string slug) public virtual void SetSlug(string slug)
{ {
Check.NotNullOrWhiteSpace(slug, nameof(slug), maxLength: BlogConsts.MaxNameLength); Check.NotNullOrWhiteSpace(slug, nameof(slug), maxLength: BlogConsts.MaxNameLength);

19
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPost.cs

@ -1,10 +1,8 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using System; using System;
using System.Text.RegularExpressions;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.Blogs.Extensions; using Volo.CmsKit.Blogs.Extensions;
using Volo.CmsKit.Users; using Volo.CmsKit.Users;
@ -12,15 +10,18 @@ namespace Volo.CmsKit.Blogs
{ {
public class BlogPost : FullAuditedAggregateRootWithUser<Guid, CmsUser>, IMultiTenant public class BlogPost : FullAuditedAggregateRootWithUser<Guid, CmsUser>, IMultiTenant
{ {
public Guid BlogId { get; protected set; } public virtual Guid BlogId { get; protected set; }
public string Title { get; protected set; } [NotNull]
public virtual string Title { get; protected set; }
public string Slug { get; protected set; } [NotNull]
public virtual string Slug { get; protected set; }
public string ShortDescription { get; protected set; } [NotNull]
public virtual string ShortDescription { get; protected set; }
public Guid? TenantId { get; protected set; } public virtual Guid? TenantId { get; protected set; }
protected BlogPost() protected BlogPost()
{ {
@ -39,7 +40,7 @@ namespace Volo.CmsKit.Blogs
ShortDescription = shortDescription; ShortDescription = shortDescription;
} }
public void SetTitle(string title) public virtual void SetTitle(string title)
{ {
Title = Check.NotNullOrWhiteSpace(title, nameof(title), BlogPostConsts.MaxTitleLength); Title = Check.NotNullOrWhiteSpace(title, nameof(title), BlogPostConsts.MaxTitleLength);
} }
@ -51,7 +52,7 @@ namespace Volo.CmsKit.Blogs
Slug = slug.NormalizeSlug(); Slug = slug.NormalizeSlug();
} }
public void SetShortDescription(string shortDescription) public virtual void SetShortDescription(string shortDescription)
{ {
ShortDescription = Check.Length(shortDescription, nameof(shortDescription), BlogPostConsts.MaxShortDescriptionLength); ShortDescription = Check.Length(shortDescription, nameof(shortDescription), BlogPostConsts.MaxShortDescriptionLength);
} }

31
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostManager.cs

@ -1,8 +1,7 @@
using System; using JetBrains.Annotations;
using System.Collections.Generic; using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
@ -10,35 +9,37 @@ namespace Volo.CmsKit.Blogs
{ {
public class BlogPostManager : DomainService, IBlogPostManager public class BlogPostManager : DomainService, IBlogPostManager
{ {
protected readonly IBlogPostRepository blogPostRepository; protected IBlogPostRepository BlogPostRepository { get; }
protected readonly IBlogRepository blogRepository; protected IBlogRepository BlogRepository { get; }
public BlogPostManager( public BlogPostManager(
IBlogPostRepository blogPostRepository, IBlogPostRepository blogPostRepository,
IBlogRepository blogRepository) IBlogRepository blogRepository)
{ {
this.blogPostRepository = blogPostRepository; BlogPostRepository = blogPostRepository;
this.blogRepository = blogRepository; BlogRepository = blogRepository;
} }
public async Task<BlogPost> CreateAsync(BlogPost blogPost) public virtual async Task<BlogPost> CreateAsync(BlogPost blogPost)
{ {
await CheckBlogExistenceAsync(blogPost.BlogId); await CheckBlogExistenceAsync(blogPost.BlogId);
await CheckSlugExistenceAsync(blogPost.BlogId, blogPost.Slug); await CheckSlugExistenceAsync(blogPost.BlogId, blogPost.Slug);
return await blogPostRepository.InsertAsync(blogPost); return await BlogPostRepository.InsertAsync(blogPost);
} }
public async Task UpdateAsync(BlogPost blogPost) public virtual async Task UpdateAsync(BlogPost blogPost)
{ {
await CheckBlogExistenceAsync(blogPost.BlogId); await CheckBlogExistenceAsync(blogPost.BlogId);
await blogPostRepository.UpdateAsync(blogPost); await BlogPostRepository.UpdateAsync(blogPost);
} }
public async Task SetSlugUrlAsync(BlogPost blogPost, string newSlug) public virtual async Task SetSlugUrlAsync(BlogPost blogPost, [NotNull] string newSlug)
{ {
Check.NotNullOrWhiteSpace(newSlug, nameof(newSlug));
await CheckSlugExistenceAsync(blogPost.BlogId, newSlug); await CheckSlugExistenceAsync(blogPost.BlogId, newSlug);
blogPost.SetSlug(newSlug); blogPost.SetSlug(newSlug);
@ -46,7 +47,7 @@ namespace Volo.CmsKit.Blogs
private async Task CheckSlugExistenceAsync(Guid blogId, string slug) private async Task CheckSlugExistenceAsync(Guid blogId, string slug)
{ {
if (await blogPostRepository.SlugExistsAsync(blogId, slug)) if (await BlogPostRepository.SlugExistsAsync(blogId, slug))
{ {
throw new BlogPostSlugAlreadyExistException(blogId, slug); throw new BlogPostSlugAlreadyExistException(blogId, slug);
} }
@ -54,7 +55,7 @@ namespace Volo.CmsKit.Blogs
private async Task CheckBlogExistenceAsync(Guid blogId) private async Task CheckBlogExistenceAsync(Guid blogId)
{ {
if (!await blogRepository.ExistsAsync(blogId)) if (!await BlogRepository.ExistsAsync(blogId))
throw new EntityNotFoundException(typeof(Blog), blogId); throw new EntityNotFoundException(typeof(Blog), blogId);
} }
} }

7
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/BlogPostSlugAlreadyExistException.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Runtime.Serialization;
using Volo.Abp; using Volo.Abp;
namespace Volo.CmsKit.Blogs namespace Volo.CmsKit.Blogs
@ -9,7 +10,7 @@ namespace Volo.CmsKit.Blogs
{ {
} }
internal BlogPostSlugAlreadyExistException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) : base(serializationInfo, context) internal BlogPostSlugAlreadyExistException(SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) : base(serializationInfo, context)
{ {
} }
@ -24,8 +25,8 @@ namespace Volo.CmsKit.Blogs
WithData(nameof(BlogId), BlogId); WithData(nameof(BlogId), BlogId);
} }
public string Slug { get; } public virtual string Slug { get; }
public Guid BlogId { get; } public virtual Guid BlogId { get; }
} }
} }

4
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostManager.cs

@ -1,4 +1,4 @@
using System; using JetBrains.Annotations;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Volo.CmsKit.Blogs namespace Volo.CmsKit.Blogs
@ -9,6 +9,6 @@ namespace Volo.CmsKit.Blogs
Task UpdateAsync(BlogPost blogPost); Task UpdateAsync(BlogPost blogPost);
Task SetSlugUrlAsync(BlogPost blogPost, string newSlug); Task SetSlugUrlAsync(BlogPost blogPost, [NotNull] string newSlug);
} }
} }

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

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;

5
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogRepository.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -6,7 +7,7 @@ namespace Volo.CmsKit.Blogs
{ {
public interface IBlogRepository : IBasicRepository<Blog, Guid> public interface IBlogRepository : IBasicRepository<Blog, Guid>
{ {
public Task<Blog> GetBySlugAsync(string slug); public Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default);
Task<bool> ExistsAsync(Guid blogId); Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default);
} }
} }

9
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
@ -14,14 +15,14 @@ namespace Volo.CmsKit.Blogs
{ {
} }
public async Task<bool> ExistsAsync(Guid blogId) public virtual async Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId); return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, cancellationToken);
} }
public Task<Blog> GetBySlugAsync(string slug) public virtual Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
{ {
return GetAsync(x => x.Slug == slug); return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken);
} }
} }
} }

10
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs

@ -1,5 +1,6 @@
using MongoDB.Driver.Core.Operations; using MongoDB.Driver.Core.Operations;
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
@ -13,16 +14,17 @@ namespace Volo.CmsKit.MongoDB.Blogs
{ {
} }
public async Task<bool> ExistsAsync(Guid blogId) public virtual async Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await AsyncExecuter.AnyAsync( return await AsyncExecuter.AnyAsync(
await GetQueryableAsync(), await GetQueryableAsync(),
x => x.Id == blogId); x => x.Id == blogId,
cancellationToken);
} }
public Task<Blog> GetBySlugAsync(string slug) public virtual Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
{ {
return GetAsync(x => x.Slug == slug); return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken);
} }
} }
} }

7
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs

@ -1,4 +1,5 @@
using System; using JetBrains.Annotations;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
@ -8,9 +9,9 @@ namespace Volo.CmsKit.Public.Blogs
{ {
public interface IBlogPostPublicAppService public interface IBlogPostPublicAppService
{ {
Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, PagedAndSortedResultRequestDto input); Task<PagedResultDto<BlogPostPublicDto>> GetListAsync([NotNull] string blogSlug, PagedAndSortedResultRequestDto input);
Task<BlogPostPublicDto> GetAsync(string blogSlug, string blogPostSlug); Task<BlogPostPublicDto> GetAsync([NotNull] string blogSlug, [NotNull] string blogPostSlug);
Task<RemoteStreamContent> GetCoverImageAsync(Guid id); Task<RemoteStreamContent> GetCoverImageAsync(Guid id);
} }

9
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs

@ -1,4 +1,5 @@
using System; using JetBrains.Annotations;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
@ -26,7 +27,7 @@ namespace Volo.CmsKit.Public.Blogs
BlobContainer = blobContainer; BlobContainer = blobContainer;
} }
public async Task<BlogPostPublicDto> GetAsync(string blogSlug, string blogPostSlug) public virtual async Task<BlogPostPublicDto> GetAsync([NotNull] string blogSlug, [NotNull] string blogPostSlug)
{ {
var blog = await BlogRepository.GetBySlugAsync(blogSlug); var blog = await BlogRepository.GetBySlugAsync(blogSlug);
@ -35,7 +36,7 @@ namespace Volo.CmsKit.Public.Blogs
return ObjectMapper.Map<BlogPost, BlogPostPublicDto>(blogPost); return ObjectMapper.Map<BlogPost, BlogPostPublicDto>(blogPost);
} }
public async Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, PagedAndSortedResultRequestDto input) public virtual async Task<PagedResultDto<BlogPostPublicDto>> GetListAsync([NotNull] string blogSlug, PagedAndSortedResultRequestDto input)
{ {
var blog = await BlogRepository.GetBySlugAsync(blogSlug); var blog = await BlogRepository.GetBySlugAsync(blogSlug);
@ -46,7 +47,7 @@ namespace Volo.CmsKit.Public.Blogs
ObjectMapper.Map<List<BlogPost>, List<BlogPostPublicDto>>(blogPosts)); ObjectMapper.Map<List<BlogPost>, List<BlogPostPublicDto>>(blogPosts));
} }
public async Task<RemoteStreamContent> GetCoverImageAsync(Guid id) public virtual async Task<RemoteStreamContent> GetCoverImageAsync(Guid id)
{ {
var stream = await BlobContainer.GetAsync(id.ToString()); var stream = await BlobContainer.GetAsync(id.ToString());

10
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs

@ -1,15 +1,11 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Content; using Volo.Abp.Content;
using Volo.Abp.GlobalFeatures; using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Public.Blogs;
namespace Volo.CmsKit.Public.Blogs namespace Volo.CmsKit.Public.Blogs
{ {
@ -28,14 +24,14 @@ namespace Volo.CmsKit.Public.Blogs
[HttpGet] [HttpGet]
[Route("{blogSlug}/{blogPostSlug}")] [Route("{blogSlug}/{blogPostSlug}")]
public Task<BlogPostPublicDto> GetAsync(string blogSlug, string blogPostSlug) public virtual Task<BlogPostPublicDto> GetAsync(string blogSlug, string blogPostSlug)
{ {
return BlogPostPublicAppService.GetAsync(blogSlug, blogPostSlug); return BlogPostPublicAppService.GetAsync(blogSlug, blogPostSlug);
} }
[HttpGet] [HttpGet]
[Route("{id}/cover-image")] [Route("{id}/cover-image")]
public Task<RemoteStreamContent> GetCoverImageAsync(Guid id) public virtual Task<RemoteStreamContent> GetCoverImageAsync(Guid id)
{ {
Response.Headers.Add("Content-Disposition", $"inline;filename=\"{id}\""); Response.Headers.Add("Content-Disposition", $"inline;filename=\"{id}\"");
Response.Headers.Add("Accept-Ranges", "bytes"); Response.Headers.Add("Accept-Ranges", "bytes");
@ -47,7 +43,7 @@ namespace Volo.CmsKit.Public.Blogs
[HttpGet] [HttpGet]
[Route("{blogSlug}")] [Route("{blogSlug}")]
public Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, PagedAndSortedResultRequestDto input) public virtual Task<PagedResultDto<BlogPostPublicDto>> GetListAsync(string blogSlug, PagedAndSortedResultRequestDto input)
{ {
return BlogPostPublicAppService.GetListAsync(blogSlug, input); return BlogPostPublicAppService.GetListAsync(blogSlug, input);
} }

Loading…
Cancel
Save