blob: 6b95c73f8f035244b87827497defd260013f9821 [file] [log] [blame]
刘嘉昕f28ea232025-04-15 16:55:43 +08001package com.pt5.pthouduan.mapper;
2
3import com.pt5.pthouduan.entity.Post;
4import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5import org.apache.ibatis.annotations.Mapper;
ym923f1d9f452025-05-27 18:29:44 +08006import org.apache.ibatis.annotations.Param;
7
8import java.util.List;
刘嘉昕f28ea232025-04-15 16:55:43 +08009
10/**
11 * <p>
ym923f1d9f452025-05-27 18:29:44 +080012 * 帖子 Mapper 接口
刘嘉昕f28ea232025-04-15 16:55:43 +080013 * </p>
14 *
ym923f1d9f452025-05-27 18:29:44 +080015 * 功能:增、删、改、查(按关键词)、点赞、置顶、用户帖子查询、置顶帖子查询
16 *
17 * 作者:杨蔓
刘嘉昕f28ea232025-04-15 16:55:43 +080018 * @since 2025-04-14
19 */
20@Mapper
21public interface PostMapper extends BaseMapper<Post> {
22
ym923f1d9f452025-05-27 18:29:44 +080023 // 创建帖子
24 void save(Post post);
25
26 // 根据帖子ID删除
27 int deleteByPostid(@Param("postid") Integer postid);
28
29 // 更新帖子
30 int updatePost(Post post);
31
32 // 模糊搜索(标题或标签)
33 List<Post> searchByKeyword(@Param("keyword") String keyword);
34
35 // 点赞 +1
36 int incrementLikes(@Param("postid") Integer postid);
37
38 // 取消点赞 -1(最小为0)
39 int decrementLikes(@Param("postid") Integer postid);
40
41 // 设置置顶状态
42 int updatePinnedStatus(@Param("postid") Integer postid, @Param("pinned") boolean pinned);
43
44 // 根据用户ID查询该用户所有帖子
45 List<Post> findByUserid(@Param("userid") Long userid);
46
47 // 查询所有置顶帖子
48 List<Post> findPinnedPosts();
49
50 // ✅ 新增:查询所有帖子(置顶优先,时间倒序)
51 List<Post> selectAllSorted();
刘嘉昕f28ea232025-04-15 16:55:43 +080052}