Browse Source

Pass the entity, not id to delete it.

pull/5067/head
Halil İbrahim Kalkan 6 years ago
parent
commit
1e93a4474c
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  2. 11
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  3. 8
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  4. 5
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs
  5. 3
      modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs

@ -16,7 +16,7 @@ namespace Volo.CmsKit.Comments
);
Task DeleteWithRepliesAsync(
Guid id,
Comment comment,
CancellationToken cancellationToken = default
);
}

11
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -42,23 +42,22 @@ namespace Volo.CmsKit.Comments
}
public async Task DeleteWithRepliesAsync(
Guid id,
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await DbSet
.Where(x => x.RepliedCommentId == id)
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var reply in replies)
{
//TODO: Discuss if it is better to mark it as deleted and show in the ui as "This is deleted" instead of deleting it and replies completely
await base.DeleteAsync(
reply.Id,
await DeleteAsync(
reply,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
await base.DeleteAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
}
}
}

8
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -50,11 +50,11 @@ namespace Volo.CmsKit.MongoDB.Comments
}
public async Task DeleteWithRepliesAsync(
Guid id,
CancellationToken cancellationToken = default)
Comment comment,
CancellationToken cancellationToken = default)
{
var replies = await GetMongoQueryable()
.Where(x => x.RepliedCommentId == id)
.Where(x => x.RepliedCommentId == comment.Id)
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var reply in replies)
@ -66,7 +66,7 @@ namespace Volo.CmsKit.MongoDB.Comments
);
}
await base.DeleteAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
await base.DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
}
}
}

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

@ -7,8 +7,6 @@ using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Authorization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Users;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Users;
@ -84,13 +82,12 @@ 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();
}
await CommentRepository.DeleteWithRepliesAsync(id);
await CommentRepository.DeleteWithRepliesAsync(comment);
}
private List<CommentWithDetailsDto> ConvertCommentsToNestedStructure(List<CommentWithAuthorQueryResultItem> comments)

3
modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs

@ -32,7 +32,8 @@ namespace Volo.CmsKit.Comments
[Fact]
public async Task DeleteWithRepliesAsync()
{
await _commentRepository.DeleteWithRepliesAsync(_cmsKitTestData.CommentWithChildId);
var comment = await _commentRepository.GetAsync(_cmsKitTestData.CommentWithChildId);
await _commentRepository.DeleteWithRepliesAsync(comment);
var list = await _commentRepository.GetListAsync();

Loading…
Cancel
Save