Commit caedda42 by 段启岩

修复可以关注同一个话题的问题

parent 9c41b925
...@@ -12,7 +12,8 @@ public enum TopicErrorCode implements IErrorCode { ...@@ -12,7 +12,8 @@ public enum TopicErrorCode implements IErrorCode {
* 话题已存在 * 话题已存在
*/ */
TOPIC_EXISTS(3001, "该话题已存在"), TOPIC_EXISTS(3001, "该话题已存在"),
TOPIC_NOT_EXISTS(3002, "该话题不存在"); TOPIC_NOT_EXISTS(3002, "该话题不存在"),
AlREADY_FOLLOWED(3003, "已关注过该话题");
TopicErrorCode(long code, String msg) { TopicErrorCode(long code, String msg) {
this.code = code; this.code = code;
......
...@@ -89,7 +89,16 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements ...@@ -89,7 +89,16 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
throw new TopicServiceException(TopicErrorCode.TOPIC_NOT_EXISTS); throw new TopicServiceException(TopicErrorCode.TOPIC_NOT_EXISTS);
} }
//3. 关注话题 //3. 判断用户是否已经关注该话题
QueryWrapper<TopicFollow> topicFollowQueryWrapper = new QueryWrapper<>();
topicFollowQueryWrapper.eq("user_id", userId);
topicFollowQueryWrapper.eq("topic", topicId);
if (null != topicFollowService.getOne(topicFollowQueryWrapper)) {
throw new TopicServiceException(TopicErrorCode.AlREADY_FOLLOWED);
}
//4. 关注话题
TopicFollow topicFollow = new TopicFollow(); TopicFollow topicFollow = new TopicFollow();
topicFollow.setTopicId(topicId); topicFollow.setTopicId(topicId);
topicFollow.setUserId(userId); topicFollow.setUserId(userId);
......
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