improvements + bookmarks
This commit is contained in:
@@ -22,28 +22,34 @@ import de.bstly.board.repository.CommentRepository;
|
||||
import de.bstly.board.repository.VoteRepository;
|
||||
|
||||
/**
|
||||
* @author Lurkars
|
||||
*
|
||||
* The Class CommentManager.
|
||||
*/
|
||||
@Component
|
||||
public class CommentManager {
|
||||
|
||||
@Autowired
|
||||
private CommentRepository commentRepository;
|
||||
|
||||
@Autowired
|
||||
private VoteRepository voteRepository;
|
||||
|
||||
@Autowired
|
||||
private VoteManager voteManager;
|
||||
|
||||
private QComment qComment = QComment.comment;
|
||||
|
||||
private QVote qVote = QVote.vote;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parent
|
||||
* @param target
|
||||
* @param page
|
||||
* @param size
|
||||
* @return
|
||||
* Fetch by ranking.
|
||||
*
|
||||
* @param target the target
|
||||
* @param parent the parent
|
||||
* @param date the date
|
||||
* @param gravity the gravity
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @return the page
|
||||
*/
|
||||
|
||||
public Page<Comment> fetchByRanking(Long target, Long parent, Instant date, double gravity,
|
||||
@@ -58,11 +64,14 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page
|
||||
* @param size
|
||||
* @param order
|
||||
* @return
|
||||
* Fetch by date.
|
||||
*
|
||||
* @param target the target
|
||||
* @param parent the parent
|
||||
* @param date the date
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @return the page
|
||||
*/
|
||||
public Page<Comment> fetchByDate(Long target, Long parent, Instant date, int page, int size) {
|
||||
if (parent == null) {
|
||||
@@ -79,10 +88,11 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @param parent
|
||||
* @return
|
||||
* Count.
|
||||
*
|
||||
* @param target the target
|
||||
* @param parent the parent
|
||||
* @return the long
|
||||
*/
|
||||
public Long count(Long target, Long parent) {
|
||||
if (parent == null) {
|
||||
@@ -93,18 +103,20 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
* Count.
|
||||
*
|
||||
* @param target the target
|
||||
* @return the long
|
||||
*/
|
||||
public Long count(Long target) {
|
||||
return commentRepository.count(qComment.target.eq(target));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param username
|
||||
* @param comment
|
||||
* Apply metadata.
|
||||
*
|
||||
* @param username the username
|
||||
* @param comment the comment
|
||||
*/
|
||||
public void applyMetadata(String username, Comment comment) {
|
||||
if (!comment.getMetadata().containsKey("comments")) {
|
||||
@@ -114,21 +126,21 @@ public class CommentManager {
|
||||
comment.getMetadata().put("points",
|
||||
voteManager.getPoints(comment.getId(), Types.comment));
|
||||
}
|
||||
|
||||
|
||||
if (!comment.getMetadata().containsKey("upvoted")) {
|
||||
comment.getMetadata().put("upvoted",
|
||||
voteRepository.exists(qVote.target.eq(comment.getId())
|
||||
.and(qVote.targetType.eq(Types.comment)).and(qVote.type.eq(VoteType.up))
|
||||
.and(qVote.author.eq(username))));
|
||||
}
|
||||
|
||||
|
||||
if (!comment.getMetadata().containsKey("downvoted")) {
|
||||
comment.getMetadata().put("downvoted",
|
||||
voteRepository.exists(qVote.target.eq(comment.getId())
|
||||
.and(qVote.targetType.eq(Types.comment))
|
||||
.and(qVote.type.eq(VoteType.down)).and(qVote.author.eq(username))));
|
||||
}
|
||||
|
||||
|
||||
if (!comment.getMetadata().containsKey("unvote")) {
|
||||
comment.getMetadata().put("unvote",
|
||||
voteRepository.exists(
|
||||
@@ -138,8 +150,10 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param entries
|
||||
* Apply metadata.
|
||||
*
|
||||
* @param username the username
|
||||
* @param entries the entries
|
||||
*/
|
||||
public void applyMetadata(String username, List<Comment> entries) {
|
||||
for (Comment comment : entries) {
|
||||
@@ -148,33 +162,40 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
* Exists.
|
||||
*
|
||||
* @param id the id
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean exists(Long id) {
|
||||
return commentRepository.existsById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
* Gets the.
|
||||
*
|
||||
* @param id the id
|
||||
* @return the comment
|
||||
*/
|
||||
public Comment get(Long id) {
|
||||
return commentRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param comment
|
||||
* @return
|
||||
* Save.
|
||||
*
|
||||
* @param comment the comment
|
||||
* @return the comment
|
||||
*/
|
||||
public Comment save(Comment comment) {
|
||||
return commentRepository.save(comment);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param commentId
|
||||
* @return
|
||||
* Gets the points.
|
||||
*
|
||||
* @param commentId the comment id
|
||||
* @return the points
|
||||
*/
|
||||
public long getPoints(Long commentId) {
|
||||
long upvotes = voteRepository.count(qVote.targetType.eq(Types.comment)
|
||||
@@ -185,8 +206,9 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param comment
|
||||
* Delete.
|
||||
*
|
||||
* @param comment the comment
|
||||
*/
|
||||
public void delete(Comment comment) {
|
||||
for (Comment subcomment : commentRepository.findAll(qComment.parent.eq(comment.getId()))) {
|
||||
@@ -199,8 +221,9 @@ public class CommentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param target
|
||||
* Delete by target.
|
||||
*
|
||||
* @param target the target
|
||||
*/
|
||||
public void deleteByTarget(Long target) {
|
||||
for (Comment comment : commentRepository.findAll(qComment.target.eq(target))) {
|
||||
|
||||
Reference in New Issue
Block a user