Browse Source

Refactor and add notes.

pull/5067/head
Halil İbrahim Kalkan 6 years ago
parent
commit
ce3b8178e5
  1. 4
      modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Controllers/CmsKitControllerBase.cs
  2. 33
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs
  3. 1
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/CmsKitPublicControllerBase.cs
  4. 1
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs

4
modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Controllers/CmsKitControllerBase.cs

@ -3,9 +3,9 @@ using Volo.CmsKit.Localization;
namespace Volo.CmsKit.Controllers namespace Volo.CmsKit.Controllers
{ {
public class CmsKitControllerBase : AbpController public abstract class CmsKitControllerBase : AbpController
{ {
public CmsKitControllerBase() protected CmsKitControllerBase()
{ {
LocalizationResource = typeof(CmsKitResource); LocalizationResource = typeof(CmsKitResource);
} }

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

@ -31,11 +31,12 @@ namespace Volo.CmsKit.Public.Comments
public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId) public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId)
{ {
var commentsWithAuthor = await CommentRepository.GetListWithAuthorsAsync(entityType, entityId); var commentsWithAuthor = await CommentRepository
.GetListWithAuthorsAsync(entityType, entityId);
return new ListResultDto<CommentWithDetailsDto>( return new ListResultDto<CommentWithDetailsDto>(
ConvertCommentsToNestedStructure(commentsWithAuthor) ConvertCommentsToNestedStructure(commentsWithAuthor)
); );
} }
[Authorize] [Authorize]
@ -45,18 +46,21 @@ namespace Volo.CmsKit.Public.Comments
if (user == null) if (user == null)
{ {
//TODO: Localize
throw new BusinessException(message: "User Not found!"); throw new BusinessException(message: "User Not found!");
} }
var comment = await CommentRepository.InsertAsync(new Comment( var comment = await CommentRepository.InsertAsync(
GuidGenerator.Create(), new Comment(
input.EntityType, GuidGenerator.Create(),
input.EntityId, input.EntityType,
input.Text, input.EntityId,
input.RepliedCommentId, input.Text,
user.Id, input.RepliedCommentId,
CurrentTenant.Id user.Id,
)); CurrentTenant.Id
)
);
return ObjectMapper.Map<Comment, CommentDto>(comment); return ObjectMapper.Map<Comment, CommentDto>(comment);
} }
@ -68,7 +72,7 @@ namespace Volo.CmsKit.Public.Comments
if (comment.CreatorId != CurrentUser.GetId()) if (comment.CreatorId != CurrentUser.GetId())
{ {
throw new BusinessException(); throw new BusinessException(); //TODO: AbpAuthorizationException!
} }
comment.SetText(input.Text); comment.SetText(input.Text);
@ -82,9 +86,10 @@ namespace Volo.CmsKit.Public.Comments
public virtual async Task DeleteAsync(Guid id) public virtual async Task DeleteAsync(Guid id)
{ {
var comment = await CommentRepository.GetAsync(id); var comment = await CommentRepository.GetAsync(id);
if (comment.CreatorId != CurrentUser.GetId()) if (comment.CreatorId != CurrentUser.GetId())
{ {
throw new BusinessException(); throw new BusinessException(); //TODO: AbpAuthorizationException!
} }
await CommentRepository.DeleteWithRepliesAsync(comment); await CommentRepository.DeleteWithRepliesAsync(comment);
@ -92,6 +97,8 @@ namespace Volo.CmsKit.Public.Comments
private List<CommentWithDetailsDto> ConvertCommentsToNestedStructure(List<CommentWithAuthorQueryResultItem> comments) private List<CommentWithDetailsDto> ConvertCommentsToNestedStructure(List<CommentWithAuthorQueryResultItem> comments)
{ {
//TODO: I think this method can be optimized if you use dictionaries instead of straight search
var parentComments = comments var parentComments = comments
.Where(c=> c.Comment.RepliedCommentId == null) .Where(c=> c.Comment.RepliedCommentId == null)
.Select(c=> ObjectMapper.Map<Comment, CommentWithDetailsDto>(c.Comment)) .Select(c=> ObjectMapper.Map<Comment, CommentWithDetailsDto>(c.Comment))

1
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/CmsKitPublicControllerBase.cs

@ -4,5 +4,6 @@ namespace Volo.CmsKit.Public
{ {
public abstract class CmsKitPublicControllerBase : CmsKitControllerBase public abstract class CmsKitPublicControllerBase : CmsKitControllerBase
{ {
} }
} }

1
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Comments/CommentPublicController.cs

@ -38,6 +38,7 @@ namespace Volo.CmsKit.Public.Comments
return CommentPublicAppService.UpdateAsync(id, input); return CommentPublicAppService.UpdateAsync(id, input);
} }
//TODO: Route seems incorrect! Should be "{id}" ?
[HttpDelete] [HttpDelete]
[Route("update")] [Route("update")]
public Task DeleteAsync(Guid id) public Task DeleteAsync(Guid id)

Loading…
Cancel
Save