Browse Source

Revise the CMS Kit REST API

pull/5163/head
Halil İbrahim Kalkan 6 years ago
parent
commit
5e8f39f7bb
  1. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreateCommentInput.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/ICommentPublicAppService.cs
  3. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/CreateReactionDto.cs
  4. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/DeleteReactionDto.cs
  5. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/IReactionPublicAppService.cs
  6. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs
  7. 16
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs
  8. 10
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs
  9. 10
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Reactions/ReactionPublicController.cs
  10. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/CommentingViewComponent.cs
  11. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js
  12. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/ReactionSelection/default.js

8
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; }

2
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<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId);
Task<CommentDto> CreateAsync(CreateCommentInput input);
Task<CommentDto> CreateAsync(string entityType, string entityId, CreateCommentInput input);
Task<CommentDto> UpdateAsync(Guid id, UpdateCommentInput input);

11
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/CreateReactionDto.cs

@ -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; }
}
}

11
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Reactions/DeleteReactionDto.cs

@ -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; }
}
}

4
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<ListResultDto<ReactionWithSelectionDto>> 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);
}
}

6
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<CommentDto> CreateAsync(CreateCommentInput input)
public virtual async Task<CommentDto> 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,

16
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
);
}

10
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<CommentDto> CreateAsync(CreateCommentInput input)
[Route("{entityType}/{entityId}")]
public Task<CommentDto> CreateAsync(string entityType, string entityId, CreateCommentInput input)
{
return CommentPublicAppService.CreateAsync(input);
return CommentPublicAppService.CreateAsync(entityType, entityId, input);
}
[HttpPost]
[HttpPut]
[Route("{id}")]
public Task<CommentDto> 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);

10
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);
}
}
}

2
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<AbpMvcUiOptions> options)

6
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);
});

6
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);

Loading…
Cancel
Save