Commit ad4eb0fc by 段启岩

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

parents d2cb4d34 fc1465a5
...@@ -43,8 +43,13 @@ public class TopicApi { ...@@ -43,8 +43,13 @@ public class TopicApi {
@PostMapping("/topic") @PostMapping("/topic")
public Response createTopic(@RequestBody @Valid CreateTopicForm createTopicForm, @CurrentSubject Subject subject) { public Response createTopic(@RequestBody @Valid CreateTopicForm createTopicForm, @CurrentSubject Subject subject) {
TopicDetail topic = topicService.createTopic(String.valueOf(subject.getId()), createTopicForm.getTopicName()); try {
return Response.success(topic); TopicDetail topic = topicService.createTopic(String.valueOf(subject.getId()), createTopicForm.getTopicName());
return Response.success(topic);
} catch (TopicServiceException e) {
e.printStackTrace();
return Response.error(e);
}
} }
......
...@@ -26,7 +26,7 @@ public interface ITopicService extends IService<Topic> { ...@@ -26,7 +26,7 @@ public interface ITopicService extends IService<Topic> {
* @param topicName * @param topicName
* @return TopicDetail * @return TopicDetail
*/ */
TopicDetail createTopic(String userId, String topicName); TopicDetail createTopic(String userId, String topicName) throws TopicServiceException;
/** /**
* 检索话题 * 检索话题
......
...@@ -67,15 +67,22 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements ...@@ -67,15 +67,22 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
} }
@Override @Override
public TopicDetail createTopic(String userId, String topicName) { public TopicDetail createTopic(String userId, String topicName) throws TopicServiceException{
//1. 创建话题 //1. 检测是否存在该话题
QueryWrapper<Topic> topicQueryWrapper = new QueryWrapper<>();
topicQueryWrapper.eq("topic_name",topicName);
if(getOne(topicQueryWrapper) != null) {
throw new TopicServiceException(TopicErrorCode.TOPIC_EXISTS);
}
//2. 创建话题
Topic topic = new Topic(); Topic topic = new Topic();
topic.setUserId(userId); topic.setUserId(userId);
topic.setTopicName(topicName); topic.setTopicName(topicName);
save(topic); save(topic);
//2. 返回话题的id与话题名称 //3. 返回话题的id与话题名称
TopicDetail topicDetail=new TopicDetail(); TopicDetail topicDetail=new TopicDetail();
BeanUtils.copyProperties(topic, topicDetail); BeanUtils.copyProperties(topic, topicDetail);
return topicDetail; return topicDetail;
......
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