Commit 6922b4fd by 胡明森

引用该话题所有动态

parent 0485dd57
......@@ -6,6 +6,7 @@ import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.authentication.Subject;
import cn.meteor.beyondclouds.modules.post.entity.Post;
import cn.meteor.beyondclouds.modules.topic.bean.TopicDetail;
import cn.meteor.beyondclouds.modules.topic.entity.Topic;
import cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException;
......@@ -167,4 +168,19 @@ public class TopicApi {
return Response.success(topicPageVO);
}
@Anonymous
@ApiOperation("引用该话题所有动态")
@GetMapping("/topic/{topicName}/posts")
public Response<PageVO<Post>> getPostByTopicName(@Valid PageForm pageForm , @PathVariable("topicName") String topicName) {
try {
IPage<Post> post = topicService.getPostByTopicName(pageForm.getPage(), pageForm.getSize(),topicName);
PageVO<Post> postPageVO = new PageVO<>(post);
return Response.success(postPageVO);
} catch (TopicServiceException e) {
e.printStackTrace();
return Response.error();
}
}
}
package cn.meteor.beyondclouds.modules.topic.service;
import cn.meteor.beyondclouds.modules.post.entity.Post;
import cn.meteor.beyondclouds.modules.topic.bean.TopicDetail;
import cn.meteor.beyondclouds.modules.topic.entity.Topic;
import cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException;
......@@ -128,4 +129,14 @@ public interface ITopicService extends IService<Topic> {
* @return
*/
IPage<Topic> getHotPage(Integer pageNumber, Integer pageSize);
/**
*该话题下所有的动态
* @param pageNumber
* @param pageSize
* @param topicName
* @throws TopicServiceException
* @return IPage<Post>
*/
IPage<Post> getPostByTopicName(Integer pageNumber, Integer pageSize, String topicName) throws TopicServiceException;
}
package cn.meteor.beyondclouds.modules.topic.service.impl;
import cn.meteor.beyondclouds.modules.post.entity.Post;
import cn.meteor.beyondclouds.modules.post.service.IPostService;
import cn.meteor.beyondclouds.modules.topic.bean.TopicDetail;
import cn.meteor.beyondclouds.modules.topic.entity.Topic;
import cn.meteor.beyondclouds.modules.topic.entity.TopicFollow;
import cn.meteor.beyondclouds.modules.topic.entity.TopicReference;
import cn.meteor.beyondclouds.modules.topic.enums.TopicErrorCode;
import cn.meteor.beyondclouds.modules.topic.exception.TopicServiceException;
import cn.meteor.beyondclouds.modules.topic.mapper.TopicMapper;
import cn.meteor.beyondclouds.modules.topic.service.ITopicFollowService;
import cn.meteor.beyondclouds.modules.topic.service.ITopicReferenceService;
import cn.meteor.beyondclouds.modules.topic.service.ITopicService;
import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.service.IUserService;
......@@ -41,10 +45,16 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
private TopicMapper topicMapper;
private ITopicReferenceService topicReferenceService;
private IPostService postService;
@Autowired
public TopicServiceImpl(ITopicFollowService topicFollowService, TopicMapper topicMapper) {
public TopicServiceImpl(ITopicFollowService topicFollowService, TopicMapper topicMapper,ITopicReferenceService topicReferenceService,IPostService postService) {
this.topicFollowService = topicFollowService;
this.topicMapper = topicMapper;
this.topicReferenceService = topicReferenceService;
this.postService = postService;
}
@Autowired
......@@ -290,4 +300,47 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
}
@Override
public IPage<Post> getPostByTopicName(Integer pageNumber, Integer pageSize, String topicName) throws TopicServiceException{
//1. 设置分页信息
IPage<TopicReference> page = new Page<>(pageNumber, pageSize);
//2. 判断该话题是否存在
QueryWrapper<Topic> topicQueryWrapper = new QueryWrapper<>();
topicQueryWrapper.eq("topic_name",topicName);
Topic topic=getOne(topicQueryWrapper);
if (topic == null) {
throw new TopicServiceException(TopicErrorCode.TOPIC_NOT_EXISTS);
}
//3. 通过话题id与动态类型3查找该话题下的所有动态
QueryWrapper<TopicReference> topicReferenceQueryWrapper = new QueryWrapper<>();
topicReferenceQueryWrapper.eq("topic_id",topic.getTopicId()).eq("referencer_type",3);
IPage<TopicReference> topicReferenceIPage = topicReferenceService.page(page,topicReferenceQueryWrapper);
//4. 获取查询到的referencerId
List<String> referencerId = topicReferenceIPage.getRecords().stream()
.map(TopicReference::getReferencerId)
.collect(Collectors.toList());
//5. 通过referencerId批量查询动态
List<Post> posts;
if (!CollectionUtils.isEmpty(referencerId)) {
posts = postService.listByIds(referencerId);
} else {
posts = List.of();
}
// 6.构造分页结果
IPage<Post> postIPage = new Page<>();
postIPage.setSize(topicReferenceIPage.getSize());
postIPage.setCurrent(topicReferenceIPage.getCurrent());
postIPage.setPages(topicReferenceIPage.getPages());
postIPage.setTotal(topicReferenceIPage.getTotal());
postIPage.setRecords(posts);
return postIPage;
}
}
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