Added getlist to comment appservice and repositories

pull/7757/head
Ahmet 5 years ago
parent 1843bae871
commit 681414dcd7

@ -5,6 +5,8 @@ namespace Volo.CmsKit.Admin.Comments
{
public class CommentGetListInput : PagedAndSortedResultRequestDto
{
public string Filter { get; set; }
public string EntityType { get; set; }
public string EntityId { get; set; }

@ -1,13 +1,13 @@
using System;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Volo.CmsKit.Admin.Comments
{
public interface ICommentAdminAppService : IApplicationService
{
Task<PagedResult<CommentDto>> GetListAsync(CommentGetListInput input);
Task<PagedResultDto<CommentDto>> GetListAsync(CommentGetListInput input);
Task<CommentWithAuthorDto> GetAsync(Guid id);

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Users;
@ -15,9 +17,33 @@ namespace Volo.CmsKit.Admin.Comments
CommentRepository = commentRepository;
}
public virtual Task<PagedResult<CommentDto>> GetListAsync(CommentGetListInput input)
public virtual async Task<PagedResultDto<CommentDto>> GetListAsync(CommentGetListInput input)
{
throw new System.NotImplementedException();
var totalCount = await CommentRepository.GetCountAsync(
input.Filter,
input.EntityType,
input.EntityId,
input.RepliedCommentId,
input.CreatorId,
input.CreationStartDate,
input.CreationEndDate);
var comments = await CommentRepository.GetListAsync(
input.Filter,
input.EntityType,
input.EntityId,
input.RepliedCommentId,
input.CreatorId,
input.CreationStartDate,
input.CreationEndDate,
input.Sorting,
input.MaxResultCount,
input.SkipCount
);
var dtos = ObjectMapper.Map<List<Comment>, List<CommentDto>>(comments);
return new PagedResultDto<CommentDto>(totalCount, dtos);
}
public virtual async Task<CommentWithAuthorDto> GetAsync(Guid id)

@ -10,6 +10,31 @@ namespace Volo.CmsKit.Comments
public interface ICommentRepository : IBasicRepository<Comment, Guid>
{
Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default);
Task<List<Comment>> GetListAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CancellationToken cancellationToken = default
);
Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType,

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -42,6 +43,57 @@ namespace Volo.CmsKit.Comments
return commentWithAuthor;
}
public async Task<List<Comment>> GetListAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default
)
{
var query = await GetListQueryAsync(
filter,
entityType,
entityId,
repliedCommentId,
creatorId,
creationStartDate,
creationEndDate);
return await query.OrderBy(sorting ?? "creationTime desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<long> GetCountAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CancellationToken cancellationToken = default
)
{
var query = await GetListQueryAsync(
filter,
entityType,
entityId,
repliedCommentId,
creatorId,
creationStartDate,
creationEndDate);
return await query.LongCountAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,
@ -81,5 +133,25 @@ namespace Volo.CmsKit.Comments
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
}
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null
)
{
return (await GetDbSetAsync())
.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(!entityId.IsNullOrWhiteSpace(), c => c.EntityId == entityId)
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creatorId.HasValue, c => c.CreatorId == creatorId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
}
}
}

@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver.Linq;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.MongoDB;
@ -40,6 +41,61 @@ namespace Volo.CmsKit.MongoDB.Comments
return commentWithAuthor;
}
public async Task<List<Comment>> GetListAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
CancellationToken cancellationToken = default
)
{
var query = await GetListQueryAsync(
filter,
entityType,
entityId,
repliedCommentId,
creatorId,
creationStartDate,
creationEndDate,
cancellationToken);
return await query.OrderBy(sorting ?? "creationTime desc")
.As<IMongoQueryable<Comment>>()
.PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<long> GetCountAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CancellationToken cancellationToken = default
)
{
var query = await GetListQueryAsync(
filter,
entityType,
entityId,
repliedCommentId,
creatorId,
creationStartDate,
creationEndDate,
cancellationToken);
return await query.As<IMongoQueryable<Comment>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId,
@ -92,5 +148,26 @@ namespace Volo.CmsKit.MongoDB.Comments
cancellationToken: GetCancellationToken(cancellationToken)
);
}
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
string filter = null,
string entityType = null,
string entityId = null,
Guid? repliedCommentId = null,
Guid? creatorId = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
CancellationToken cancellationToken = default
)
{
return (await GetMongoQueryableAsync(cancellationToken))
.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(!entityId.IsNullOrWhiteSpace(), c => c.EntityId == entityId)
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
.WhereIf(creatorId.HasValue, c => c.CreatorId == creatorId)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
}
}
}

Loading…
Cancel
Save