用户,分区,作品的增删改查,根据作者查所有作品的接口,根据用户查还有多少任务没做,帖子和评论的增删改查,并优化了测试文件的结构

Change-Id: I4266495b6465fcbdf5705f02a59d2ae9fa54cbda
diff --git a/src/main/java/edu/bjtu/groupone/backend/api/CommentController.java b/src/main/java/edu/bjtu/groupone/backend/api/CommentController.java
new file mode 100644
index 0000000..d182c7e
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/api/CommentController.java
@@ -0,0 +1,58 @@
+package edu.bjtu.groupone.backend.api;
+
+import edu.bjtu.groupone.backend.domain.entity.Comment;
+import edu.bjtu.groupone.backend.domain.entity.Result;
+import edu.bjtu.groupone.backend.service.CommentService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.ExampleObject;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@CrossOrigin
+@Tag(name = "评论相关接口")
+@RestController
+public class CommentController {
+
+    @Autowired
+    private CommentService commentService;
+
+    @Operation(summary = "添加评论")
+    @PostMapping("/comments")
+    public Result<String> addComment(@RequestBody Comment comment) {
+        commentService.addComment(comment);
+        return Result.success("评论添加成功");
+    }
+
+    @Operation(summary = "删除评论")
+    @DeleteMapping("/comments/{commentId}")
+    public Result<String> deleteComment(@PathVariable Long commentId) {
+        commentService.deleteComment(commentId);
+        return Result.success("评论删除成功");
+    }
+
+    @Operation(summary = "更新评论")
+    @PutMapping("/comments/{commentId}")
+    public Result<String> updateComment(@PathVariable Long commentId, @RequestBody Comment comment) {
+        comment.setCommentId(commentId);
+        commentService.updateComment(comment);
+        return Result.success("评论更新成功");
+    }
+
+    @Operation(summary = "获取评论详情")
+    @GetMapping("/comments/{commentId}")
+    public Result<Comment> getComment(@PathVariable Long commentId) {
+        return Result.success(commentService.getCommentById(commentId));
+    }
+
+    @Operation(summary = "获取帖子所有评论")
+    @GetMapping("/comments/post/{postId}")
+    public Result<List<Comment>> getCommentsByPostId(@PathVariable Long postId) {
+        return Result.success(commentService.getCommentsByPostId(postId));
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/api/PostController.java b/src/main/java/edu/bjtu/groupone/backend/api/PostController.java
new file mode 100644
index 0000000..0258f2d
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/api/PostController.java
@@ -0,0 +1,58 @@
+package edu.bjtu.groupone.backend.api;
+
+import edu.bjtu.groupone.backend.domain.entity.Post;
+import edu.bjtu.groupone.backend.domain.entity.Result;
+import edu.bjtu.groupone.backend.service.PostService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.ExampleObject;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@CrossOrigin
+@Tag(name = "帖子相关接口")
+@RestController
+public class PostController {
+
+    @Autowired
+    private PostService postService;
+
+    @Operation(summary = "添加帖子")
+    @PostMapping("/posts")
+    public Result<String> addPost(@RequestBody Post post) {
+        postService.addPost(post);
+        return Result.success("帖子添加成功");
+    }
+
+    @Operation(summary = "删除帖子")
+    @DeleteMapping("/posts/{postId}")
+    public Result<String> deletePost(@PathVariable Long postId) {
+        postService.deletePost(postId);
+        return Result.success("帖子删除成功");
+    }
+
+    @Operation(summary = "更新帖子")
+    @PutMapping("/posts/{postId}")
+    public Result<String> updatePost(@PathVariable Long postId, @RequestBody Post post) {
+        post.setPostId(postId);
+        postService.updatePost(post);
+        return Result.success("帖子更新成功");
+    }
+
+    @Operation(summary = "获取帖子详情")
+    @GetMapping("/posts/{postId}")
+    public Result<Post> getPost(@PathVariable Long postId) {
+        return Result.success(postService.getPostById(postId));
+    }
+
+    @Operation(summary = "获取所有帖子")
+    @GetMapping("/posts")
+    public Result<List<Post>> getAllPosts() {
+        return Result.success(postService.getAllPosts());
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/api/UserController.java b/src/main/java/edu/bjtu/groupone/backend/api/UserController.java
index 46fb153..c4ebbec 100644
--- a/src/main/java/edu/bjtu/groupone/backend/api/UserController.java
+++ b/src/main/java/edu/bjtu/groupone/backend/api/UserController.java
@@ -389,4 +389,40 @@
         String newToken = JwtUtils.generateJwt(payload);
         return Result.success(newToken);
     }
+    @Operation(
+            summary = "查询用户剩余任务数量",
+            description = "根据用户ID查询剩余未完成的任务数量(包括种子、帖子、评论)",
+            responses = {
+                    @ApiResponse(
+                            responseCode = "200",
+                            description = "查询成功",
+                            content = @Content(
+                                    schema = @Schema(implementation = Result.class),
+                                    examples = @ExampleObject(
+                                            name = "查询成功示例",
+                                            value = "{\"code\":200,\"message\":\"操作成功\",\"data\":3}"
+                                    )
+                            )
+                    ),
+                    @ApiResponse(
+                            responseCode = "400",
+                            description = "用户不存在",
+                            content = @Content(
+                                    schema = @Schema(implementation = Result.class),
+                                    examples = @ExampleObject(
+                                            name = "查询失败示例",
+                                            value = "{\"code\":400,\"message\":\"用户不存在\",\"data\":null}"
+                                    )
+                            )
+                    )
+            }
+    )
+    @GetMapping("/api/tasks/remaining/{userId}")
+    public Result<Integer> getRemainingTasks(@PathVariable int userId) {
+        int remainingTasks = userService.getRemainingTasks(userId);
+        if (remainingTasks < 0) {
+            return Result.error("用户不存在");
+        }
+        return Result.success(remainingTasks);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/api/WorkController.java b/src/main/java/edu/bjtu/groupone/backend/api/WorkController.java
index 1eb4bee..d15c4ce 100644
--- a/src/main/java/edu/bjtu/groupone/backend/api/WorkController.java
+++ b/src/main/java/edu/bjtu/groupone/backend/api/WorkController.java
@@ -1,16 +1,23 @@
 package edu.bjtu.groupone.backend.api;
 
 import edu.bjtu.groupone.backend.domain.dto.WorkResponse;
+import edu.bjtu.groupone.backend.domain.entity.Result;
 import edu.bjtu.groupone.backend.domain.entity.Work;
 import edu.bjtu.groupone.backend.service.WorkService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.ExampleObject;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 @RestController
 @RequestMapping("/api/works")
 @Tag(name = "Work", description = "作品相关接口")
@@ -57,4 +64,40 @@
     public ResponseEntity<Work> getWork(@PathVariable Long id) {
         return ResponseEntity.ok(workService.getWorkById(id));
     }
+    @Operation(
+            summary = "根据作者查询所有作品",
+            description = "根据作者名称查询其所有作品",
+            responses = {
+                    @ApiResponse(
+                            responseCode = "200",
+                            description = "查询成功",
+                            content = @Content(
+                                    schema = @Schema(implementation = Result.class),
+                                    examples = @ExampleObject(
+                                            name = "查询成功示例",
+                                            value = "{\"code\":200,\"message\":\"操作成功\",\"data\":[{\"id\":101,\"title\":\"《我的世界》\",\"author\":\"张三\",\"views\":1234,\"categoryId\":1,\"description\":\"一部关于...\",\"createTime\":\"2023-06-15\"}]}"
+                                    )
+                            )
+                    ),
+                    @ApiResponse(
+                            responseCode = "400",
+                            description = "作者不存在",
+                            content = @Content(
+                                    schema = @Schema(implementation = Result.class),
+                                    examples = @ExampleObject(
+                                            name = "查询失败示例",
+                                            value = "{\"code\":400,\"message\":\"作者不存在\",\"data\":null}"
+                                    )
+                            )
+                    )
+            }
+    )
+    @GetMapping("/works/byAuthor")
+    public Result<List<WorkResponse>> getWorksByAuthor(@RequestParam String author) {
+        List<WorkResponse> works = workService.getWorksByAuthor(author);
+        if (works == null || works.isEmpty()) {
+            return Result.error("作者不存在");
+        }
+        return Result.success(works);
+    }
 }
diff --git a/src/main/java/edu/bjtu/groupone/backend/domain/entity/Comment.java b/src/main/java/edu/bjtu/groupone/backend/domain/entity/Comment.java
new file mode 100644
index 0000000..4c30e53
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/domain/entity/Comment.java
@@ -0,0 +1,16 @@
+package edu.bjtu.groupone.backend.domain.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Comment {
+    private Long commentId;
+    private Long postId;
+    private int userId;
+    private String content;
+    private String createTime;
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/domain/entity/Post.java b/src/main/java/edu/bjtu/groupone/backend/domain/entity/Post.java
new file mode 100644
index 0000000..56a009f
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/domain/entity/Post.java
@@ -0,0 +1,18 @@
+// Post.java
+package edu.bjtu.groupone.backend.domain.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Post {
+    private Long postId;
+    private int userId;
+    private String title;
+    private String content;
+    private String createTime;
+    private int views;
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/domain/entity/Task.java b/src/main/java/edu/bjtu/groupone/backend/domain/entity/Task.java
new file mode 100644
index 0000000..1470d79
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/domain/entity/Task.java
@@ -0,0 +1,15 @@
+package edu.bjtu.groupone.backend.domain.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Task {
+    private int taskId;
+    private int userId;
+    private String type; // "seed" (种子), "post", "comment"
+    private boolean completed;
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/mapper/CommentMapper.java b/src/main/java/edu/bjtu/groupone/backend/mapper/CommentMapper.java
new file mode 100644
index 0000000..e45ba4e
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/mapper/CommentMapper.java
@@ -0,0 +1,24 @@
+package edu.bjtu.groupone.backend.mapper;
+
+import edu.bjtu.groupone.backend.domain.entity.Comment;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface CommentMapper {
+    @Insert("INSERT INTO `comment` (`post_id`, `user_id`, `content`, `create_time`) VALUES (#{postId}, #{userId}, #{content}, #{createTime})")
+    void insertComment(Comment comment);
+
+    @Delete("DELETE FROM `comment` WHERE `comment_id` = #{commentId}")
+    void deleteComment(Long commentId);
+
+    @Update("UPDATE `comment` SET `post_id` = #{postId}, `user_id` = #{userId}, `content` = #{content}, `create_time` = #{createTime} WHERE `comment_id` = #{commentId}")
+    void updateComment(Comment comment);
+
+    @Select("SELECT * FROM `comment` WHERE `comment_id` = #{commentId}")
+    Comment selectCommentById(Long commentId);
+
+    @Select("SELECT * FROM `comment` WHERE `post_id` = #{postId}")
+    List<Comment> selectCommentsByPostId(Long postId);
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/mapper/PostMapper.java b/src/main/java/edu/bjtu/groupone/backend/mapper/PostMapper.java
new file mode 100644
index 0000000..4d1f73d
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/mapper/PostMapper.java
@@ -0,0 +1,24 @@
+package edu.bjtu.groupone.backend.mapper;
+
+import edu.bjtu.groupone.backend.domain.entity.Post;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface PostMapper {
+    @Insert("INSERT INTO `post` (`user_id`, `title`, `content`, `create_time`, `views`) VALUES (#{userId}, #{title}, #{content}, #{createTime}, #{views})")
+    void insertPost(Post post);
+
+    @Delete("DELETE FROM `post` WHERE `post_id` = #{postId}")
+    void deletePost(Long postId);
+
+    @Update("UPDATE `post` SET `user_id` = #{userId}, `title` = #{title}, `content` = #{content}, `create_time` = #{createTime}, `views` = #{views} WHERE `post_id` = #{postId}")
+    void updatePost(Post post);
+
+    @Select("SELECT * FROM `post` WHERE `post_id` = #{postId}")
+    Post selectPostById(Long postId);
+
+    @Select("SELECT * FROM `post`")
+    List<Post> selectAllPosts();
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/mapper/UserMapper.java b/src/main/java/edu/bjtu/groupone/backend/mapper/UserMapper.java
index 8049e6a..dfcedad 100644
--- a/src/main/java/edu/bjtu/groupone/backend/mapper/UserMapper.java
+++ b/src/main/java/edu/bjtu/groupone/backend/mapper/UserMapper.java
@@ -40,6 +40,9 @@
     @Select("SELECT * FROM user")
     List<User> selectAllUsers();
 
+    @Select("SELECT COUNT(*) FROM task WHERE user_id = #{userId} AND completed = false")
+    int countRemainingTasks(int userId);
+
     @Select({"SELECT * FROM user WHERE user_id = #{id}"})
     User selectById(@Param("id") Long id);
 }
diff --git a/src/main/java/edu/bjtu/groupone/backend/mapper/WorkMybatisMapper.java b/src/main/java/edu/bjtu/groupone/backend/mapper/WorkMybatisMapper.java
index 90836a8..c127c8c 100644
--- a/src/main/java/edu/bjtu/groupone/backend/mapper/WorkMybatisMapper.java
+++ b/src/main/java/edu/bjtu/groupone/backend/mapper/WorkMybatisMapper.java
@@ -34,4 +34,8 @@
     // 查询
     @Select("SELECT * FROM works WHERE id = #{id}")
     Work findById(Long id);
+    @Select("SELECT * FROM works WHERE author = #{author}")
+    List<Work> findByAuthor(String author);
+
+
 }
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/CommentService.java b/src/main/java/edu/bjtu/groupone/backend/service/CommentService.java
new file mode 100644
index 0000000..1cbd321
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/service/CommentService.java
@@ -0,0 +1,14 @@
+package edu.bjtu.groupone.backend.service;
+
+import edu.bjtu.groupone.backend.domain.entity.Comment;
+import java.util.List;
+
+public interface CommentService {
+    void addComment(Comment comment);
+    void deleteComment(Long commentId);
+    void updateComment(Comment comment);
+    Comment getCommentById(Long commentId);
+    List<Comment> getCommentsByPostId(Long postId);
+}
+
+// CommentServiceImpl.jav
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/PostService.java b/src/main/java/edu/bjtu/groupone/backend/service/PostService.java
new file mode 100644
index 0000000..a87d48f
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/service/PostService.java
@@ -0,0 +1,13 @@
+// PostService.java
+package edu.bjtu.groupone.backend.service;
+
+import edu.bjtu.groupone.backend.domain.entity.Post;
+import java.util.List;
+
+public interface PostService {
+    void addPost(Post post);
+    void deletePost(Long postId);
+    void updatePost(Post post);
+    Post getPostById(Long postId);
+    List<Post> getAllPosts();
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/UserService.java b/src/main/java/edu/bjtu/groupone/backend/service/UserService.java
index 77d3bba..9bcc79e 100644
--- a/src/main/java/edu/bjtu/groupone/backend/service/UserService.java
+++ b/src/main/java/edu/bjtu/groupone/backend/service/UserService.java
@@ -20,4 +20,5 @@
     void updateUser(User user);
     User getUserById(int userId);
     List<User> getAllUsers();
+    int getRemainingTasks(int userId);
 }
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/WorkService.java b/src/main/java/edu/bjtu/groupone/backend/service/WorkService.java
index ec0494f..eaff2e2 100644
--- a/src/main/java/edu/bjtu/groupone/backend/service/WorkService.java
+++ b/src/main/java/edu/bjtu/groupone/backend/service/WorkService.java
@@ -13,6 +13,7 @@
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class WorkService {
@@ -61,4 +62,10 @@
     public Work getWorkById(Long id) {
         return workMybatisMapper.findById(id);
     }
+    public List<WorkResponse> getWorksByAuthor(String author) {
+        List<Work> works = workMybatisMapper.findByAuthor(author);
+        return works.stream()
+                .map(this::convertToResponse)
+                .collect(Collectors.toList());
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/impl/CommentServiceImpl.java b/src/main/java/edu/bjtu/groupone/backend/service/impl/CommentServiceImpl.java
new file mode 100644
index 0000000..f792a29
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/service/impl/CommentServiceImpl.java
@@ -0,0 +1,40 @@
+package edu.bjtu.groupone.backend.service.impl;
+
+import edu.bjtu.groupone.backend.mapper.CommentMapper;
+import edu.bjtu.groupone.backend.domain.entity.Comment;
+import edu.bjtu.groupone.backend.service.CommentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CommentServiceImpl implements CommentService {
+    @Autowired
+    private CommentMapper commentMapper;
+
+    @Override
+    public void addComment(Comment comment) {
+        commentMapper.insertComment(comment);
+    }
+
+    @Override
+    public void deleteComment(Long commentId) {
+        commentMapper.deleteComment(commentId);
+    }
+
+    @Override
+    public void updateComment(Comment comment) {
+        commentMapper.updateComment(comment);
+    }
+
+    @Override
+    public Comment getCommentById(Long commentId) {
+        return commentMapper.selectCommentById(commentId);
+    }
+
+    @Override
+    public List<Comment> getCommentsByPostId(Long postId) {
+        return commentMapper.selectCommentsByPostId(postId);
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/impl/PostServiceImpl.java b/src/main/java/edu/bjtu/groupone/backend/service/impl/PostServiceImpl.java
new file mode 100644
index 0000000..8eb57ac
--- /dev/null
+++ b/src/main/java/edu/bjtu/groupone/backend/service/impl/PostServiceImpl.java
@@ -0,0 +1,40 @@
+package edu.bjtu.groupone.backend.service.impl;
+
+import edu.bjtu.groupone.backend.mapper.PostMapper;
+import edu.bjtu.groupone.backend.domain.entity.Post;
+import edu.bjtu.groupone.backend.service.PostService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class PostServiceImpl implements PostService {
+    @Autowired
+    private PostMapper postMapper;
+
+    @Override
+    public void addPost(Post post) {
+        postMapper.insertPost(post);
+    }
+
+    @Override
+    public void deletePost(Long postId) {
+        postMapper.deletePost(postId);
+    }
+
+    @Override
+    public void updatePost(Post post) {
+        postMapper.updatePost(post);
+    }
+
+    @Override
+    public Post getPostById(Long postId) {
+        return postMapper.selectPostById(postId);
+    }
+
+    @Override
+    public List<Post> getAllPosts() {
+        return postMapper.selectAllPosts();
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/edu/bjtu/groupone/backend/service/impl/UserServImpl.java b/src/main/java/edu/bjtu/groupone/backend/service/impl/UserServImpl.java
index 5cdc9c1..ba2f9e9 100644
--- a/src/main/java/edu/bjtu/groupone/backend/service/impl/UserServImpl.java
+++ b/src/main/java/edu/bjtu/groupone/backend/service/impl/UserServImpl.java
@@ -139,4 +139,13 @@
     public List<User> getAllUsers() {
         return userMapper.selectAllUsers();
     }
+    @Override
+    public int getRemainingTasks(int userId) {
+        User user = userMapper.selectUserById(userId);
+        if (user == null) {
+            return -1; // 表示用户不存在
+        }
+        // 假设任务表名为 task,查询未完成的任务数量
+        return userMapper.countRemainingTasks(userId);
+    }
 }
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql
index a36d6ea..53bd187 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema.sql
@@ -23,6 +23,37 @@
                                FOREIGN KEY (`followed_id`) REFERENCES `user`(`user_id`)
 );
 
+-- 新增任务表
+CREATE TABLE `task` (
+                        `task_id` INT AUTO_INCREMENT PRIMARY KEY,
+                        `user_id` INT NOT NULL,
+                        `type` VARCHAR(50) NOT NULL, -- "seed", "post", "comment"
+                        `completed` BOOLEAN NOT NULL DEFAULT FALSE,
+                        FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`)
+);
+
+-- 新增帖子表
+CREATE TABLE `post` (
+                        `post_id` BIGINT AUTO_INCREMENT PRIMARY KEY,
+                        `user_id` INT NOT NULL,
+                        `title` VARCHAR(255) NOT NULL,
+                        `content` TEXT NOT NULL,
+                        `create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+                        `views` INT DEFAULT 0,
+                        FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`)
+);
+
+-- 新增评论表
+CREATE TABLE `comment` (
+                           `comment_id` BIGINT AUTO_INCREMENT PRIMARY KEY,
+                           `post_id` BIGINT NOT NULL,
+                           `user_id` INT NOT NULL,
+                           `content` TEXT NOT NULL,
+                           `create_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+                           FOREIGN KEY (`post_id`) REFERENCES `post`(`post_id`),
+                           FOREIGN KEY (`user_id`) REFERENCES `user`(`user_id`)
+);
+
 -- 插入语句使用反引号包裹表名和列名
 INSERT INTO `user` (
     `username`, `email`, `password`, `registration_date`, `identification_number`, `role`