Commit 118af37e by 段启岩

Merge remote-tracking branch 'origin/fix-issue#12'

parents 8b43006a 1d5e6574
......@@ -72,15 +72,9 @@ public class QuestionApi {
//设置用户ID(问题发布者ID)
question.setUserId((String) subject.getId());
//祛除重复标签
HashSet<String> tags = QuestionUtils.toHashSet(questionForm.getTagIds());
//祛除重复话题
HashSet<String> topicIds = QuestionUtils.toHashSet(questionForm.getTopicIds());
//发布问题
try {
questionService.postQuestion(question,questionForm.getQuestionDetail(),tags, topicIds);
questionService.postQuestion(question, questionForm.getQuestionDetail(), questionForm.getTagIds(), questionForm.getTopicIds());
return Response.success();
} catch (QuestionServiceException e) {
e.printStackTrace();
......@@ -131,19 +125,9 @@ public class QuestionApi {
//3.设置用户ID
question.setUserId((String) subject.getId());
//4.祛除重复标签
HashSet<String> tags = null;
if (!CollectionUtils.isEmpty(questionForm.getTagIds())) {
tags = QuestionUtils.toHashSet(questionForm.getTagIds());
}
//5.祛除重复话题
HashSet<String> topicIds = null;
if (!CollectionUtils.isEmpty(questionForm.getTopicIds())) {
topicIds = QuestionUtils.toHashSet(questionForm.getTopicIds());
}
//6.修改问题
//4.修改问题
try {
questionService.updateQuestion(question, questionForm.getQuestionDetail(), tags, topicIds);
questionService.updateQuestion(question, questionForm.getQuestionDetail(), questionForm.getTagIds(), questionForm.getTopicIds());
return Response.success();
} catch (QuestionServiceException e) {
e.printStackTrace();
......
......@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.HashSet;
import java.util.List;
/**
* <p>
......@@ -28,7 +29,7 @@ public interface IQuestionService extends IService<Question> {
* @param topicIds 话题ID
* @throws QuestionServiceException 问题业务异常
*/
void postQuestion(Question question, String questionDetail, HashSet<String> tags, HashSet<String> topicIds) throws QuestionServiceException;
void postQuestion(Question question, String questionDetail, List<String> tags, List<String> topicIds) throws QuestionServiceException;
/**
* 删除问题
......@@ -46,7 +47,7 @@ public interface IQuestionService extends IService<Question> {
* @param topicIds 话题ID
* @throws QuestionServiceException 问题业务异常
*/
void updateQuestion(Question question, String questionDetail, HashSet<String> tags, HashSet<String> topicIds) throws QuestionServiceException;
void updateQuestion(Question question, String questionDetail, List<String> tags, List<String> topicIds) throws QuestionServiceException;
/**
......
......@@ -99,7 +99,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
@Transactional(rollbackFor = Exception.class)
@Override
public void postQuestion(Question question, String questionDetail, HashSet<String> tagIds, HashSet<String> topicIds) throws QuestionServiceException {
public void postQuestion(Question question, String questionDetail, List<String> tagIds, List<String> topicIds) throws QuestionServiceException {
//1.检查问题标题是否以?结尾
if (!question.getQuestionTitle().endsWith(QUESTION_END_EN) && !question.getQuestionTitle().endsWith(QUESTION_END_CN)){
throw new QuestionServiceException(QuestionErrorCode.QUESTION_END_ERROR);
......@@ -128,7 +128,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
if (!CollectionUtils.isEmpty(topicIds)) {
// 获取要引用的话题,不正确的话题ID会被自动过滤
List<String> existsTopicIds = topicService.listByIds(topicIds).stream().map(Topic::getTopicId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(existsTopicIds)) {
List<TopicReference> topicReferenceList = new ArrayList<>();
for (String topicId : existsTopicIds) {
......@@ -203,7 +202,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
@Transactional(rollbackFor = Exception.class)
@Override
public void updateQuestion(Question question, String questionDetail, HashSet<String> tagIds, HashSet<String> topicIds) throws QuestionServiceException {
public void updateQuestion(Question question, String questionDetail, List<String> tagIds, List<String> topicIds) throws QuestionServiceException {
//1.判断自己是否发布过此问题
QueryWrapper<Question> questionQueryWrapper = new QueryWrapper<>();
questionQueryWrapper.eq("question_id",question.getQuestionId())
......
......@@ -25,15 +25,4 @@ public class QuestionUtils {
return queryWrapper;
}
/**
* 处理标签
* @param tagIdList 标签
* @return Set
*/
public static HashSet<String> toHashSet(List<String> tagIdList){
HashSet<String> tagIds = new HashSet<>();
tagIds.addAll(tagIdList);
return tagIds;
}
}
......@@ -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: 2018006709
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