Commit bebce5f3 by 胡学良

采纳回复

parent d59d9d2c
......@@ -21,6 +21,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
......@@ -216,8 +217,8 @@ public class QuestionApi {
@GetMapping("/my/question/participated")
public Response<PageVO<QuestionReply>> getMyParticipateQuestions(@Valid PageForm pageForm, @CurrentSubject Subject subject) {
//获取我的列表并返回
IPage<QuestionReply> userParticipateQuestionReplyPage = questionService.getUserParticipateQuestionReplyPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<QuestionReply> questionReplyPageVO = new PageVO<>(userParticipateQuestionReplyPage);
IPage<QuestionReply> myParticipateQuestionReplyPage = questionService.getUserParticipateQuestionReplyPage(pageForm.getPage(), pageForm.getSize(), (String) subject.getId());
PageVO<QuestionReply> questionReplyPageVO = new PageVO<>(myParticipateQuestionReplyPage);
return Response.success(questionReplyPageVO);
}
......@@ -237,5 +238,21 @@ public class QuestionApi {
return Response.success(questionPageVO);
}
/**
* 用户参与的问答列表
* @param pageForm 分页表单
* @param userId 用户ID
* @return 用户参与的问答列表
*/
@Anonymous
@ApiOperation("用户参与的问答列表")
@GetMapping("/user/{userId}/question/participated")
public Response<PageVO<QuestionReply>> getUserParticipateQuestions(@Valid PageForm pageForm, @PathVariable("userId") String userId) {
//获取用户参与的问答列表并返回
IPage<QuestionReply> userParticipateQuestionReplyPage = questionService.getUserParticipateQuestionReplyPage(pageForm.getPage(), pageForm.getSize(), userId);
PageVO<QuestionReply> questionReplyPageVO = new PageVO<>(userParticipateQuestionReplyPage);
return Response.success(questionReplyPageVO);
}
}
......@@ -8,10 +8,7 @@ import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @author 胡学良
......@@ -47,4 +44,23 @@ public class QuestionReply {
return Response.error(e);
}
}
/**
* 采纳回复
* @param questionId 问题ID
* @param replyId 回复ID
* @param userId 发布问题用户ID
* @return default
*/
@ApiOperation("采纳回复")
@PutMapping("/question/reply/{replyId}/adoption")
public Response adoptReply(String questionId, @PathVariable("replyId") String replyId, String userId) {
try {
questionReplyService.adoptReply(questionId, replyId, userId);
return Response.success();
} catch (QuestionReplyServiceException e) {
e.printStackTrace();
return Response.error(e);
}
}
}
......@@ -7,7 +7,14 @@ import cn.meteor.beyondclouds.core.IErrorCode;
* @since 2020/2/1
*/
public enum QuestionReplyErrorCode implements IErrorCode {
;
/**
* 回复不存在
*/
REPLY_NOT_FOUND(4001, "回复不存在"),
/**
* 回复已被采纳
*/
REPLY_ADOPTED(4002, "回复已被采纳");
private long code;
private String msg;
......@@ -19,11 +26,11 @@ public enum QuestionReplyErrorCode implements IErrorCode {
@Override
public long code() {
return 0;
return code;
}
@Override
public String msg() {
return null;
return msg;
}
}
......@@ -19,6 +19,16 @@ public interface IQuestionReplyService extends IService<QuestionReply> {
* @param questionId 问题ID
* @param reply 回复内容
* @param userId 用户ID
* @throws QuestionReplyServiceException 问题回复业务异常
*/
void replyQuestion(String questionId, String reply, String userId) throws QuestionReplyServiceException;
/**
* 采纳回复
* @param questionId 问题ID
* @param replyId 回复ID
* @param userId 用户ID
* @throws QuestionReplyServiceException 问题回复业务异常
*/
void adoptReply(String questionId, String replyId, String userId) throws QuestionReplyServiceException;
}
......@@ -3,10 +3,13 @@ package cn.meteor.beyondclouds.modules.question.service.impl;
import cn.meteor.beyondclouds.modules.question.entity.Question;
import cn.meteor.beyondclouds.modules.question.entity.QuestionReply;
import cn.meteor.beyondclouds.modules.question.enums.QuestionErrorCode;
import cn.meteor.beyondclouds.modules.question.enums.QuestionReplyErrorCode;
import cn.meteor.beyondclouds.modules.question.exception.QuestionReplyServiceException;
import cn.meteor.beyondclouds.modules.question.mapper.QuestionReplyMapper;
import cn.meteor.beyondclouds.modules.question.service.IQuestionReplyService;
import cn.meteor.beyondclouds.modules.question.service.IQuestionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -22,6 +25,8 @@ import org.springframework.stereotype.Service;
@Service
public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, QuestionReply> implements IQuestionReplyService {
private int ADOPTED_REPLY_STATUS = 1;
private IQuestionService questionService;
@Autowired
......@@ -48,4 +53,38 @@ public class QuestionReplyServiceImpl extends ServiceImpl<QuestionReplyMapper, Q
questionReply.setReplyStatus(0);
save(questionReply);
}
@Override
public void adoptReply(String questionId, String replyId, String userId) throws QuestionReplyServiceException {
//1.判断用户是否发布过该问题
QueryWrapper<Question> questionQueryWrapper = new QueryWrapper<>();
questionQueryWrapper.eq("user_id", userId)
.eq("question_id", questionId);
Question question = questionService.getOne(questionQueryWrapper);
//若问题不存在,则抛出问题不存在异常
if (null == question) {
throw new QuestionReplyServiceException(QuestionErrorCode.QUESTION_NOT_FOUND);
}
//2.判断该问题的回复是否存在
QueryWrapper<QuestionReply> questionReplyQueryWrapper = new QueryWrapper<>();
questionReplyQueryWrapper.eq("question_id", questionId)
.eq("reply_id", replyId);
QuestionReply questionReply = getOne(questionReplyQueryWrapper);
//若该回复不存在,则抛出回复不存在异常
if (null == questionReply) {
throw new QuestionReplyServiceException(QuestionReplyErrorCode.REPLY_NOT_FOUND);
}
//3.判断该回复之前是否已被采纳,若已被采纳,则抛出回复已被采纳异常
if (1 == questionReply.getReplyStatus()) {
throw new QuestionReplyServiceException(QuestionReplyErrorCode.REPLY_ADOPTED);
}
//4.采纳回复
UpdateWrapper<QuestionReply> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("reply_status",ADOPTED_REPLY_STATUS).eq("reply_id",replyId);
update(updateWrapper);
}
}
......@@ -3,7 +3,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 100Centa30821%mysql
password: 197442
swagger:
enable: true
......
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