Browse Source

Delete comments when deleting blog posts and pages

pull/21108/head
liangshiwei 2 years ago
parent
commit
751639bcca
  1. 8
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs
  2. 8
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs
  3. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  4. 5
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  5. 5
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

8
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs

@ -10,6 +10,7 @@ using Volo.Abp.ObjectExtending;
using Volo.Abp.Users;
using Volo.CmsKit.Admin.MediaDescriptors;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Features;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Permissions;
@ -25,6 +26,8 @@ public class BlogPostAdminAppService : CmsKitAppServiceBase, IBlogPostAdminAppSe
protected BlogPostManager BlogPostManager { get; }
protected IBlogPostRepository BlogPostRepository { get; }
protected IBlogRepository BlogRepository { get; }
protected ICommentRepository CommentRepository { get; }
protected ICmsUserLookupService UserLookupService { get; }
protected IMediaDescriptorAdminAppService MediaDescriptorAdminAppService { get; }
@ -34,13 +37,15 @@ public class BlogPostAdminAppService : CmsKitAppServiceBase, IBlogPostAdminAppSe
IBlogPostRepository blogPostRepository,
IBlogRepository blogRepository,
ICmsUserLookupService userLookupService,
IMediaDescriptorAdminAppService mediaDescriptorAdminAppService)
IMediaDescriptorAdminAppService mediaDescriptorAdminAppService,
ICommentRepository commentRepository)
{
BlogPostManager = blogPostManager;
BlogPostRepository = blogPostRepository;
BlogRepository = blogRepository;
UserLookupService = userLookupService;
MediaDescriptorAdminAppService = mediaDescriptorAdminAppService;
CommentRepository = commentRepository;
}
[Authorize(CmsKitAdminPermissions.BlogPosts.Create)]
@ -127,6 +132,7 @@ public class BlogPostAdminAppService : CmsKitAppServiceBase, IBlogPostAdminAppSe
public virtual async Task DeleteAsync(Guid id)
{
await BlogPostRepository.DeleteAsync(id);
await CommentRepository.DeleteByEntityTypeAsync(BlogPostConsts.EntityType, id.ToString());
}
[Authorize(CmsKitAdminPermissions.BlogPosts.Publish)]

8
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs

@ -8,6 +8,7 @@ using Volo.Abp.Data;
using Volo.Abp.Features;
using Volo.Abp.GlobalFeatures;
using Volo.Abp.ObjectExtending;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Features;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Pages;
@ -21,6 +22,8 @@ namespace Volo.CmsKit.Admin.Pages;
public class PageAdminAppService : CmsKitAdminAppServiceBase, IPageAdminAppService
{
protected IPageRepository PageRepository { get; }
protected ICommentRepository CommentRepository { get; }
protected PageManager PageManager { get; }
@ -29,11 +32,13 @@ public class PageAdminAppService : CmsKitAdminAppServiceBase, IPageAdminAppServi
public PageAdminAppService(
IPageRepository pageRepository,
PageManager pageManager,
IDistributedCache<PageCacheItem> pageCache)
IDistributedCache<PageCacheItem> pageCache,
ICommentRepository commentRepository)
{
PageRepository = pageRepository;
PageManager = pageManager;
PageCache = pageCache;
CommentRepository = commentRepository;
}
public virtual async Task<PageDto> GetAsync(Guid id)
@ -108,6 +113,7 @@ public class PageAdminAppService : CmsKitAdminAppServiceBase, IPageAdminAppServi
await PageRepository.DeleteAsync(page);
await PageCache.RemoveAsync(PageCacheItem.GetKey(page.Slug));
await CommentRepository.DeleteByEntityTypeAsync(PageConsts.EntityType, id.ToString());
}
[Authorize(CmsKitAdminPermissions.Pages.SetAsHomePage)]

6
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs

@ -49,4 +49,10 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
);
Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default);
Task DeleteByEntityTypeAsync(
[NotNull] string entityType,
[NotNull] string entityId,
CancellationToken cancellationToken = default
);
}

5
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -186,4 +186,9 @@ public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Commen
.WhereIf(CommentApproveState.Disapproved == commentApproveState, c => c.Comment.IsApproved == false)
.WhereIf(CommentApproveState.Waiting == commentApproveState, c => c.Comment.IsApproved == null);
}
public async Task DeleteByEntityTypeAsync(string entityType, string entityId, CancellationToken cancellationToken = default)
{
await (await GetDbSetAsync()).Where(x => x.EntityType == entityType && x.EntityId == entityId).ExecuteDeleteAsync(GetCancellationToken(cancellationToken));
}
}

5
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -207,4 +207,9 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C
.WhereIf(CommentApproveState.Disapproved == commentApproveState, c => c.IsApproved == false)
.WhereIf(CommentApproveState.Waiting == commentApproveState, c => c.IsApproved == null);
}
public async Task DeleteByEntityTypeAsync(string entityType, string entityId, CancellationToken cancellationToken = default)
{
await (await GetDbContextAsync(cancellationToken)).Comments.DeleteManyAsync(x => x.EntityType == entityType && x.EntityId == entityId, GetCancellationToken(cancellationToken));
}
}

Loading…
Cancel
Save