|
|
@@ -0,0 +1,56 @@
|
|
|
+package nju.seec.helper.service.impl;
|
|
|
+
|
|
|
+import nju.seec.helper.dao.CommentDAO;
|
|
|
+import nju.seec.helper.dao.ReplyDAO;
|
|
|
+import nju.seec.helper.dao.SlideDAO;
|
|
|
+import nju.seec.helper.dto.LoginUser;
|
|
|
+import nju.seec.helper.dto.ReplyDTO;
|
|
|
+import nju.seec.helper.entity.Comment;
|
|
|
+import nju.seec.helper.entity.Reply;
|
|
|
+import nju.seec.helper.service.ReplyService;
|
|
|
+import nju.seec.helper.util.exception.HelperException;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author cst
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ReplyServiceImpl implements ReplyService {
|
|
|
+ private final SlideDAO slideDAO;
|
|
|
+ private final CommentDAO commentDAO;
|
|
|
+ private final ReplyDAO replyDAO;
|
|
|
+
|
|
|
+ public ReplyServiceImpl(SlideDAO slideDAO, CommentDAO commentDAO, ReplyDAO replyDAO) {
|
|
|
+ this.slideDAO = slideDAO;
|
|
|
+ this.commentDAO = commentDAO;
|
|
|
+ this.replyDAO = replyDAO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void createReply(LoginUser user, ReplyDTO replyDTO) {
|
|
|
+ Comment comment = commentDAO.findCommentById(replyDTO.getCommentId());
|
|
|
+ if (!slideDAO.findSlideById(comment.getSlideId()).getTeacherId().equals(user.getId())) {
|
|
|
+ throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权回复该评论");
|
|
|
+ }
|
|
|
+
|
|
|
+ Reply reply = new Reply()
|
|
|
+ .setComment(comment)
|
|
|
+ .setTeacherId(user.getId())
|
|
|
+ .setContent(replyDTO.getContent());
|
|
|
+ comment.getReplies().add(reply);
|
|
|
+ commentDAO.save(comment);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void removeReply(LoginUser user, Integer replyId) {
|
|
|
+ Reply reply = replyDAO.findReplyById(replyId);
|
|
|
+ if (!reply.getTeacherId().equals(user.getId())) {
|
|
|
+ throw HelperException.of(HelperException.ExceptionType.FORBIDDEN, "您无权删除该回复");
|
|
|
+ }
|
|
|
+
|
|
|
+ replyDAO.deleteById(replyId);
|
|
|
+ }
|
|
|
+}
|