|
|
@@ -79,6 +79,10 @@ public class CommentServiceImpl implements CommentService {
|
|
|
public void topComment(LoginUser user, Long commentId) {
|
|
|
Comment comment = commentDAO.findCommentById(commentId);
|
|
|
|
|
|
+ if (!comment.getShow()) {
|
|
|
+ throw HelperException.of(ExceptionType.FORBIDDEN, "私密评论,无法置顶");
|
|
|
+ }
|
|
|
+
|
|
|
if (!existsUpdateAuth(user, comment)) {
|
|
|
throw HelperException.of(ExceptionType.FORBIDDEN, "您无权在该评论区置顶评论");
|
|
|
}
|
|
|
@@ -117,12 +121,35 @@ public class CommentServiceImpl implements CommentService {
|
|
|
Comment comment = commentDAO.findCommentById(commentId);
|
|
|
|
|
|
if (!existsGetAuth(user, comment)) {
|
|
|
- throw HelperException.of(ExceptionType.FORBIDDEN, "您无权参考该评论");
|
|
|
+ throw HelperException.of(ExceptionType.FORBIDDEN, "您无权获取该评论");
|
|
|
}
|
|
|
|
|
|
return new CommentVO(comment);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(readOnly = true)
|
|
|
+ @Override
|
|
|
+ public Page<CommentVO> getSelfCommentsBySlideAndPageNumber(LoginUser user, Long slideId, Integer pageNumber, Boolean show, Pageable pageable) {
|
|
|
+ return commentDAO.findBySlideIdAndPageNumberAndUserAndShow(slideId, pageNumber, userDAO.findUserById(user.getId()), show, pageable).map(CommentVO::new);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void modifyCommentShow(LoginUser user, Long commentId, Boolean show) {
|
|
|
+ Comment comment = commentDAO.findCommentById(commentId);
|
|
|
+
|
|
|
+ if (comment.getShow().equals(show)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!existsUpdateAuth(user, comment)) {
|
|
|
+ throw HelperException.of(ExceptionType.FORBIDDEN, "您无权修改该评论的展示状态");
|
|
|
+ }
|
|
|
+
|
|
|
+ unTopComment(comment);
|
|
|
+ commentDAO.save(comment.setShow(show));
|
|
|
+ }
|
|
|
+
|
|
|
private void unTopComment(Comment comment) {
|
|
|
Integer topNumber = comment.getTopNumber();
|
|
|
comment.setTopNumber(0);
|
|
|
@@ -130,7 +157,7 @@ public class CommentServiceImpl implements CommentService {
|
|
|
commentDAO.saveAll(
|
|
|
commentDAO.findBySlideIdAndPageNumberAndTopNumberGreaterThan(comment.getSlideId(), comment.getPageNumber(), topNumber)
|
|
|
.parallelStream()
|
|
|
- .peek(topComment -> topComment.setTopNumber(comment.getTopNumber() - 1))
|
|
|
+ .peek(topComment -> topComment.setTopNumber(topComment.getTopNumber() - 1))
|
|
|
.collect(Collectors.toList())
|
|
|
);
|
|
|
}
|
|
|
@@ -148,7 +175,8 @@ public class CommentServiceImpl implements CommentService {
|
|
|
|
|
|
@Override
|
|
|
public boolean existsUpdateAuth(LoginUser user, Comment comment) {
|
|
|
- return slideDAO.findSlideById(comment.getSlideId()).getTeacher().getId().equals(user.getId());
|
|
|
+ return comment.getUser().getId().equals(user.getId())
|
|
|
+ || slideDAO.findSlideById(comment.getSlideId()).getTeacher().getId().equals(user.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|