bug_fix+historyview
Change-Id: I6f446c1b660a4322865cfcf5502c88cb772ca0a1
diff --git a/src/main/java/com/example/g8backend/mapper/PostMapper.java b/src/main/java/com/example/g8backend/mapper/PostMapper.java
index 8f7e029..d49125e 100644
--- a/src/main/java/com/example/g8backend/mapper/PostMapper.java
+++ b/src/main/java/com/example/g8backend/mapper/PostMapper.java
@@ -4,11 +4,7 @@
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 org.apache.ibatis.annotations.*;
import java.util.List;
@@ -55,4 +51,7 @@
// 获取某个帖子点赞数
@Select("SELECT COUNT(*) FROM post_likes WHERE post_id = #{postId}")
Long selectCount(@Param("postId") Long postId);
+
+ @Update("UPDATE posts SET view_count = view_count + 1 WHERE post_id = #{postId}")
+ void incrementViewCount(Long postId);
}
diff --git a/src/main/java/com/example/g8backend/mapper/PostViewMapper.java b/src/main/java/com/example/g8backend/mapper/PostViewMapper.java
new file mode 100644
index 0000000..7423418
--- /dev/null
+++ b/src/main/java/com/example/g8backend/mapper/PostViewMapper.java
@@ -0,0 +1,21 @@
+package com.example.g8backend.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.g8backend.entity.PostView;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+@Mapper
+public interface PostViewMapper extends BaseMapper<PostView> {
+
+
+ @Select("SELECT post_id FROM post_views WHERE user_id = #{userId}")
+ List<Long> findViewedPostIds(@Param("userId") Long userId);
+
+
+ @Select("SELECT * FROM post_views WHERE user_id = #{userId} ORDER BY view_time DESC LIMIT #{limit}")
+ List<PostView> selectRecentViews(@Param("userId") Long userId, @Param("limit") int limit);
+}
\ No newline at end of file