diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/Dtos/CommentDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/Dtos/CommentDto.cs index b89c964c27..f43b7f552b 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/Dtos/CommentDto.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/Dtos/CommentDto.cs @@ -5,7 +5,7 @@ namespace Volo.Blogging.Comments.Dtos { public class CommentDto : FullAuditedEntityDto { - public Guid RepliedCommentId { get; set; } + public Guid? RepliedCommentId { get; set; } public string Text { get; set; } } diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs index 2b27c67ca4..32b4f4cd18 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Comments/ICommentAppService.cs @@ -8,8 +8,6 @@ namespace Volo.Blogging.Comments { public interface ICommentAppService : IApplicationService { - Task> GetListOfPostAsync(GetCommentListOfPostAsync input); - Task> GetHierarchicalListOfPostAsync(GetCommentListOfPostAsync input); Task CreateAsync(CreateCommentDto input); diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index a3e17bc109..02dee1b1ca 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -9,7 +9,7 @@ using Volo.Blogging.Comments.Dtos; namespace Volo.Blogging.Comments { - // [Authorize(BloggingPermissions.Comments.Default)] + // [Authorize(BloggingPermissions.Comments.Default)] public class CommentAppService : ApplicationService, ICommentAppService { private readonly ICommentRepository _commentRepository; @@ -42,15 +42,10 @@ namespace Volo.Blogging.Comments hierarchicalComments = hierarchicalComments.OrderByDescending(c => c.Comment.CreationTime).ToList(); - foreach (var hierarchicalComment in hierarchicalComments) - { - hierarchicalComment.Replies = hierarchicalComment.Replies.OrderBy(c => c.CreationTime).ToList(); - } - return hierarchicalComments; } - public async Task> GetListOfPostAsync(GetCommentListOfPostAsync input) + private async Task> GetListOfPostAsync(GetCommentListOfPostAsync input) { var comments = await _commentRepository.GetListOfPostAsync(input.PostId); diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index f39f9f369e..baf14fa8f7 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -41,11 +41,7 @@ namespace Volo.Blogging.Posts foreach (var postDto in postDtos) { - var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); - - var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId)); - - postDto.Tags = ObjectMapper.Map, List>(tags); + postDto.Tags = await GetTagsOfPost(postDto); postDto.CommentCount = (await _commentRepository.GetListAsync()).Count(p => p.PostId == postDto.Id); } @@ -67,11 +63,7 @@ namespace Volo.Blogging.Posts var postDto = ObjectMapper.Map(post); - var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); - - var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId)); - - postDto.Tags = ObjectMapper.Map, List>(tags); + postDto.Tags = await GetTagsOfPost(postDto); return postDto; } @@ -82,11 +74,7 @@ namespace Volo.Blogging.Posts var postDto = ObjectMapper.Map(post); - var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); - - var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId)); - - postDto.Tags = ObjectMapper.Map, List>(tags); + postDto.Tags = await GetTagsOfPost(postDto); return postDto; } @@ -162,6 +150,15 @@ namespace Volo.Blogging.Posts } + private async Task> GetTagsOfPost(PostWithDetailsDto postDto) + { + var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == postDto.Id); + + var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId)); + + return ObjectMapper.Map, List>(tags); + } + private List SplitTags(string tags) { if (tags.IsNullOrWhiteSpace())