complete_postlike

Change-Id: If5a628b11d1bf19d531703ec1a8b62f1690ed7fb
diff --git a/src/main/java/com/example/g8backend/mapper/PostMapper.java b/src/main/java/com/example/g8backend/mapper/PostMapper.java
index 0cba5c1..51c3164 100644
--- a/src/main/java/com/example/g8backend/mapper/PostMapper.java
+++ b/src/main/java/com/example/g8backend/mapper/PostMapper.java
@@ -1,17 +1,24 @@
 package com.example.g8backend.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.example.g8backend.entity.Post;
+import com.example.g8backend.entity.PostLike;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Insert;
 
 import java.util.List;
 
 @Mapper
 public interface PostMapper extends BaseMapper<Post> {
+
+    // 获取用户的帖子
     List<Post> getPostsByUserId(@Param("userId") Long userId);
 
+    // 搜索帖子
     @Select("<script>" +
             "SELECT p.* " +
             "FROM posts p " +
@@ -30,6 +37,22 @@
             "</if>" +
             "</script>")
     List<Post> searchPosts(@Param("keyword") String keyword,
-                           @Param("tagIds") List<Long> tagIds,  // 改成接受一个tagIds列表
+                           @Param("tagIds") List<Long> tagIds,
                            @Param("author") String author);
+
+    // 检查用户是否已经点赞该帖子
+    @Select("SELECT EXISTS (SELECT 1 FROM post_likes WHERE user_id = #{userId} AND post_id = #{postId})")
+    boolean existsByUserIdAndPostId(@Param("userId") Long userId, @Param("postId") Long postId);
+
+    // 插入一条点赞记录
+    @Insert("INSERT INTO post_likes (user_id, post_id) VALUES (#{userId}, #{postId})")
+    void insert(PostLike postLike);
+
+    // 删除用户对帖子的点赞记录
+    @Delete("DELETE FROM post_likes WHERE user_id = #{userId} AND post_id = #{postId}")
+    void deleteLikeByUserIdAndPostId(@Param("userId") Long userId, @Param("postId") Long postId);
+
+    // 获取某个帖子点赞数
+    @Select("SELECT COUNT(*) FROM post_likes WHERE post_id = #{postId}")
+    Long selectCount(@Param("postId") Long postId);
 }