|
|
@@ -1,7 +1,7 @@
|
|
|
package nju.seec.helper.service.impl;
|
|
|
|
|
|
import nju.seec.helper.dao.CommentDAO;
|
|
|
-import nju.seec.helper.dao.PageDAO;
|
|
|
+import nju.seec.helper.dao.SlideDAO;
|
|
|
import nju.seec.helper.dto.CommentDTO;
|
|
|
import nju.seec.helper.dto.LoginUser;
|
|
|
import nju.seec.helper.dto.ReplyDTO;
|
|
|
@@ -23,18 +23,19 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class CommentServiceImpl implements CommentService {
|
|
|
private final CommentDAO commentDAO;
|
|
|
- private final PageDAO pageDAO;
|
|
|
+ private final SlideDAO slideDAO;
|
|
|
|
|
|
- public CommentServiceImpl(CommentDAO commentDAO, PageDAO pageDAO) {
|
|
|
+ public CommentServiceImpl(CommentDAO commentDAO, SlideDAO slideDAO) {
|
|
|
this.commentDAO = commentDAO;
|
|
|
- this.pageDAO = pageDAO;
|
|
|
+ this.slideDAO = slideDAO;
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public CommentVO createComment(LoginUser user, CommentDTO commentDTO) {
|
|
|
Comment comment = new Comment();
|
|
|
- comment.setPageId(commentDTO.getPageId())
|
|
|
+ comment.setSlideId(commentDTO.getSlideId())
|
|
|
+ .setPageNumber(commentDTO.getPageNumber())
|
|
|
.setUserId(user.getId())
|
|
|
.setUserName(user.getName())
|
|
|
.setUserType(user.getType())
|
|
|
@@ -57,24 +58,22 @@ public class CommentServiceImpl implements CommentService {
|
|
|
@Override
|
|
|
public void topComment(LoginUser user, Integer commentId) {
|
|
|
Comment comment = commentDAO.findCommentById(commentId);
|
|
|
- if (comment.getTopNumber() == null) {
|
|
|
- if (!pageDAO.findPageById(comment.getPageId()).getTeacherId().equals(user.getId())) {
|
|
|
- throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权进行置顶操作");
|
|
|
- }
|
|
|
- Integer topCommentNum = commentDAO.countTopComments(comment.getPageId());
|
|
|
- if (topCommentNum == null) {
|
|
|
- topCommentNum = 0;
|
|
|
- }
|
|
|
- comment.setTopNumber(topCommentNum + 1);
|
|
|
- commentDAO.save(comment);
|
|
|
+ if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
|
+ throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权进行置顶操作");
|
|
|
}
|
|
|
+ Integer topCommentNum = commentDAO.countTopComments(comment.getSlideId(), comment.getPageNumber());
|
|
|
+ if (topCommentNum == null) {
|
|
|
+ topCommentNum = 0;
|
|
|
+ }
|
|
|
+ comment.setTopNumber(topCommentNum + 1);
|
|
|
+ commentDAO.save(comment);
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
@Override
|
|
|
- public List<CommentVO> getCommentsByType(Integer pageId, Pageable pageable) {
|
|
|
+ public List<CommentVO> getCommentsBySlideIdAndPageNumber(Integer slideId, Integer pageNumber, Pageable pageable) {
|
|
|
return commentDAO
|
|
|
- .findComments(pageId, pageable)
|
|
|
+ .findComments(slideId, pageNumber, pageable)
|
|
|
.getContent()
|
|
|
.stream()
|
|
|
.map(CommentVO::new)
|
|
|
@@ -85,7 +84,7 @@ public class CommentServiceImpl implements CommentService {
|
|
|
@Override
|
|
|
public void replyComment(LoginUser user, ReplyDTO replyDTO) {
|
|
|
Comment comment = commentDAO.findCommentById(replyDTO.getCommentId());
|
|
|
- if (!pageDAO.findPageById(comment.getPageId()).getTeacherId().equals(user.getId())) {
|
|
|
+ if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
|
throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权回复该评论");
|
|
|
}
|
|
|
|