|
@@ -1,5 +1,6 @@
|
|
|
package nju.seec.helper.service.impl;
|
|
package nju.seec.helper.service.impl;
|
|
|
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import nju.seec.helper.dao.CommentDAO;
|
|
import nju.seec.helper.dao.CommentDAO;
|
|
|
import nju.seec.helper.dao.ReplyDAO;
|
|
import nju.seec.helper.dao.ReplyDAO;
|
|
|
import nju.seec.helper.dao.SlideDAO;
|
|
import nju.seec.helper.dao.SlideDAO;
|
|
@@ -9,12 +10,14 @@ import nju.seec.helper.entity.Comment;
|
|
|
import nju.seec.helper.entity.Reply;
|
|
import nju.seec.helper.entity.Reply;
|
|
|
import nju.seec.helper.service.ReplyService;
|
|
import nju.seec.helper.service.ReplyService;
|
|
|
import nju.seec.helper.util.exception.HelperException;
|
|
import nju.seec.helper.util.exception.HelperException;
|
|
|
|
|
+import nju.seec.helper.vo.ReplyVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author cst
|
|
* @author cst
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class ReplyServiceImpl implements ReplyService {
|
|
public class ReplyServiceImpl implements ReplyService {
|
|
|
private final SlideDAO slideDAO;
|
|
private final SlideDAO slideDAO;
|
|
@@ -29,18 +32,22 @@ public class ReplyServiceImpl implements ReplyService {
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
@Override
|
|
|
- public void createReply(LoginUser user, ReplyDTO replyDTO) {
|
|
|
|
|
|
|
+ public ReplyVO createReply(LoginUser user, ReplyDTO replyDTO) {
|
|
|
Comment comment = commentDAO.findCommentById(replyDTO.getCommentId());
|
|
Comment comment = commentDAO.findCommentById(replyDTO.getCommentId());
|
|
|
if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
|
throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权回复该评论");
|
|
throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权回复该评论");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (comment.getReply() != null) {
|
|
|
|
|
+ throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您已回复该评论");
|
|
|
|
|
+ }
|
|
|
Reply reply = new Reply()
|
|
Reply reply = new Reply()
|
|
|
.setComment(comment)
|
|
.setComment(comment)
|
|
|
.setTeacherId(user.getId())
|
|
.setTeacherId(user.getId())
|
|
|
.setContent(replyDTO.getContent());
|
|
.setContent(replyDTO.getContent());
|
|
|
- comment.getReplies().add(reply);
|
|
|
|
|
- commentDAO.save(comment);
|
|
|
|
|
|
|
+ reply.setComment(comment);
|
|
|
|
|
+ reply = replyDAO.save(reply);
|
|
|
|
|
+ return new ReplyVO(reply);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -51,6 +58,8 @@ public class ReplyServiceImpl implements ReplyService {
|
|
|
throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权删除该回复");
|
|
throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权删除该回复");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- replyDAO.deleteById(replyId);
|
|
|
|
|
|
|
+ Comment comment = reply.getComment();
|
|
|
|
|
+ comment.setReply(null);
|
|
|
|
|
+ replyDAO.delete(reply);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|