From 681414dcd744143bc04ed5caa3d7e67c5a540d4f Mon Sep 17 00:00:00 2001 From: Ahmet Date: Tue, 16 Feb 2021 18:37:39 +0300 Subject: [PATCH] Added getlist to comment appservice and repositories --- .../Admin/Comments/CommentGetListInput.cs | 2 + .../Admin/Comments/ICommentAdminAppService.cs | 4 +- .../Admin/Comments/CommentAdminAppService.cs | 30 ++++++- .../CmsKit/Comments/ICommentRepository.cs | 25 ++++++ .../Comments/EfCoreCommentRepository.cs | 72 +++++++++++++++++ .../Comments/MongoCommentRepository.cs | 79 ++++++++++++++++++- 6 files changed, 207 insertions(+), 5 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs index 2113f93e99..69462870ff 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs @@ -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; } 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 48fbd2d108..d6903c0cc5 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 @@ -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> 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 44c763cd7c..a8e8faf6a2 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,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> GetListAsync(CommentGetListInput input) + public virtual async Task> 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>(comments); + + return new PagedResultDto(totalCount, dtos); } public virtual async Task GetAsync(Guid id) 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 523b03dd2f..7ea61d47bf 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 @@ -10,6 +10,31 @@ namespace Volo.CmsKit.Comments public interface ICommentRepository : IBasicRepository { Task GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default); + + Task> 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 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> GetListWithAuthorsAsync( [NotNull] string entityType, 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 725aa64e89..95781ae496 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 @@ -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> 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 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> GetListWithAuthorsAsync( string entityType, string entityId, @@ -81,5 +133,25 @@ namespace Volo.CmsKit.Comments await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken)); } + + protected virtual async Task> 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); + } } } 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 7e6a434c3f..78d727b57c 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 @@ -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> 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>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + + public async Task 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>() + .LongCountAsync(GetCancellationToken(cancellationToken)); + } + public async Task> GetListWithAuthorsAsync( string entityType, string entityId, @@ -92,5 +148,26 @@ namespace Volo.CmsKit.MongoDB.Comments cancellationToken: GetCancellationToken(cancellationToken) ); } + + protected virtual async Task> 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); + } } }