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 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] [Required]
[DynamicStringLength(typeof(CommentConsts), nameof(CommentConsts.MaxTextLength))] [DynamicStringLength(typeof(CommentConsts), nameof(CommentConsts.MaxTextLength))]
public string Text { get; set; } 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<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); 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<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] [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()); var user = await CmsUserLookupService.FindByIdAsync(CurrentUser.GetId());
@ -53,8 +53,8 @@ namespace Volo.CmsKit.Public.Comments
var comment = await CommentRepository.InsertAsync( var comment = await CommentRepository.InsertAsync(
new Comment( new Comment(
GuidGenerator.Create(), GuidGenerator.Create(),
input.EntityType, entityType,
input.EntityId, entityId,
input.Text, input.Text,
input.RepliedCommentId, input.RepliedCommentId,
user.Id, 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] [Authorize]
public virtual async Task CreateAsync(CreateReactionDto input) public virtual async Task CreateAsync(string entityType, string entityId, string reaction)
{ {
await ReactionManager.CreateAsync( await ReactionManager.CreateAsync(
CurrentUser.GetId(), CurrentUser.GetId(),
input.EntityType, entityType,
input.EntityId, entityId,
input.ReactionName reaction
); );
} }
[Authorize] [Authorize]
public virtual async Task DeleteAsync(DeleteReactionDto input) public virtual async Task DeleteAsync(string entityType, string entityId, string reaction)
{ {
await ReactionManager.DeleteAsync( await ReactionManager.DeleteAsync(
CurrentUser.GetId(), CurrentUser.GetId(),
input.EntityType, entityType,
input.EntityId, entityId,
input.ReactionName 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] [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}")] [Route("{id}")]
public Task<CommentDto> UpdateAsync(Guid id, UpdateCommentInput input) public Task<CommentDto> UpdateAsync(Guid id, UpdateCommentInput input)
{ {
return CommentPublicAppService.UpdateAsync(id, input); return CommentPublicAppService.UpdateAsync(id, input);
} }
//TODO: Route seems incorrect! Should be "{id}" ?
[HttpDelete] [HttpDelete]
[Route("update")] [Route("{id}")]
public Task DeleteAsync(Guid id) public Task DeleteAsync(Guid id)
{ {
return CommentPublicAppService.DeleteAsync(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] [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] [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 ICommentPublicAppService CommentPublicAppService { get; }
public AbpMvcUiOptions AbpMvcUiOptions { get; } public AbpMvcUiOptions AbpMvcUiOptions { get; }
public CommentingViewComponent( public CommentingViewComponent(
ICommentPublicAppService commentPublicAppService, ICommentPublicAppService commentPublicAppService,
IOptions<AbpMvcUiOptions> options) 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(); e.preventDefault();
var formAsObject = $form.serializeFormToObject(); var formAsObject = $form.serializeFormToObject();
volo.cmsKit.public.comments.commentPublic.create( volo.cmsKit.public.comments.commentPublic.create(
$.extend(getFilters(), { $commentArea.attr('data-entity-type'),
$commentArea.attr('data-entity-id'),
{
repliedCommentId: formAsObject.repliedCommentId, repliedCommentId: formAsObject.repliedCommentId,
text: formAsObject.commentText text: formAsObject.commentText
}) }
).then(function () { ).then(function () {
widgetManager.refresh($widget); 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 () { $icon.click(function () {
var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create'; var methodName = $icon.hasClass('cms-reaction-icon-selected') ? 'delete' : 'create';
volo.cmsKit.public.reactions.reactionPublic[methodName]( volo.cmsKit.public.reactions.reactionPublic[methodName](
$.extend(getFilters(), { $reactionArea.attr('data-entity-type'),
reactionName: reactionName $reactionArea.attr('data-entity-id'),
}) reactionName
).then(function () { ).then(function () {
$selectIcon.popover('hide'); $selectIcon.popover('hide');
widgetManager.refresh($widget); widgetManager.refresh($widget);

Loading…
Cancel
Save