Commit 8b8b1bf9 by 胡学良

评论列表

parent 8328e4b2
package cn.meteor.beyondclouds.modules.question.api;
import cn.meteor.beyondclouds.common.form.PageForm;
import cn.meteor.beyondclouds.common.vo.PageVO;
import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.bean.Subject;
import cn.meteor.beyondclouds.modules.question.entity.QuestionReplyComment;
import cn.meteor.beyondclouds.modules.question.exception.QuestionReplyCommentServiceException;
import cn.meteor.beyondclouds.modules.question.form.QuestionReplyCommentForm;
import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyCommentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -73,4 +78,29 @@ public class QuestionReplyCommentApi {
return Response.error(e);
}
}
/**
* 评论列表
* @param replyId 回复ID
* @param pageForm 分页表单
* @param parentId 父评论ID
* @return 评论列表
*/
@Anonymous
@ApiOperation("评论列表")
@GetMapping("/question/reply/{replyId}/comments")
public Response<PageVO<QuestionReplyComment>> getReplyComments(@PathVariable("replyId") String replyId,
@Valid PageForm pageForm,
@RequestParam(value = "parentId", required = false) String parentId) {
try {
IPage<QuestionReplyComment> replyCommentPage = questionReplyCommentService.getReplyCommentPage(pageForm.getPage(), pageForm.getSize(), replyId, parentId);
PageVO<QuestionReplyComment> questionReplyCommentPageVO = new PageVO<>(replyCommentPage);
return Response.success(questionReplyCommentPageVO);
} catch (QuestionReplyCommentServiceException e) {
e.printStackTrace();
return Response.error(e);
}
}
}
......@@ -2,7 +2,9 @@ package cn.meteor.beyondclouds.modules.question.service;
import cn.meteor.beyondclouds.modules.question.entity.QuestionReplyComment;
import cn.meteor.beyondclouds.modules.question.exception.QuestionReplyCommentServiceException;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.models.auth.In;
/**
* <p>
......@@ -31,4 +33,15 @@ public interface IQuestionReplyCommentService extends IService<QuestionReplyComm
* @throws QuestionReplyCommentServiceException 问题回复评论业务异常
*/
void deleteReplyComment(String userId, String commentId) throws QuestionReplyCommentServiceException;
/**
* 评论列表
* @param pageNumber 页数
* @param pageSize 页面大小
* @param replyId 回复ID
* @param parentId 父评论ID
* @return 分页对象
* @throws QuestionReplyCommentServiceException
*/
IPage<QuestionReplyComment> getReplyCommentPage(Integer pageNumber, Integer pageSize, String replyId, String parentId) throws QuestionReplyCommentServiceException;
}
......@@ -10,13 +10,18 @@ import cn.meteor.beyondclouds.modules.question.mapper.QuestionReplyCommentMapper
import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyCommentService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionService;
import cn.meteor.beyondclouds.modules.question.util.QuestionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.nio.file.Watchable;
/**
* <p>
* 问题回复评论表 服务实现类
......@@ -121,4 +126,31 @@ public class QuestionReplyCommentServiceImpl extends ServiceImpl<QuestionReplyCo
questionReplyCommentQueryWrapper.like("thread",questionReplyComment.getThread());
remove(questionReplyCommentQueryWrapper);
}
@Override
public IPage<QuestionReplyComment> getReplyCommentPage(Integer pageNumber, Integer pageSize, String replyId, String parentId) throws QuestionReplyCommentServiceException {
Assert.notNull(replyId, "replyId must not be null");
IPage<QuestionReplyComment> page = new Page<>(pageNumber, pageSize);
//如果parentId为空,则只获取一级评论
if (null == parentId) {
QueryWrapper<QuestionReplyComment> questionReplyCommentQueryWrapper = new QueryWrapper<>();
questionReplyCommentQueryWrapper.eq("reply_id",replyId)
.eq("depth",0)
.orderByDesc("create_time");
return page(page, questionReplyCommentQueryWrapper);
}
//如果parentId不为null,则获取其子评论
//判断父评论是否存在
QuestionReplyComment questionReplyComment = getById(parentId);
if (null == questionReplyComment) {
throw new QuestionReplyCommentServiceException(QuestionReplyCommentErrorCode.PARENT_COMMENT_NOT_FOUND);
}
return page(page, QuestionUtils.getWrapper("parent_id",parentId));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment