Browse Source
Merge pull request #12612 from abpframework/enisn/5.2-cmskit-comments-query-fix
CmsKit - Comments query fix
pull/12613/head
Yunus Emre Kalkan
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
16 additions and
17 deletions
-
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
-
modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs
|
|
|
@ -7,7 +7,6 @@ using System.Threading.Tasks; |
|
|
|
using MongoDB.Driver; |
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories.MongoDB; |
|
|
|
using Volo.Abp.MongoDB; |
|
|
|
using Volo.CmsKit.Comments; |
|
|
|
@ -23,25 +22,16 @@ public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, C |
|
|
|
|
|
|
|
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var query = from comment in (await GetMongoQueryableAsync(cancellationToken)) |
|
|
|
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id |
|
|
|
where id == comment.Id |
|
|
|
select new { |
|
|
|
Comment = comment, |
|
|
|
Author = user |
|
|
|
}; |
|
|
|
|
|
|
|
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|
|
|
|
|
|
|
if (commentWithAuthor == null) |
|
|
|
{ |
|
|
|
throw new EntityNotFoundException(typeof(Comment), id); |
|
|
|
} |
|
|
|
var comment = await GetAsync(id); |
|
|
|
var author = await (await GetDbContextAsync()) |
|
|
|
.CmsUsers |
|
|
|
.AsQueryable() |
|
|
|
.FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken)); |
|
|
|
|
|
|
|
return new CommentWithAuthorQueryResultItem() |
|
|
|
{ |
|
|
|
Comment = commentWithAuthor.Comment, |
|
|
|
Author = commentWithAuthor.Author |
|
|
|
Comment = comment, |
|
|
|
Author = author |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -54,6 +54,15 @@ public abstract class CommentRepository_Tests<TStartupModule> : CmsKitTestBase<T |
|
|
|
list.Any(x => x.Author == null).ShouldBeFalse(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task GetWithAuthorAsync() |
|
|
|
{ |
|
|
|
var commentDetail = await _commentRepository.GetWithAuthorAsync(_cmsKitTestData.CommentWithChildId); |
|
|
|
|
|
|
|
commentDetail.ShouldNotBeNull(); |
|
|
|
commentDetail.Author.ShouldNotBeNull(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task DeleteWithRepliesAsync() |
|
|
|
{ |
|
|
|
|