|
|
@@ -37,6 +37,7 @@ public class CommentServiceImpl implements CommentService {
|
|
|
.setUserId(user.getId())
|
|
|
.setUserName(user.getName())
|
|
|
.setUserType(user.getType())
|
|
|
+ .setTitle(commentDTO.getTitle())
|
|
|
.setContent(commentDTO.getContent());
|
|
|
comment = commentDAO.save(comment);
|
|
|
return new CommentVO(comment);
|
|
|
@@ -49,24 +50,45 @@ public class CommentServiceImpl implements CommentService {
|
|
|
if (!comment.getUserId().equals(user.getId())) {
|
|
|
throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权删除该评论");
|
|
|
}
|
|
|
- commentDAO.deleteById(commentId);
|
|
|
+ unTopComment(comment);
|
|
|
+ commentDAO.delete(comment);
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void topComment(LoginUser user, Integer commentId) {
|
|
|
Comment comment = commentDAO.findCommentById(commentId);
|
|
|
+
|
|
|
if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
|
- throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权进行置顶操作");
|
|
|
+ throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权在该评论区置顶评论");
|
|
|
}
|
|
|
- Integer topCommentNum = commentDAO.countTopComments(comment.getSlideId(), comment.getPageNumber());
|
|
|
- if (topCommentNum == null) {
|
|
|
- topCommentNum = 0;
|
|
|
+
|
|
|
+ unTopComment(comment);
|
|
|
+ comment.setTopNumber(commentDAO.countTopComments(comment.getSlideId(), comment.getPageNumber()) + 1);
|
|
|
+ commentDAO.save(comment);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void unTopComment(LoginUser user, Integer commentId) {
|
|
|
+ Comment comment = commentDAO.findCommentById(commentId);
|
|
|
+
|
|
|
+ if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
|
+ throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权在该评论区取消置顶评论");
|
|
|
}
|
|
|
- comment.setTopNumber(topCommentNum + 1);
|
|
|
+
|
|
|
+ unTopComment(comment);
|
|
|
commentDAO.save(comment);
|
|
|
}
|
|
|
|
|
|
+ private void unTopComment(Comment comment) {
|
|
|
+ Integer topNumber = comment.getTopNumber();
|
|
|
+ if (topNumber != null) {
|
|
|
+ comment.setTopNumber(null);
|
|
|
+ commentDAO.decTopNumber(comment.getSlideId(), comment.getPageNumber(), topNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(readOnly = true)
|
|
|
@Override
|
|
|
public List<CommentVO> getCommentsBySlideIdAndPageNumber(Integer slideId, Integer pageNumber, Pageable pageable) {
|