Browse Source

added author information to comment return list

pull/7757/head
Ahmet 6 years ago
parent
commit
da78623e83
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/ICommentAdminAppService.cs
  2. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs
  4. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  5. 18
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  6. 24
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  7. 4
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Comments/CommentAdminAppService_Tests.cs
  8. 4
      modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs

2
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 public interface ICommentAdminAppService : IApplicationService
{ {
Task<PagedResultDto<CommentDto>> GetListAsync(CommentGetListInput input); Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input);
Task<CommentWithAuthorDto> GetAsync(Guid id); Task<CommentWithAuthorDto> GetAsync(Guid id);

13
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
@ -22,7 +23,7 @@ namespace Volo.CmsKit.Admin.Comments
CommentRepository = commentRepository; CommentRepository = commentRepository;
} }
public virtual async Task<PagedResultDto<CommentDto>> GetListAsync(CommentGetListInput input) public virtual async Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input)
{ {
var totalCount = await CommentRepository.GetCountAsync( var totalCount = await CommentRepository.GetCountAsync(
input.Text, input.Text,
@ -46,9 +47,15 @@ namespace Volo.CmsKit.Admin.Comments
input.SkipCount input.SkipCount
); );
var dtos = ObjectMapper.Map<List<Comment>, List<CommentDto>>(comments); var dtos = comments.Select(queryResultItem =>
{
var dto = ObjectMapper.Map<Comment, CommentWithAuthorDto>(queryResultItem.Comment);
dto.Author = ObjectMapper.Map<CmsUser, CmsUserDto>(queryResultItem.Author);
return new PagedResultDto<CommentDto>(totalCount, dtos); return dto;
}).ToList();
return new PagedResultDto<CommentWithAuthorDto>(totalCount, dtos);
} }
public virtual async Task<CommentWithAuthorDto> GetAsync(Guid id) public virtual async Task<CommentWithAuthorDto> GetAsync(Guid id)

2
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs

@ -25,7 +25,7 @@ namespace Volo.CmsKit.Admin.Comments
} }
[HttpGet] [HttpGet]
public virtual Task<PagedResultDto<CommentDto>> GetListAsync(CommentGetListInput input) public virtual Task<PagedResultDto<CommentWithAuthorDto>> GetListAsync(CommentGetListInput input)
{ {
return CommentAdminAppService.GetListAsync(input); return CommentAdminAppService.GetListAsync(input);
} }

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

@ -11,7 +11,7 @@ namespace Volo.CmsKit.Comments
{ {
Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default); Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default);
Task<List<Comment>> GetListAsync( Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
string entityId = null, string entityId = null,

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

@ -43,7 +43,7 @@ namespace Volo.CmsKit.Comments
return commentWithAuthor; return commentWithAuthor;
} }
public async Task<List<Comment>> GetListAsync( public async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
string entityId = null, string entityId = null,
@ -66,9 +66,19 @@ namespace Volo.CmsKit.Comments
creationStartDate, creationStartDate,
creationEndDate); creationEndDate);
return await query.OrderBy(sorting ?? "creationTime desc") query = query.OrderBy(sorting ?? "creationTime desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount);
.ToListAsync(GetCancellationToken(cancellationToken));
var query2 = from comment in query
join user in (await GetDbContextAsync()).Set<CmsUser>() 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<long> GetCountAsync( public async Task<long> GetCountAsync(

24
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.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.CmsKit.Comments; using Volo.CmsKit.Comments;
using Volo.CmsKit.Users;
namespace Volo.CmsKit.MongoDB.Comments namespace Volo.CmsKit.MongoDB.Comments
{ {
@ -41,7 +42,7 @@ namespace Volo.CmsKit.MongoDB.Comments
return commentWithAuthor; return commentWithAuthor;
} }
public async Task<List<Comment>> GetListAsync( public async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
string entityId = null, string entityId = null,
@ -65,10 +66,29 @@ namespace Volo.CmsKit.MongoDB.Comments
creationEndDate, creationEndDate,
cancellationToken); cancellationToken);
return await query.OrderBy(sorting ?? "creationTime desc") var comments = await query.OrderBy(sorting ?? "creationTime desc")
.As<IMongoQueryable<Comment>>() .As<IMongoQueryable<Comment>>()
.PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount) .PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .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<long> GetCountAsync( public async Task<long> GetCountAsync(

4
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 Shouldly;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.CmsKit.Admin.Comments; using Volo.CmsKit.Admin.Comments;
@ -27,6 +28,7 @@ namespace Volo.CmsKit.Comments
comments.TotalCount.ShouldBe(6); comments.TotalCount.ShouldBe(6);
comments.Items.Count.ShouldBe(3); comments.Items.Count.ShouldBe(3);
comments.Items.Any(x => x.Author != null).ShouldBeTrue();
} }
[Fact] [Fact]

4
modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs

@ -26,7 +26,7 @@ namespace Volo.CmsKit.Comments
comments.ShouldNotBeNull(); comments.ShouldNotBeNull();
comments.Count.ShouldBe(6); 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); var replies = await _commentRepository.GetListAsync(repliedCommentId: headCommentId);
@ -63,7 +63,7 @@ namespace Volo.CmsKit.Comments
var list = await _commentRepository.GetListAsync(); var list = await _commentRepository.GetListAsync();
list.Any(x=> list.Any(x=>
x.Id == _cmsKitTestData.CommentWithChildId || x.RepliedCommentId == _cmsKitTestData.CommentWithChildId) x.Comment.Id == _cmsKitTestData.CommentWithChildId || x.Comment.RepliedCommentId == _cmsKitTestData.CommentWithChildId)
.ShouldBeFalse(); .ShouldBeFalse();
} }
} }

Loading…
Cancel
Save