fixes+improvements

This commit is contained in:
2021-10-03 20:23:26 +02:00
parent 0842b1dfb8
commit 6d6f21d4f2
5 changed files with 155 additions and 18 deletions
@@ -182,4 +182,28 @@ public class CommentManager {
return upvotes - downvotes;
}
/**
*
* @param comment
*/
public void delete(Comment comment) {
for (Comment subcomment : commentRepository.findAll(qComment.parent.eq(comment.getId()))) {
delete(subcomment);
}
voteManager.deleteByTarget(comment.getId(), Types.comment);
commentRepository.delete(comment);
}
/**
*
* @param target
*/
public void deleteByTarget(Long target) {
for (Comment comment : commentRepository.findAll(qComment.target.eq(target))) {
delete(comment);
}
}
}
@@ -142,6 +142,16 @@ public class EntryManager {
return entryRepository.save(entry);
}
/**
*
* @param entry
*/
public void delete(Entry entry) {
commentManager.deleteByTarget(entry.getId());
voteManager.deleteByTarget(entry.getId(), Types.entry);
entryRepository.delete(entry);
}
/**
*
* @param entryId
@@ -52,6 +52,17 @@ public class VoteManager {
voteRepository.delete(vote);
}
/**
*
* @param vote
*/
public void deleteByTarget(Long target, Types targetType) {
for (Vote vote : voteRepository
.findAll(qVote.target.eq(target).and(qVote.targetType.eq(targetType)))) {
delete(vote);
}
}
/**
*
* @param target