blob: b8fa1bf1daf114f489c821407342a76289d45b5b [file] [log] [blame]
夜雨声烦5c9d1312025-04-23 17:46:19 +08001package com.example.g8backend.mapper;
2
3import com.example.g8backend.entity.Comment;
4import org.apache.ibatis.annotations.*;
5
6import java.util.List;
7
8@Mapper
9public interface CommentMapper {
10
11 // 插入评论
12 @Insert("INSERT INTO comments (post_id, user_id, content, parent_comment_id) VALUES (#{postId}, #{userId}, #{content}, #{parentCommentId})")
13 int insert(Comment comment);
14
15 // 获取顶级评论
16 @Select("SELECT * FROM comments WHERE post_id = #{postId} AND parent_comment_id IS NULL ORDER BY created_at DESC")
17 List<Comment> findTopLevelCommentsByPostId(Long postId);
18
19 // 获取某个父评论ID对应的子评论
20 @Select("SELECT * FROM comments WHERE parent_comment_id = #{parentCommentId} ORDER BY created_at DESC")
21 List<Comment> findRepliesByParentCommentId(Long parentCommentId);
22
23 // 删除评论
24 @Delete("DELETE FROM comments WHERE comment_id = #{commentId}")
25 int deleteById(Long commentId);
26}