Browse Source

code review was done.

pull/19919/head
EmreKendirli 2 years ago
parent
commit
9cc53bdbe9
  1. 2
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Volo.CmsKit.Web.Unified.csproj
  2. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs
  3. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs
  4. 1
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs
  5. 16
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  6. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Comments/CommentAdminController.cs
  7. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/CommentSettingViewComponent.cs
  8. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml
  9. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml
  10. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs
  11. 13
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml
  12. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
  13. 9
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js
  14. 5
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
  15. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs
  16. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
  17. 12
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs
  18. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  19. 14
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  20. 346
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  21. 454
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  22. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

2
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Volo.CmsKit.Web.Unified.csproj

@ -6,7 +6,7 @@
<PreserveCompilationReferences>true</PreserveCompilationReferences> <PreserveCompilationReferences>true</PreserveCompilationReferences>
<UserSecretsId>Volo.CmsKit-c2d31439-b723-48e2-b061-5ebd7aeb6010</UserSecretsId> <UserSecretsId>Volo.CmsKit-c2d31439-b723-48e2-b061-5ebd7aeb6010</UserSecretsId>
<!-- Options for DB: MongoDB, EntityFrameworkCore --> <!-- Options for DB: MongoDB, EntityFrameworkCore -->
<DefineConstants>$(DefineConstants);MongoDB</DefineConstants> <DefineConstants>$(DefineConstants);MongoDB </DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

4
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Comments/CommentGetListInput.cs

@ -1,5 +1,6 @@
using System; using System;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Comments; namespace Volo.CmsKit.Admin.Comments;
@ -17,7 +18,8 @@ public class CommentGetListInput : PagedAndSortedResultRequestDto
public DateTime? CreationStartDate { get; set; } public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; } public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; }
public CommentApproveStateType commentApproveStateType { get; set; }
} }

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs

@ -17,6 +17,8 @@ public class CmsKitAdminPermissionDefinitionProvider : PermissionDefinitionProvi
.RequireGlobalFeatures(typeof(CommentsFeature)); .RequireGlobalFeatures(typeof(CommentsFeature));
contentGroup.AddChild(CmsKitAdminPermissions.Comments.Delete, L("Permission:Comments.Delete")) contentGroup.AddChild(CmsKitAdminPermissions.Comments.Delete, L("Permission:Comments.Delete"))
.RequireGlobalFeatures(typeof(CommentsFeature)); .RequireGlobalFeatures(typeof(CommentsFeature));
contentGroup.AddChild(CmsKitAdminPermissions.Comments.Update, L("Permission:Comments.Update"))
.RequireGlobalFeatures(typeof(CommentsFeature));
var tagGroup = cmsGroup.AddPermission(CmsKitAdminPermissions.Tags.Default, L("Permission:TagManagement")) var tagGroup = cmsGroup.AddPermission(CmsKitAdminPermissions.Tags.Default, L("Permission:TagManagement"))
.RequireGlobalFeatures(typeof(TagsFeature)); .RequireGlobalFeatures(typeof(TagsFeature));

1
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs

@ -8,6 +8,7 @@ public static class CmsKitAdminPermissions
{ {
public const string Default = GroupName + ".Comments"; public const string Default = GroupName + ".Comments";
public const string Delete = Default + ".Delete"; public const string Delete = Default + ".Delete";
public const string Update = Default + ".Update";
} }
public static class Tags public static class Tags

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

@ -38,8 +38,8 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Author, input.Author,
input.CreationStartDate, input.CreationStartDate,
input.CreationEndDate, input.CreationEndDate,
input.IsApproved input.commentApproveStateType
); );
var comments = await CommentRepository.GetListAsync( var comments = await CommentRepository.GetListAsync(
@ -52,8 +52,8 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Sorting, input.Sorting,
input.MaxResultCount, input.MaxResultCount,
input.SkipCount, input.SkipCount,
input.IsApproved input.commentApproveStateType
); );
var dtos = comments.Select(queryResultItem => var dtos = comments.Select(queryResultItem =>
{ {
@ -114,8 +114,8 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
} }
public async Task<int> GetPendingCommentCount() public async Task<int> GetPendingCommentCount()
{ {
var count = await CommentRepository.GetCountAsync(isApproved: "null"); var count = await CommentRepository.GetCountAsync(commentApproveStateType: CommentApproveStateType.Null);
return (int)(count == null ? 0 : count); return (int)(count);
} }
@ -128,7 +128,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Author, input.Author,
input.CreationStartDate, input.CreationStartDate,
input.CreationEndDate, input.CreationEndDate,
"null" CommentApproveStateType.Null
); );
@ -142,7 +142,7 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp
input.Sorting, input.Sorting,
input.MaxResultCount, input.MaxResultCount,
input.SkipCount, input.SkipCount,
"null" CommentApproveStateType.Null
); );
var dtos = comments.Select(queryResultItem => var dtos = comments.Select(queryResultItem =>

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

@ -51,13 +51,16 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
[HttpPost] [HttpPost]
[Route("{id}")] [Route("{id}")]
public Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto) [Authorize(CmsKitAdminPermissions.Comments.Update)]
public Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto commentApprovalDto)
{ {
return CommentAdminAppService.UpdateApprovalStatusAsync(id, commentApprovalDto); return CommentAdminAppService.UpdateApprovalStatusAsync(id, commentApprovalDto);
} }
[HttpPost] [HttpPost]
[Route("settings")] [Route("settings")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task SetSettings(SettingsDto settingsDto) public Task SetSettings(SettingsDto settingsDto)
{ {
return CommentAdminAppService.SetSettings(settingsDto); return CommentAdminAppService.SetSettings(settingsDto);
@ -65,21 +68,23 @@ public class CommentAdminController : CmsKitAdminController, ICommentAdminAppSer
[HttpGet] [HttpGet]
[Route("settings")] [Route("settings")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<SettingsDto> GetSettings() public Task<SettingsDto> GetSettings()
{ {
return CommentAdminAppService.GetSettings(); return CommentAdminAppService.GetSettings();
} }
[HttpGet] [HttpGet]
[Route("waiting-count")] [Route("waiting-count")]
public Task<int> GetPendingCommentCount() [Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<int> GetPendingCommentCount()
{ {
return CommentAdminAppService.GetPendingCommentCount(); return CommentAdminAppService.GetPendingCommentCount();
} }
[HttpGet] [HttpGet]
[Route("waiting")] [Route("waiting")]
[Authorize(CmsKitAdminPermissions.Comments.Default)]
public Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input) public Task<PagedResultDto<CommentWithAuthorDto>> GetWaitingCommentsWithRepliesAsync(CommentGetListInput input)
{ {
return CommentAdminAppService.GetWaitingCommentsWithRepliesAsync(input); return CommentAdminAppService.GetWaitingCommentsWithRepliesAsync(input);

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/CommentSettingViewComponent.cs

@ -1,8 +1,13 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Widgets;
namespace Volo.CmsKit.Admin.Web.Components.MySettingGroup; namespace Volo.CmsKit.Admin.Web.Components.MySettingGroup;
[Widget(
ScriptFiles = new[] { "/Components/CommentsSetting/index.js" }
)]
[ViewComponent(Name = "CmsKitCommentOptions")]
public class CommentSettingViewComponent: AbpViewComponent public class CommentSettingViewComponent: AbpViewComponent
{ {
public virtual IViewComponentResult Invoke() public virtual IViewComponentResult Invoke()

2
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Components/CommentsSetting/Index.cshtml

@ -10,7 +10,7 @@
<abp-script src="/client-proxies/cms-kit-admin-proxy.js" /> <abp-script src="/client-proxies/cms-kit-admin-proxy.js" />
<abp-script src="/client-proxies/cms-kit-common-proxy.js" /> <abp-script src="/client-proxies/cms-kit-common-proxy.js" />
@* <abp-script src="" /> *@ @* <abp-script src="" /> *@
<script src="/Components/CommentsSetting/index.js"></script> @* <script src="/Components/CommentsSetting/index.js"></script> *@
</abp-script-bundle> </abp-script-bundle>
} }
@{ @{

13
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml

@ -5,6 +5,7 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Layout @using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments @using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments
@using Volo.CmsKit.Admin.Web.Menus @using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Comments
@using Volo.CmsKit.Localization @using Volo.CmsKit.Localization
@inject IPageLayout PageLayout @inject IPageLayout PageLayout
@ -94,13 +95,13 @@
<abp-input asp-for="@Model.Author" label="@L["Username"].Value" type="text"/> <abp-input asp-for="@Model.Author" label="@L["Username"].Value" type="text"/>
</abp-column> </abp-column>
<abp-column size-lg="_2" size-md="_12"> <abp-column size-lg="_2" size-md="_12">
<div class="mb-3"> <div class="mb-3" id="isApprovedColumn">
<label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label> <label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label>
<select id="isApprovedSelect" asp-for="@Model.IsApproved" class="form-control"> <select id="isApprovedSelect" asp-for="@Model.commentApproveStateType" class="form-control">
<option value="">@L["CommentFilter:All"].Value</option> <option value="@CommentApproveStateType.All">@L["CommentFilter:All"].Value</option>
<option value="true">@L["CommentFilter:Approved"].Value</option> <option value="@CommentApproveStateType.True">@L["CommentFilter:Approved"].Value</option>
<option value="false">@L["CommentFilter:Disapproved"].Value</option> <option value="@CommentApproveStateType.False">@L["CommentFilter:Disapproved"].Value</option>
<option value="null">@L["CommentFilter:Waiting"].Value</option> <option value="@CommentApproveStateType.Null">@L["CommentFilter:Waiting"].Value</option>
</select> </select>
</div> </div>
</abp-column> </abp-column>

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Details.cshtml.cs

@ -2,6 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.CmsKit.Admin.Comments; using Volo.CmsKit.Admin.Comments;
using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments; namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments;
@ -15,7 +16,9 @@ public class DetailsModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; } public DateTime? CreationStartDate { get; set; }
public DateTime? CreationEndDate { get; set; } public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; } public CommentApproveStateType commentApproveStateType { get; set; }
//public string IsApproved { get; set; }
public CommentWithAuthorDto CommentWithAuthorDto { get; protected set; } public CommentWithAuthorDto CommentWithAuthorDto { get; protected set; }

13
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml

@ -4,6 +4,7 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Layout @using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments @using Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments
@using Volo.CmsKit.Admin.Web.Menus @using Volo.CmsKit.Admin.Web.Menus
@using Volo.CmsKit.Comments
@using Volo.CmsKit.Localization @using Volo.CmsKit.Localization
@inject IPageLayout PageLayout @inject IPageLayout PageLayout
@ -59,13 +60,13 @@
</abp-column> </abp-column>
<abp-column size-lg="_2" size-md="_6"> <abp-column size-lg="_2" size-md="_6">
<div class="mb-3"> <div class="mb-3" id="isApprovedColumn">
<label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label> <label class="mb-1" for="isApprovedSelect">@L["CommentFilter:ApproveState"].Value</label>
<select id="isApprovedSelect" asp-for="@Model.IsApproved" class="form-control"> <select id="isApprovedSelect" asp-for="@Model.commentApproveStateType" class="form-control">
<option value="">@L["CommentFilter:All"].Value</option> <option value="@CommentApproveStateType.All">@L["CommentFilter:All"].Value</option>
<option value="true">@L["CommentFilter:Approved"].Value</option> <option value="@CommentApproveStateType.True">@L["CommentFilter:Approved"].Value</option>
<option value="false">@L["CommentFilter:Disapproved"].Value</option> <option value="@CommentApproveStateType.False">@L["CommentFilter:Disapproved"].Value</option>
<option value="null">@L["CommentFilter:Waiting"].Value</option> <option value="@CommentApproveStateType.Null">@L["CommentFilter:Waiting"].Value</option>
</select> </select>
</div> </div>
</abp-column> </abp-column>

3
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs

@ -1,4 +1,5 @@
using System; using System;
using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments; namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments;
@ -11,6 +12,6 @@ public class IndexModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; } = null; public DateTime? CreationStartDate { get; set; } = null;
public DateTime? CreationEndDate { get; set; } public DateTime? CreationEndDate { get; set; }
public string IsApproved { get; set; } public CommentApproveStateType commentApproveStateType { get; set; }
} }

9
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js

@ -200,7 +200,14 @@ $(function (){
_dataTable.ajax.reloadEx(); _dataTable.ajax.reloadEx();
}); });
commentsService.getSettings().then(function (data) {
if (data.requireApprovement) {
$('#CommentsTable').DataTable().column(4).visible(true);
} else {
$('#CommentsTable').DataTable().column(4).visible(false);
$('#isApprovedColumn').hide();
}
})
filterForm.submit(function (e){ filterForm.submit(function (e){
e.preventDefault(); e.preventDefault();
_dataTable.ajax.reloadEx(); _dataTable.ajax.reloadEx();

5
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js

@ -236,11 +236,11 @@ $(function (){
e.preventDefault(); e.preventDefault();
_dataTable.ajax.reloadEx(); _dataTable.ajax.reloadEx();
}); });
// Get and display pending comment count // Get and display pending comment count
commentsService.getPendingCommentCount().then(function (count) { commentsService.getPendingCommentCount().then(function (count) {
console.log(count)
if (count > 0) { if (count > 0) {
var alertMessage = l("CommentAlertMessage") + count + ""; var alertMessage = l("CommentAlertMessage", count);
var alertElement = '<abp-alert alert-type="Warning">' + alertMessage + '</abp-alert>'; var alertElement = '<abp-alert alert-type="Warning">' + alertMessage + '</abp-alert>';
$('#commentsAlert').html(alertElement); $('#commentsAlert').html(alertElement);
$('#commentsAlert').show() $('#commentsAlert').show()
@ -256,6 +256,7 @@ $(function (){
$('#CommentsTable').DataTable().column(6).visible(true); $('#CommentsTable').DataTable().column(6).visible(true);
} else { } else {
$('#CommentsTable').DataTable().column(6).visible(false); $('#CommentsTable').DataTable().column(6).visible(false);
$('#isApprovedColumn').hide();
} }
}) })
}); });

3
modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.SettingManagement.Web.Pages.SettingManagement; using Volo.Abp.SettingManagement.Web.Pages.SettingManagement;
using Volo.CmsKit.Admin.Web.Components.MySettingGroup; using Volo.CmsKit.Admin.Web.Components.MySettingGroup;
using Volo.CmsKit.Localization; using Volo.CmsKit.Localization;
@ -9,7 +10,6 @@ namespace Volo.CmsKit.Admin.Web.Settings;
public class CommentSettingPageContributor : ISettingPageContributor public class CommentSettingPageContributor : ISettingPageContributor
{ {
public Task ConfigureAsync(SettingPageCreationContext context) public Task ConfigureAsync(SettingPageCreationContext context)
{ {
var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<CmsKitResource>>(); var l = context.ServiceProvider.GetRequiredService<IStringLocalizer<CmsKitResource>>();
@ -22,6 +22,7 @@ public class CommentSettingPageContributor : ISettingPageContributor
) )
); );
return Task.CompletedTask; return Task.CompletedTask;
} }

4
modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js

@ -176,7 +176,7 @@
volo.cmsKit.admin.comments.commentAdmin.getList = function(input, ajaxParams) { volo.cmsKit.admin.comments.commentAdmin.getList = function(input, ajaxParams) {
return abp.ajax($.extend(true, { return abp.ajax($.extend(true, {
url: abp.appPath + 'api/cms-kit-admin/comments' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'isApproved', value: input.isApproved }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '', url: abp.appPath + 'api/cms-kit-admin/comments' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'commentApproveStateType', value: input.commentApproveStateType }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
type: 'GET' type: 'GET'
}, ajaxParams)); }, ajaxParams));
}; };
@ -230,7 +230,7 @@
volo.cmsKit.admin.comments.commentAdmin.getWaitingCommentsWithReplies = function(input, ajaxParams) { volo.cmsKit.admin.comments.commentAdmin.getWaitingCommentsWithReplies = function(input, ajaxParams) {
return abp.ajax($.extend(true, { return abp.ajax($.extend(true, {
url: abp.appPath + 'api/cms-kit-admin/comments/waiting' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'isApproved', value: input.isApproved }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '', url: abp.appPath + 'api/cms-kit-admin/comments/waiting' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'commentApproveStateType', value: input.commentApproveStateType }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
type: 'GET' type: 'GET'
}, ajaxParams)); }, ajaxParams));
}; };

12
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.CmsKit.Comments;
public enum CommentApproveStateType
{
All,
True,
False,
Null
}

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -246,7 +246,7 @@
"Approve":"Approve", "Approve":"Approve",
"Disapproved":"Disapproved", "Disapproved":"Disapproved",
"CommentAlertMessage":"You have waiting comments: ", "CommentAlertMessage":"There are {0} comments waiting for approval",
"Menu:CmsKitCommentOptions":"CmsKit Comment Options" "Menu:CmsKitCommentOptions":"CmsKit Comment Options"
} }

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

@ -21,26 +21,26 @@ public interface ICommentRepository : IBasicRepository<Comment, Guid>
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<long> GetCountAsync( Task<long> GetCountAsync(
string text = null, string text = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
string isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType, [NotNull] string entityType,
[NotNull] string entityId, [NotNull] string entityId,
bool? isApproved, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task DeleteWithRepliesAsync( Task DeleteWithRepliesAsync(

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

@ -15,179 +15,189 @@ using Volo.CmsKit.Users;
namespace Volo.CmsKit.Comments; namespace Volo.CmsKit.Comments;
public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Comment, Guid>, public class EfCoreCommentRepository : EfCoreRepository<ICmsKitDbContext, Comment, Guid>,
ICommentRepository ICommentRepository
{ {
public EfCoreCommentRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) public EfCoreCommentRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
} }
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var query = from comment in (await GetDbSetAsync()) var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where id == comment.Id where id == comment.Id
select new CommentWithAuthorQueryResultItem select new CommentWithAuthorQueryResultItem
{ {
Comment = comment, Comment = comment,
Author = user Author = user
}; };
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (commentWithAuthor == null) if (commentWithAuthor == null)
{ {
throw new EntityNotFoundException(typeof(Comment), id); throw new EntityNotFoundException(typeof(Comment), id);
} }
return commentWithAuthor; return commentWithAuthor;
} }
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
bool? isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var token = GetCancellationToken(cancellationToken); var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync( var query = await GetListQueryAsync(
filter, filter,
entityType, entityType,
repliedCommentId, repliedCommentId,
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
isApproved, commentApproveStateType,
token); token);
if (!sorting.IsNullOrEmpty()) if (!sorting.IsNullOrEmpty())
{ {
sorting = "comment." + sorting; sorting = "comment." + sorting;
} }
query = query.OrderBy(sorting.IsNullOrEmpty() ? "comment.creationTime desc" : sorting) query = query.OrderBy(sorting.IsNullOrEmpty() ? "comment.creationTime desc" : sorting)
.PageBy(skipCount, maxResultCount); .PageBy(skipCount, maxResultCount);
return await query.ToListAsync(token); return await query.ToListAsync(token);
} }
public virtual async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
string text = null, string text = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
bool? isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
var token = GetCancellationToken(cancellationToken); var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync( var query = await GetListQueryAsync(
text, text,
entityType, entityType,
repliedCommentId, repliedCommentId,
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
isApproved, commentApproveStateType,
token); token);
return await query.LongCountAsync(token); return await query.LongCountAsync(token);
} }
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType, string entityType,
string entityId, string entityId,
bool ? isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var query = from comment in (await GetDbSetAsync()) var query = from comment in (await GetDbSetAsync())
join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id join user in (await GetDbContextAsync()).Set<CmsUser>() on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime orderby comment.CreationTime
select new CommentWithAuthorQueryResultItem select new CommentWithAuthorQueryResultItem
{ {
Comment = comment, Comment = comment,
Author = user Author = user
}; };
if (isApproved.HasValue) if (CommentApproveStateType.True == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == true);
}
else if (CommentApproveStateType.False == commentApproveStateType)
{ {
query = query.Where(c => c.Comment.IsApproved == isApproved.Value); query = query.Where(c => c.Comment.IsApproved == false);
}
else if (CommentApproveStateType.Null == commentApproveStateType)
{
query = query.Where(c => c.Comment.IsApproved == null);
} }
return await query.ToListAsync(GetCancellationToken(cancellationToken)); return await query.ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task DeleteWithRepliesAsync( public virtual async Task DeleteWithRepliesAsync(
Comment comment, Comment comment,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var replies = await (await GetDbSetAsync()) var replies = await (await GetDbSetAsync())
.Where(x => x.RepliedCommentId == comment.Id) .Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
foreach (var reply in replies) foreach (var reply in replies)
{ {
await DeleteAsync( await DeleteAsync(
reply, reply,
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); );
} }
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken)); await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken)); return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
} }
protected virtual async Task<IQueryable<CommentWithAuthorQueryResultItem>> GetListQueryAsync( protected virtual async Task<IQueryable<CommentWithAuthorQueryResultItem>> GetListQueryAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
bool? isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default
CancellationToken cancellationToken = default
)
) {
{ var commentDbSet = await GetDbSetAsync();
var commentDbSet = await GetDbSetAsync(); var cmsUserSet = (await GetDbContextAsync()).Set<CmsUser>();
var cmsUserSet = (await GetDbContextAsync()).Set<CmsUser>();
var query = from comment in commentDbSet
var query = from comment in commentDbSet join user in cmsUserSet
join user in cmsUserSet on comment.CreatorId equals user.Id
on comment.CreatorId equals user.Id select new CommentWithAuthorQueryResultItem
select new CommentWithAuthorQueryResultItem {
{ Comment = comment,
Comment = comment, Author = user
Author = user };
};
return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter))
return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter)) .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType))
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType)) .WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId)
.WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId) .WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername))
.WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername)) .WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
.WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate) .WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate)
.WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate) .WhereIf(CommentApproveStateType.True == commentApproveStateType, c => c.Comment.IsApproved == true)
.WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved); .WhereIf(CommentApproveStateType.False == commentApproveStateType, c => c.Comment.IsApproved == false)
} .WhereIf(CommentApproveStateType.Null == commentApproveStateType, c => c.Comment.IsApproved == null);
//.WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved);
}
} }

454
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -16,231 +16,231 @@ namespace Volo.CmsKit.MongoDB.Comments;
public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, Comment, Guid>, ICommentRepository public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, Comment, Guid>, ICommentRepository
{ {
public MongoCommentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) public MongoCommentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider)
{ {
} }
public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default) public virtual async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
{ {
var comment = await GetAsync(id); var comment = await GetAsync(id);
var author = await (await GetDbContextAsync()) var author = await (await GetDbContextAsync())
.CmsUsers .CmsUsers
.AsQueryable() .AsQueryable()
.FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken)); .FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken));
return new CommentWithAuthorQueryResultItem() return new CommentWithAuthorQueryResultItem()
{ {
Comment = comment, Comment = comment,
Author = author Author = author
}; };
} }
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(
string filter = null, string filter = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
//bool? isApprovedValue = ParseIsApproved(isApproved); //bool? isApprovedValue = ParseIsApproved(isApproved);
var token = GetCancellationToken(cancellationToken); var token = GetCancellationToken(cancellationToken);
var query = await GetListQueryAsync( var query = await GetListQueryAsync(
filter, filter,
entityType, entityType,
repliedCommentId, repliedCommentId,
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
isApproved, commentApproveStateType,
token); token);
var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting) var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
.As<IMongoQueryable<Comment>>() .As<IMongoQueryable<Comment>>()
.PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount) .PageBy<Comment, IMongoQueryable<Comment>>(skipCount, maxResultCount)
.ToListAsync(token); .ToListAsync(token);
var commentIds = comments.Select(x => x.Id).ToList(); var commentIds = comments.Select(x => x.Id).ToList();
var authorsQuery = from comment in (await GetMongoQueryableAsync(token)) var authorsQuery = from comment in (await GetMongoQueryableAsync(token))
join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
where commentIds.Contains(comment.Id) where commentIds.Contains(comment.Id)
orderby comment.CreationTime orderby comment.CreationTime
select user; select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token); var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(token);
return comments return comments
.Select( .Select(
comment => comment =>
new CommentWithAuthorQueryResultItem new CommentWithAuthorQueryResultItem
{ {
Comment = comment, Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId) Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList(); }).ToList();
} }
public virtual async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
string text = null, string text = null,
string entityType = null, string entityType = null,
Guid? repliedCommentId = null, Guid? repliedCommentId = null,
string authorUsername = null, string authorUsername = null,
DateTime? creationStartDate = null, DateTime? creationStartDate = null,
DateTime? creationEndDate = null, DateTime? creationEndDate = null,
string isApproved = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
//bool? isApprovedValue = ParseIsApproved(isApproved); //bool? isApprovedValue = ParseIsApproved(isApproved);
var query = await GetListQueryAsync( var query = await GetListQueryAsync(
text, text,
entityType, entityType,
repliedCommentId, repliedCommentId,
authorUsername, authorUsername,
creationStartDate, creationStartDate,
creationEndDate, creationEndDate,
isApproved, commentApproveStateType,
cancellationToken); cancellationToken);
return await query.As<IMongoQueryable<Comment>>() return await query.As<IMongoQueryable<Comment>>()
.LongCountAsync(GetCancellationToken(cancellationToken)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync( public virtual async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType, string entityType,
string entityId, string entityId,
bool? isApproved, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken)) var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken))
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime orderby comment.CreationTime
select user; select user;
var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken)); var authors = await ApplyDataFilters<IMongoQueryable<CmsUser>, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
var commentsQuery = (await GetMongoQueryableAsync(cancellationToken)) var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
.Where(c => c.EntityId == entityId && c.EntityType == entityType); .Where(c => c.EntityId == entityId && c.EntityType == entityType);
commentsQuery = isApproved.Value ? commentsQuery = (IMongoQueryable<Comment>)FilterCommentsByApprovalState(commentsQuery, commentApproveStateType);
commentsQuery.Where(c => c.IsApproved == true) :
commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null); var comments = await commentsQuery
.OrderBy(c => c.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken));
var comments = await commentsQuery
.OrderBy(c => c.CreationTime) return comments
.ToListAsync(GetCancellationToken(cancellationToken)); .Select(
comment =>
return comments new CommentWithAuthorQueryResultItem
.Select( {
comment => Comment = comment,
new CommentWithAuthorQueryResultItem Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
{ }).ToList();
Comment = comment, }
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
}).ToList(); public virtual async Task DeleteWithRepliesAsync(
} Comment comment,
CancellationToken cancellationToken = default)
public virtual async Task DeleteWithRepliesAsync( {
Comment comment, var replies = await (await GetMongoQueryableAsync(cancellationToken))
CancellationToken cancellationToken = default) .Where(x => x.RepliedCommentId == comment.Id)
{ .ToListAsync(GetCancellationToken(cancellationToken));
var replies = await (await GetMongoQueryableAsync(cancellationToken))
.Where(x => x.RepliedCommentId == comment.Id) await base.DeleteAsync(
.ToListAsync(GetCancellationToken(cancellationToken)); comment,
cancellationToken: GetCancellationToken(cancellationToken)
await base.DeleteAsync( );
comment,
cancellationToken: GetCancellationToken(cancellationToken) foreach (var reply in replies)
); {
await base.DeleteAsync(
foreach (var reply in replies) reply,
{ cancellationToken: GetCancellationToken(cancellationToken)
await base.DeleteAsync( );
reply, }
cancellationToken: GetCancellationToken(cancellationToken) }
);
} public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
} {
return await (await GetMongoQueryableAsync(cancellationToken))
public virtual async Task<bool> ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default) .AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
{ }
return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken)); protected virtual async Task<IQueryable<Comment>> GetListQueryAsync(
} string filter = null,
string entityType = null,
protected virtual async Task<IQueryable<Comment>> GetListQueryAsync( Guid? repliedCommentId = null,
string filter = null, string authorUsername = null,
string entityType = null, DateTime? creationStartDate = null,
Guid? repliedCommentId = null, DateTime? creationEndDate = null,
string authorUsername = null, CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
DateTime? creationStartDate = null, CancellationToken cancellationToken = default
DateTime? creationEndDate = null, )
string isApproved = null, {
CancellationToken cancellationToken = default var queryable = await GetMongoQueryableAsync(cancellationToken);
)
{ if (!string.IsNullOrEmpty(authorUsername))
var queryable = await GetMongoQueryableAsync(cancellationToken); {
var author = await (await GetMongoQueryableAsync<CmsUser>(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
if (!string.IsNullOrEmpty(authorUsername))
{ var authorId = author?.Id ?? Guid.Empty;
var author = await (await GetMongoQueryableAsync<CmsUser>(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
queryable = queryable.Where(x => x.CreatorId == authorId);
var authorId = author?.Id ?? Guid.Empty; }
queryable = queryable.Where(x => x.CreatorId == authorId); queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
} .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter)) .WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
.WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType) .WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
.WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId) //.WhereIf(CommentApproveStateType.True == commentApproveStateType, c => c.IsApproved == true)
.WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate) //.WhereIf(CommentApproveStateType.False == commentApproveStateType, c => c.IsApproved == false)
.WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate); //.WhereIf(CommentApproveStateType.Null == commentApproveStateType, c => c.IsApproved == null);
if (!string.IsNullOrWhiteSpace(isApproved)) if (CommentApproveStateType.True == commentApproveStateType)
{ {
bool? isApprovedValue = ParseIsApproved(isApproved); queryable = queryable.Where(c => c.IsApproved == true);
if (isApprovedValue.HasValue) }
{ else if (CommentApproveStateType.False == commentApproveStateType)
queryable = queryable.Where(c => c.IsApproved == isApprovedValue); {
} queryable = queryable.Where(c => c.IsApproved == false);
else if (isApprovedValue == null)
{ }
queryable = queryable.Where(c => c.IsApproved == null); else if (CommentApproveStateType.Null == commentApproveStateType)
} {
queryable = queryable.Where(c => c.IsApproved == null);
} }
return queryable;
return queryable;
}
public static bool? ParseIsApproved(string isApproved) }
{
if (string.IsNullOrWhiteSpace(isApproved)) public IQueryable<Comment> FilterCommentsByApprovalState(IQueryable<Comment> commentsQuery, CommentApproveStateType approveState)
{ {
return null; switch (approveState)
} {
case CommentApproveStateType.True:
return isApproved.ToLower() switch commentsQuery = commentsQuery.Where(c => c.IsApproved == true);
{ break;
"true" => true, case CommentApproveStateType.False:
"false" => false, commentsQuery = commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null);
"null" => (bool?)null, break;
_ => null }
}; return commentsQuery;
} }
} }

4
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

@ -58,8 +58,10 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli
public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId) public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId)
{ {
string state = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement); string state = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement);
var commentsWithAuthor = bool.Parse(state) ?
await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.True) :
await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.False);
var commentsWithAuthor = await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, bool.Parse(state));
return new ListResultDto<CommentWithDetailsDto>( return new ListResultDto<CommentWithDetailsDto>(
ConvertCommentsToNestedStructure(commentsWithAuthor) ConvertCommentsToNestedStructure(commentsWithAuthor)

Loading…
Cancel
Save