diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs index d6903c0cc5..2bddc35a25 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs @@ -7,7 +7,7 @@ namespace Volo.CmsKit.Admin.Comments { public interface ICommentAdminAppService : IApplicationService { - Task> GetListAsync(CommentGetListInput input); + Task> GetListAsync(CommentGetListInput input); Task GetAsync(Guid id); diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs index e045f1137a..238e475f15 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Dtos; @@ -22,7 +23,7 @@ namespace Volo.CmsKit.Admin.Comments CommentRepository = commentRepository; } - public virtual async Task> GetListAsync(CommentGetListInput input) + public virtual async Task> GetListAsync(CommentGetListInput input) { var totalCount = await CommentRepository.GetCountAsync( input.Text, @@ -46,9 +47,15 @@ namespace Volo.CmsKit.Admin.Comments input.SkipCount ); - var dtos = ObjectMapper.Map, List>(comments); + var dtos = comments.Select(queryResultItem => + { + var dto = ObjectMapper.Map(queryResultItem.Comment); + dto.Author = ObjectMapper.Map(queryResultItem.Author); - return new PagedResultDto(totalCount, dtos); + return dto; + }).ToList(); + + return new PagedResultDto(totalCount, dtos); } public virtual async Task GetAsync(Guid id) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs index 9f71761235..91482d137a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs @@ -25,7 +25,7 @@ namespace Volo.CmsKit.Admin.Comments } [HttpGet] - public virtual Task> GetListAsync(CommentGetListInput input) + public virtual Task> GetListAsync(CommentGetListInput input) { return CommentAdminAppService.GetListAsync(input); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs index 6293e125b6..f6c4cfb25c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs @@ -11,7 +11,7 @@ namespace Volo.CmsKit.Comments { Task GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default); - Task> GetListAsync( + Task> GetListAsync( string filter = null, string entityType = null, string entityId = null, diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs index 1e939e7740..9be480ce11 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs @@ -43,7 +43,7 @@ namespace Volo.CmsKit.Comments return commentWithAuthor; } - public async Task> GetListAsync( + public async Task> GetListAsync( string filter = null, string entityType = null, string entityId = null, @@ -66,9 +66,19 @@ namespace Volo.CmsKit.Comments creationStartDate, creationEndDate); - return await query.OrderBy(sorting ?? "creationTime desc") - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + query = query.OrderBy(sorting ?? "creationTime desc") + .PageBy(skipCount, maxResultCount); + + var query2 = from comment in query + join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id + orderby comment.CreationTime + select new CommentWithAuthorQueryResultItem + { + Comment = comment, + Author = user + }; + + return await query2.ToListAsync(GetCancellationToken(cancellationToken)); } public async Task GetCountAsync( diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs index 39eb8cb223..351a78333b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs @@ -11,6 +11,7 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Comments; +using Volo.CmsKit.Users; namespace Volo.CmsKit.MongoDB.Comments { @@ -41,7 +42,7 @@ namespace Volo.CmsKit.MongoDB.Comments return commentWithAuthor; } - public async Task> GetListAsync( + public async Task> GetListAsync( string filter = null, string entityType = null, string entityId = null, @@ -65,10 +66,29 @@ namespace Volo.CmsKit.MongoDB.Comments creationEndDate, cancellationToken); - return await query.OrderBy(sorting ?? "creationTime desc") + var comments = await query.OrderBy(sorting ?? "creationTime desc") .As>() .PageBy>(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); + + var commentIds = comments.Select(x => x.Id).ToList(); + + var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken)) + join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id + where commentIds.Contains(comment.Id) + orderby comment.CreationTime + select user; + + var authors = await authorsQuery.ToListAsync(cancellationToken); + + return comments + .Select( + comment => + new CommentWithAuthorQueryResultItem + { + Comment = comment, + Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId) + }).ToList(); } public async Task GetCountAsync( diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Comments/CommentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Comments/CommentAdminAppService_Tests.cs index e42312a97b..7c62889201 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Comments/CommentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Comments/CommentAdminAppService_Tests.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using Shouldly; using Volo.Abp.Domain.Entities; using Volo.CmsKit.Admin.Comments; @@ -27,6 +28,7 @@ namespace Volo.CmsKit.Comments comments.TotalCount.ShouldBe(6); comments.Items.Count.ShouldBe(3); + comments.Items.Any(x => x.Author != null).ShouldBeTrue(); } [Fact] diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs index e7b36a242a..3b166834a0 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs @@ -26,7 +26,7 @@ namespace Volo.CmsKit.Comments comments.ShouldNotBeNull(); comments.Count.ShouldBe(6); - var headCommentId = comments.First(x => x.RepliedCommentId != null).RepliedCommentId; + var headCommentId = comments.First(x => x.Comment.RepliedCommentId != null).Comment.RepliedCommentId; var replies = await _commentRepository.GetListAsync(repliedCommentId: headCommentId); @@ -63,7 +63,7 @@ namespace Volo.CmsKit.Comments var list = await _commentRepository.GetListAsync(); list.Any(x=> - x.Id == _cmsKitTestData.CommentWithChildId || x.RepliedCommentId == _cmsKitTestData.CommentWithChildId) + x.Comment.Id == _cmsKitTestData.CommentWithChildId || x.Comment.RepliedCommentId == _cmsKitTestData.CommentWithChildId) .ShouldBeFalse(); } }