From 5e8f39f7bbbf29c31f1df9ab4ea1c5b6ca519273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 15 Aug 2020 22:03:04 +0300 Subject: [PATCH] Revise the CMS Kit REST API --- .../CmsKit/Public/Comments/CreateCommentInput.cs | 8 -------- .../Public/Comments/ICommentPublicAppService.cs | 2 +- .../CmsKit/Public/Reactions/CreateReactionDto.cs | 11 ----------- .../CmsKit/Public/Reactions/DeleteReactionDto.cs | 11 ----------- .../Reactions/IReactionPublicAppService.cs | 4 ++-- .../Public/Comments/CommentPublicAppService.cs | 6 +++--- .../Public/Reactions/ReactionPublicAppService.cs | 16 ++++++++-------- .../Public/Comments/CommentPublicController.cs | 10 +++++----- .../Public/Reactions/ReactionPublicController.cs | 10 ++++++---- .../Commenting/CommentingViewComponent.cs | 2 +- .../Shared/Components/Commenting/default.js | 6 ++++-- .../Components/ReactionSelection/default.js | 6 +++--- 12 files changed, 33 insertions(+), 59 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/CreateReactionDto.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/DeleteReactionDto.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs index a0bcbfd6bd..c489721466 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs @@ -7,14 +7,6 @@ namespace Volo.CmsKit.Public.Comments { public class CreateCommentInput { - [Required] - [DynamicStringLength(typeof(CommentConsts), nameof(CommentConsts.MaxEntityTypeLength))] - public string EntityType { get; set; } - - [Required] - [DynamicStringLength(typeof(CommentConsts), nameof(CommentConsts.MaxEntityIdLength))] - public string EntityId { get; set; } - [Required] [DynamicStringLength(typeof(CommentConsts), nameof(CommentConsts.MaxTextLength))] public string Text { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/ICommentPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/ICommentPublicAppService.cs index 260b2646a5..8ac8c92988 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/ICommentPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/ICommentPublicAppService.cs @@ -9,7 +9,7 @@ namespace Volo.CmsKit.Public.Comments { Task> GetListAsync(string entityType, string entityId); - Task CreateAsync(CreateCommentInput input); + Task CreateAsync(string entityType, string entityId, CreateCommentInput input); Task UpdateAsync(Guid id, UpdateCommentInput input); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/CreateReactionDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/CreateReactionDto.cs deleted file mode 100644 index 8612ba6762..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/CreateReactionDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Volo.CmsKit.Public.Reactions -{ - public class CreateReactionDto - { - public string EntityType { get; set; } - - public string EntityId { get; set; } - - public string ReactionName { get; set; } - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/DeleteReactionDto.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/DeleteReactionDto.cs deleted file mode 100644 index 8ce4dd6808..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/DeleteReactionDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Volo.CmsKit.Public.Reactions -{ - public class DeleteReactionDto - { - public string EntityType { get; set; } - - public string EntityId { get; set; } - - public string ReactionName { get; set; } - } -} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/IReactionPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/IReactionPublicAppService.cs index 3058148afd..8a32d7cc11 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/IReactionPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/IReactionPublicAppService.cs @@ -8,8 +8,8 @@ namespace Volo.CmsKit.Public.Reactions { Task> GetForSelectionAsync(string entityType, string entityId); - Task CreateAsync(CreateReactionDto input); + Task CreateAsync(string entityType, string entityId, string reaction); - Task DeleteAsync(DeleteReactionDto input); + Task DeleteAsync(string entityType, string entityId, string reaction); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs index 07a6a22979..b003382b56 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs @@ -40,7 +40,7 @@ namespace Volo.CmsKit.Public.Comments } [Authorize] - public virtual async Task CreateAsync(CreateCommentInput input) + public virtual async Task CreateAsync(string entityType, string entityId, CreateCommentInput input) { var user = await CmsUserLookupService.FindByIdAsync(CurrentUser.GetId()); @@ -53,8 +53,8 @@ namespace Volo.CmsKit.Public.Comments var comment = await CommentRepository.InsertAsync( new Comment( GuidGenerator.Create(), - input.EntityType, - input.EntityId, + entityType, + entityId, input.Text, input.RepliedCommentId, user.Id, diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs index 54839bd161..44135d867e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs @@ -57,24 +57,24 @@ namespace Volo.CmsKit.Public.Reactions } [Authorize] - public virtual async Task CreateAsync(CreateReactionDto input) + public virtual async Task CreateAsync(string entityType, string entityId, string reaction) { await ReactionManager.CreateAsync( CurrentUser.GetId(), - input.EntityType, - input.EntityId, - input.ReactionName + entityType, + entityId, + reaction ); } [Authorize] - public virtual async Task DeleteAsync(DeleteReactionDto input) + public virtual async Task DeleteAsync(string entityType, string entityId, string reaction) { await ReactionManager.DeleteAsync( CurrentUser.GetId(), - input.EntityType, - input.EntityId, - input.ReactionName + entityType, + entityId, + reaction ); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs index d2dfbc83f4..b14dac1139 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs @@ -26,21 +26,21 @@ namespace Volo.CmsKit.Public.Comments } [HttpPost] - public Task CreateAsync(CreateCommentInput input) + [Route("{entityType}/{entityId}")] + public Task CreateAsync(string entityType, string entityId, CreateCommentInput input) { - return CommentPublicAppService.CreateAsync(input); + return CommentPublicAppService.CreateAsync(entityType, entityId, input); } - [HttpPost] + [HttpPut] [Route("{id}")] public Task UpdateAsync(Guid id, UpdateCommentInput input) { return CommentPublicAppService.UpdateAsync(id, input); } - //TODO: Route seems incorrect! Should be "{id}" ? [HttpDelete] - [Route("update")] + [Route("{id}")] public Task DeleteAsync(Guid id) { return CommentPublicAppService.DeleteAsync(id); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Reactions/ReactionPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Reactions/ReactionPublicController.cs index cbab4a649f..6b60890e4f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Reactions/ReactionPublicController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Reactions/ReactionPublicController.cs @@ -25,15 +25,17 @@ namespace Volo.CmsKit.Public.Reactions } [HttpPut] - public virtual Task CreateAsync(CreateReactionDto input) + [Route("{entityType}/{entityId}/{reaction}")] + public virtual Task CreateAsync(string entityType, string entityId, string reaction) { - return ReactionPublicAppService.CreateAsync(input); + return ReactionPublicAppService.CreateAsync(entityType, entityId, reaction); } [HttpDelete] - public virtual Task DeleteAsync(DeleteReactionDto input) + [Route("{entityType}/{entityId}/{reaction}")] + public virtual Task DeleteAsync(string entityType, string entityId, string reaction) { - return ReactionPublicAppService.DeleteAsync(input); + return ReactionPublicAppService.DeleteAsync(entityType, entityId, reaction); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs index 7053c65a29..e8d6e73e9a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs @@ -21,7 +21,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting { public ICommentPublicAppService CommentPublicAppService { get; } public AbpMvcUiOptions AbpMvcUiOptions { get; } - + public CommentingViewComponent( ICommentPublicAppService commentPublicAppService, IOptions options) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js index 4fb29abb51..2950f8239b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js @@ -122,10 +122,12 @@ e.preventDefault(); var formAsObject = $form.serializeFormToObject(); volo.cmsKit.public.comments.commentPublic.create( - $.extend(getFilters(), { + $commentArea.attr('data-entity-type'), + $commentArea.attr('data-entity-id'), + { repliedCommentId: formAsObject.repliedCommentId, text: formAsObject.commentText - }) + } ).then(function () { widgetManager.refresh($widget); }); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js index 38e5da93e5..3214d3af6b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js @@ -33,9 +33,9 @@ $icon.click(function () { var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; volo.cmsKit.public.reactions.reactionPublic[methodName]( - $.extend(getFilters(), { - reactionName: reactionName - }) + $reactionArea.attr('data-entity-type'), + $reactionArea.attr('data-entity-id'), + reactionName ).then(function () { $selectIcon.popover('hide'); widgetManager.refresh($widget);