Commit fc57e42f by 胡明森

通过话题id与话题name获取话题详情

parent 08a40aa6
......@@ -83,10 +83,14 @@ public class TopicApi {
@Anonymous
@ApiOperation("话题详情")
@GetMapping("/topic/{topicId}")
public Response getTopic(@PathVariable("topicId") String topicId) {
@GetMapping("/topic/{topicBy}")
public Response getTopic(@PathVariable("topicBy") String topicBy, String by) {
if (by == null) {
by="id";
}
try {
Topic topic = topicService.getTopic(topicId);
Topic topic = topicService.getTopic(topicBy,by);
return Response.success(topic);
} catch (TopicServiceException e) {
e.printStackTrace();
......
......@@ -46,10 +46,12 @@ public interface ITopicService extends IService<Topic> {
/**
* 话题详情
* @param topicId
* @param topicBy
* @param by
* @return
* @throws TopicServiceException
*/
Topic getTopic(String topicId) throws TopicServiceException;
Topic getTopic(String topicBy, String by) throws TopicServiceException;
/**
* 我关注的话题
......
......@@ -99,10 +99,24 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
@Override
public Topic getTopic(String topicId) throws TopicServiceException {
public Topic getTopic(String topicBy,String by) throws TopicServiceException {
//1. 获取话题
Topic topic = getById(topicId);
//1. 判断by为话题id,还是话题名称
Topic topic;
if ("id".equals(by)) {
// 通过话题id获取话题
topic = getById(topicBy);
} else {
// 通过话题name获取话题
QueryWrapper<Topic> topicQueryWrapper = new QueryWrapper<>();
topicQueryWrapper.eq("topic_name",topicBy);
topic = getOne(topicQueryWrapper);
}
//2. 找不到该话题,抛出业务异常
if (topic == null) {
......
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