Refactor and add notes.

pull/5067/head
Halil İbrahim Kalkan 5 years ago
parent aad36a44b4
commit ce3b8178e5

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

@ -31,11 +31,12 @@ namespace Volo.CmsKit.Public.Comments
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>(
ConvertCommentsToNestedStructure(commentsWithAuthor)
);
);
}
[Authorize]
@ -45,18 +46,21 @@ namespace Volo.CmsKit.Public.Comments
if (user == null)
{
//TODO: Localize
throw new BusinessException(message: "User Not found!");
}
var comment = await CommentRepository.InsertAsync(new Comment(
GuidGenerator.Create(),
input.EntityType,
input.EntityId,
input.Text,
input.RepliedCommentId,
user.Id,
CurrentTenant.Id
));
var comment = await CommentRepository.InsertAsync(
new Comment(
GuidGenerator.Create(),
input.EntityType,
input.EntityId,
input.Text,
input.RepliedCommentId,
user.Id,
CurrentTenant.Id
)
);
return ObjectMapper.Map<Comment, CommentDto>(comment);
}
@ -68,7 +72,7 @@ namespace Volo.CmsKit.Public.Comments
if (comment.CreatorId != CurrentUser.GetId())
{
throw new BusinessException();
throw new BusinessException(); //TODO: AbpAuthorizationException!
}
comment.SetText(input.Text);
@ -82,9 +86,10 @@ namespace Volo.CmsKit.Public.Comments
public virtual async Task DeleteAsync(Guid id)
{
var comment = await CommentRepository.GetAsync(id);
if (comment.CreatorId != CurrentUser.GetId())
{
throw new BusinessException();
throw new BusinessException(); //TODO: AbpAuthorizationException!
}
await CommentRepository.DeleteWithRepliesAsync(comment);
@ -92,6 +97,8 @@ namespace Volo.CmsKit.Public.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
.Where(c=> c.Comment.RepliedCommentId == null)
.Select(c=> ObjectMapper.Map<Comment, CommentWithDetailsDto>(c.Comment))

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

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

Loading…
Cancel
Save