Skip to content

Commit

Permalink
fix: bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Pleasurecruise committed Nov 14, 2024
1 parent e0cc5da commit 43296c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public interface TopicMapper {
void deleteTopicComments(Integer topicId);

/**
* 查询用户发布的帖子
* 查询用户发布的帖子ids
*/
List<Topic> getPublishedPosts(@Param("authorId") Integer authorId);
List<Integer> getPublishedTopicIds(@Param("authorId") Integer authorId);

/**
* 查询用户收藏的帖子ids
*/
List<Integer> getCollectedTopicIds(Integer id);
List<Integer> getCollectedTopicIds(@Param("id") Integer id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,30 +215,32 @@ public PageResult pageQuery(PageQueryDTO pageQueryDTO) {
@Override
public PageResult<Topic> getPublishedPosts(Integer id, int page, int pageSize) {
PageHelper.startPage(page, pageSize);
List<Topic> posts = topicMapper.getPublishedPosts(id);
List<Integer> publishedTopicIds = topicMapper.getPublishedTopicIds(id);
List<Topic> posts = topicMapper.getTopicsByIds(publishedTopicIds);
PageInfo<Topic> pageInfo = new PageInfo<>(posts);
return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
}

/**
* 查询评论的帖子(分页)
* 查询收藏的帖子(分页)
*/
@Override
public PageResult<Topic> getCommentedPosts(Integer id, int page, int pageSize) {
public PageResult<Topic> getCollectedPosts(Integer id, int page, int pageSize) {
PageHelper.startPage(page, pageSize);
List<Topic> posts = commentMapper.getCommentedPosts(id);
List<Integer> collectedTopicIds = topicMapper.getCollectedTopicIds(id);
log.info("collectedTopicIds:{}", collectedTopicIds);
List<Topic> posts = topicMapper.getTopicsByIds(collectedTopicIds);
PageInfo<Topic> pageInfo = new PageInfo<>(posts);
return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
}

/**
* 查询收藏的帖子(分页)
* 查询评论的帖子(分页)
*/
@Override
public PageResult<Topic> getCollectedPosts(Integer id, int page, int pageSize) {
public PageResult<Topic> getCommentedPosts(Integer id, int page, int pageSize) {
PageHelper.startPage(page, pageSize);
List<Integer> collectedTopicIds = topicMapper.getCollectedTopicIds(id);
List<Topic> posts = topicMapper.getTopicsByIds(collectedTopicIds);
List<Topic> posts = commentMapper.getCommentedPosts(id);
PageInfo<Topic> pageInfo = new PageInfo<>(posts);
return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
}
Expand Down
6 changes: 4 additions & 2 deletions backend/wall-server/src/main/resources/mapper/TopicMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
<result property="isDraft" column="isDraft" />
</resultMap>

<select id="getPublishedPosts" parameterType="int" resultType="Topic">
SELECT * FROM topic WHERE authorID = #{authorId}
<select id="getPublishedTopicIds" parameterType="int" resultType="int">
SELECT id
FROM topic
WHERE authorID = #{authorId}
</select>

<!-- Likes functionality -->
Expand Down

0 comments on commit 43296c2

Please sign in to comment.