后端更新
Change-Id: I43c6dd58e1a21aa790357cdaee43477579abdc6d
diff --git a/src/main/java/com/ptp/ptplatform/controller/HelpCommentController.java b/src/main/java/com/ptp/ptplatform/controller/HelpCommentController.java
index 15504be..c937428 100644
--- a/src/main/java/com/ptp/ptplatform/controller/HelpCommentController.java
+++ b/src/main/java/com/ptp/ptplatform/controller/HelpCommentController.java
@@ -1,24 +1,56 @@
package com.ptp.ptplatform.controller;
+import com.ptp.ptplatform.entity.HelpComment;
import com.ptp.ptplatform.service.HelpCommentService;
import com.ptp.ptplatform.utils.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
+import java.time.LocalDateTime;
+import java.util.List;
+
@RestController
@RequestMapping("/help/comments")
@AllArgsConstructor
public class HelpCommentController {
-
private final HelpCommentService commentService;
- /**
- * 点赞评论
- * POST /help/comments/{commentId}/like
- */
@PostMapping("/{commentId}/like")
public Result like(@PathVariable int commentId) {
commentService.incrementLike(commentId);
return Result.ok();
}
+
+ // 获取评论的回复
+ @GetMapping("/{commentId}/replies")
+ public Result getReplies(@PathVariable int commentId) {
+ List<HelpComment> replies = commentService.getReplies(commentId);
+ return Result.ok().data("replies", replies);
+ }
+
+ @PostMapping("/{commentId}/replies")
+ public Result addReply(@PathVariable int commentId,
+ @RequestBody HelpComment reply) {
+ HelpComment parentComment = commentService.getById(commentId);
+ if (parentComment == null) {
+ return Result.error(404).setMessage("被回复的评论不存在");
+ }
+
+ // 设置完整字段
+ reply.setPostId(parentComment.getPostId());
+ reply.setParentId(commentId);
+ reply.setAuthorId(reply.getAuthorId());
+ reply.setReplyTo(parentComment.getAuthorId());
+ reply.setCreateTime(LocalDateTime.now()); // 设置创建时间
+ reply.setLikeCount(0); // 初始化点赞数
+
+ commentService.save(reply);
+
+ // 返回完整的评论数据
+ return Result.ok()
+ .data("reply", reply)
+ .data("parentCommentId", commentId); // 同时返回父评论ID
+ }
+
+
}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/controller/HelpPostController.java b/src/main/java/com/ptp/ptplatform/controller/HelpPostController.java
index 5fb626c..646ed76 100644
--- a/src/main/java/com/ptp/ptplatform/controller/HelpPostController.java
+++ b/src/main/java/com/ptp/ptplatform/controller/HelpPostController.java
@@ -3,16 +3,19 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ptp.ptplatform.entity.HelpComment;
import com.ptp.ptplatform.entity.HelpPost;
-import com.ptp.ptplatform.entity.SeedPost;
import com.ptp.ptplatform.service.HelpCommentService;
import com.ptp.ptplatform.service.HelpPostService;
import com.ptp.ptplatform.utils.Result;
import lombok.AllArgsConstructor;
-import lombok.Data;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
@RestController
@RequestMapping("/help/posts")
@@ -28,56 +31,91 @@
return Result.ok().data("post", post);
}
-
-
// 列表分页
@GetMapping
public Result listPosts(@RequestParam(defaultValue = "1") int page,
- @RequestParam(defaultValue = "10") int size) {
+ @RequestParam(defaultValue = "5") int size) {
IPage<HelpPost> ipage = postService.page(
new Page<>(page, size),
new QueryWrapper<HelpPost>().orderByDesc("create_time")
);
return Result.ok()
.data("records", ipage.getRecords())
- .data("total", ipage.getTotal());
+ .data("total", ipage.getTotal());
}
- // 帖子详情 + 评论
- @GetMapping("/{postId}")
- public Result getPost(@PathVariable int postId) {
- HelpPost post = postService.getById(postId);
- List<HelpComment> comments = commentService.list(
+ @GetMapping("/{Id}")
+ public Result getPost(@PathVariable int Id) {
+ HelpPost post = postService.getById(Id);
+ if (post == null) {
+ return Result.error(404).setMessage("帖子不存在");
+ }
+
+ // 获取所有评论(按创建时间排序)
+ List<HelpComment> allComments = commentService.list(
new QueryWrapper<HelpComment>()
- .eq("post_id", postId)
+ .eq("post_id", Id)
.orderByAsc("create_time")
);
+
+ // 构建评论树形结构
+ List<HelpComment> rootComments = new ArrayList<>();
+ Map<Integer, HelpComment> commentMap = new HashMap<>();
+
+ // 第一遍:初始化所有评论到map中
+ for (HelpComment comment : allComments) {
+ comment.setReplies(new ArrayList<>()); // 初始化replies列表
+ commentMap.put(comment.getId(), comment);
+ }
+
+ // 第二遍:构建父子关系
+ for (HelpComment comment : allComments) {
+ if (comment.getParentId() == 0) {
+ rootComments.add(comment);
+ } else {
+ HelpComment parent = commentMap.get(comment.getParentId());
+ if (parent != null) {
+ parent.getReplies().add(comment);
+ }
+ }
+ }
+
return Result.ok()
- .data("post", post)
- .data("comments", comments);
+ .data("post", post)
+ .data("comments", rootComments);
}
// 点赞帖子
- @PostMapping("/{postId}/like")
- public Result likePost(@PathVariable int postId) {
- postService.incrementLike(postId);
+ @PostMapping("/{Id}/like")
+ public Result likePost(@PathVariable int Id) {
+ postService.incrementLike(Id);
return Result.ok();
}
- // 发布评论
- @PostMapping("/{postId}/comments")
- public Result comment(@PathVariable int postId,
- @RequestBody HelpComment comment) {
- comment.setPostId(postId);
- commentService.save(comment);
- postService.incrementReplyCount(postId);
- return Result.ok()
- .data("commentId", comment.getId());
- }
- @Data
- @AllArgsConstructor
- static class HelpDetailResponse {
- private HelpPost post;
- private List<HelpComment> comments;
+ @PostMapping("/{Id}/comments")
+ public Result comment(@PathVariable int Id,
+ @RequestBody HelpComment comment) {
+ // 设置评论信息
+ comment.setPostId(Id);
+ comment.setCreateTime(LocalDateTime.now());
+ comment.setLikeCount(0); // 初始化点赞数
+ comment.setParentId(0); // 默认父评论ID
+ comment.setReplyTo(null); // 主评论 replyTo=null
+
+ // 保存评论
+ boolean saved = commentService.save(comment);
+ if (!saved) {
+ return Result.error(404).setMessage("评论保存失败");
+ }
+
+ // 更新回复数
+ postService.incrementReplyCount(Id);
+
+ // 获取更新后的完整评论(包含数据库生成的ID和时间)
+ HelpComment newComment = commentService.getById(comment.getId());
+
+ return Result.ok()
+ .data("comment", newComment) // 返回完整评论数据
+ .data("newReplyCount", postService.getById(Id).getReplyCount());
}
}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/controller/SeedCommentController.java b/src/main/java/com/ptp/ptplatform/controller/SeedCommentController.java
deleted file mode 100644
index 635080f..0000000
--- a/src/main/java/com/ptp/ptplatform/controller/SeedCommentController.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.ptp.ptplatform.controller;
-
-import com.ptp.ptplatform.service.SeedCommentService;
-import com.ptp.ptplatform.utils.Result;
-import lombok.AllArgsConstructor;
-import org.springframework.web.bind.annotation.*;
-
-@RestController
-@RequestMapping("/seed/comments")
-@AllArgsConstructor
-public class SeedCommentController {
- private final SeedCommentService commentService;
-
- @PostMapping("/{commentId}/like")
- public Result like(@PathVariable int commentId) {
- commentService.incrementLike(commentId);
- return Result.ok();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/controller/SeedPostController.java b/src/main/java/com/ptp/ptplatform/controller/SeedPostController.java
deleted file mode 100644
index f481b9b..0000000
--- a/src/main/java/com/ptp/ptplatform/controller/SeedPostController.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.ptp.ptplatform.controller;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.ptp.ptplatform.entity.HelpPost;
-import com.ptp.ptplatform.entity.SeedComment;
-import com.ptp.ptplatform.entity.SeedPost;
-import com.ptp.ptplatform.service.SeedCommentService;
-import com.ptp.ptplatform.service.SeedPostService;
-import com.ptp.ptplatform.utils.Result;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import org.springframework.web.bind.annotation.*;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import java.util.List;
-
-@RestController
-@RequestMapping("/seed/posts")
-@AllArgsConstructor
-public class SeedPostController {
- private final SeedPostService postService;
- private final SeedCommentService commentService;
-
- // 创建帖子
- @PostMapping
- public Result createPost(@RequestBody SeedPost post) {
- postService.save(post);
- return Result.ok().data("post", post);
- }
-
-
- // 列表分页
- @GetMapping
- public Result listPosts(@RequestParam(defaultValue = "1") int page,
- @RequestParam(defaultValue = "10") int size) {
- IPage<SeedPost> ipage = postService.page(
- new Page<>(page, size),
- new QueryWrapper<SeedPost>().orderByDesc("create_time")
- );
- return Result.ok()
- .data("records", ipage.getRecords())
- .data("total", ipage.getTotal());
- }
-
- // 帖子详情 + 评论
- @GetMapping("/{postId}")
- public Result getPost(@PathVariable int postId) {
- SeedPost post = postService.getById(postId);
- List<SeedComment> comments = commentService.list(
- new QueryWrapper<SeedComment>()
- .eq("post_id", postId)
- .orderByAsc("create_time")
- );
- return Result.ok()
- .data("post", post)
- .data("comments", comments);
- }
-
- // 点赞帖子
- @PostMapping("/{postId}/like")
- public Result likePost(@PathVariable int postId) {
- postService.incrementLike(postId);
- return Result.ok();
- }
- // 发布评论
- @PostMapping("/{postId}/comments")
- public Result comment(@PathVariable int postId,
- @RequestBody SeedComment comment) {
- comment.setPostId(postId);
- commentService.save(comment);
- postService.incrementReplyCount(postId);
- return Result.ok()
- .data("commentId", comment.getId());
- }
-
- @Data
- @AllArgsConstructor
- static class SeedDetailResponse {
- private SeedPost post;
- private List<SeedComment> comments;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/controller/TorrentCommentController.java b/src/main/java/com/ptp/ptplatform/controller/TorrentCommentController.java
new file mode 100644
index 0000000..1140ff7
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/controller/TorrentCommentController.java
@@ -0,0 +1,55 @@
+package com.ptp.ptplatform.controller;
+
+import com.ptp.ptplatform.entity.TorrentComment;
+import com.ptp.ptplatform.service.TorrentCommentService;
+import com.ptp.ptplatform.utils.Result;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@RestController
+@RequestMapping("/torrent/comments")
+@AllArgsConstructor
+public class TorrentCommentController {
+ private final TorrentCommentService commentService;
+
+ @PostMapping("/{commentId}/like")
+ public Result like(@PathVariable int commentId) {
+ commentService.incrementLike(commentId);
+ return Result.ok();
+ }
+
+ // 获取评论的回复
+ @GetMapping("/{commentId}/replies")
+ public Result getReplies(@PathVariable int commentId) {
+ List<TorrentComment> replies = commentService.getReplies(commentId);
+ return Result.ok().data("replies", replies);
+ }
+
+ @PostMapping("/{commentId}/replies")
+ public Result addReply(@PathVariable int commentId,
+ @RequestBody TorrentComment reply) {
+ TorrentComment parentComment = commentService.getById(commentId);
+ if (parentComment == null) {
+ return Result.error(404).setMessage("被回复的评论不存在");
+ }
+
+ // 设置完整字段
+ reply.setPostId(parentComment.getPostId());
+ reply.setParentId(commentId);
+ reply.setAuthorId(reply.getAuthorId());
+ reply.setReplyTo(parentComment.getAuthorId());
+ reply.setCreateTime(LocalDateTime.now()); // 设置创建时间
+ reply.setLikeCount(0); // 初始化点赞数
+
+ commentService.save(reply);
+
+ // 返回完整的评论数据
+ return Result.ok()
+ .data("reply", reply)
+ .data("parentCommentId", commentId); // 同时返回父评论ID
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/controller/TorrentController.java b/src/main/java/com/ptp/ptplatform/controller/TorrentController.java
new file mode 100644
index 0000000..3c71ba1
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/controller/TorrentController.java
@@ -0,0 +1,121 @@
+package com.ptp.ptplatform.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ptp.ptplatform.entity.TorrentComment;
+import com.ptp.ptplatform.entity.Torrent;
+import com.ptp.ptplatform.service.TorrentCommentService;
+import com.ptp.ptplatform.service.TorrentService;
+import com.ptp.ptplatform.utils.Result;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/torrent")
+@AllArgsConstructor
+public class TorrentController {
+ private final TorrentService postService;
+ private final TorrentCommentService commentService;
+
+ // 创建帖子
+ @PostMapping
+ public Result createTorrent(@RequestBody Torrent torrent) {
+ postService.save(torrent);
+ return Result.ok().data("post", torrent);
+ }
+
+ // 列表分页
+ @GetMapping
+ public Result listPosts(@RequestParam(defaultValue = "1") int page,
+ @RequestParam(defaultValue = "5") int size) {
+ IPage<Torrent> ipage = postService.page(
+ new Page<>(page, size),
+ new QueryWrapper<Torrent>().orderByDesc("create_time")
+ );
+ return Result.ok()
+ .data("records", ipage.getRecords())
+ .data("total", ipage.getTotal());
+ }
+
+ @GetMapping("/{Id}")
+ public Result getPost(@PathVariable int Id) {
+ Torrent torrent = postService.getById(Id);
+ if (torrent == null) {
+ return Result.error(404).setMessage("种子不存在"); // 明确设置404状态码
+ }
+
+ // 获取所有评论(按创建时间排序)
+ List<TorrentComment> allComments = commentService.list(
+ new QueryWrapper<TorrentComment>()
+ .eq("post_id", Id)
+ .orderByAsc("create_time")
+ );
+
+ // 构建评论树形结构
+ List<TorrentComment> rootComments = new ArrayList<>();
+ Map<Integer, TorrentComment> commentMap = new HashMap<>();
+
+ // 第一遍:初始化所有评论到map中
+ for (TorrentComment comment : allComments) {
+ comment.setReplies(new ArrayList<>()); // 初始化replies列表
+ commentMap.put(comment.getId(), comment);
+ }
+
+ // 第二遍:构建父子关系
+ for (TorrentComment comment : allComments) {
+ if (comment.getParentId() == 0) {
+ rootComments.add(comment);
+ } else {
+ TorrentComment parent = commentMap.get(comment.getParentId());
+ if (parent != null) {
+ parent.getReplies().add(comment);
+ }
+ }
+ }
+
+ return Result.ok()
+ .data("torrent", torrent)
+ .data("comments", rootComments);
+ }
+
+ // 点赞帖子
+ @PostMapping("/{Id}/like")
+ public Result likePost(@PathVariable int Id) {
+ postService.incrementLike(Id);
+ return Result.ok();
+ }
+
+ @PostMapping("/{Id}/comments")
+ public Result comment(@PathVariable int Id,
+ @RequestBody TorrentComment comment) {
+ // 设置评论信息
+ comment.setPostId(Id);
+ comment.setCreateTime(LocalDateTime.now());
+ comment.setLikeCount(0); // 初始化点赞数
+ comment.setParentId(0); // 默认父评论ID
+ comment.setReplyTo(null); // 主评论 replyTo=null
+
+ // 保存评论
+ boolean saved = commentService.save(comment);
+ if (!saved) {
+ return Result.error(404).setMessage("评论保存失败");
+ }
+
+ // 更新回复数
+ postService.incrementReplyCount(Id);
+
+ // 获取更新后的完整评论(包含数据库生成的ID和时间)
+ TorrentComment newComment = commentService.getById(comment.getId());
+
+ return Result.ok()
+ .data("comment", newComment) // 返回完整评论数据
+ .data("newReplyCount", postService.getById(Id).getReplyCount());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/controller/UserController.java b/src/main/java/com/ptp/ptplatform/controller/UserController.java
index 0b1dcb2..9265ce7 100644
--- a/src/main/java/com/ptp/ptplatform/controller/UserController.java
+++ b/src/main/java/com/ptp/ptplatform/controller/UserController.java
@@ -42,10 +42,10 @@
String token = JwtUtils.generateToken(user.getUsername());
return Result.ok().data("token", token); // 返回令牌给前端
} else {
- return Result.error().setMessage("密码错误");
+ return Result.error(404).setMessage("密码错误");
}
} else {
- return Result.error().setMessage("用户不存在");
+ return Result.error(404).setMessage("用户不存在");
}
}
@@ -67,15 +67,15 @@
return Result.ok().setMessage("新建用户成功");
} else {
- return Result.error().setMessage("邀请码已经被使用,注册失败");
+ return Result.error(404).setMessage("邀请码已经被使用,注册失败");
}
} else {
- return Result.error().setMessage("邀请码不存在,注册失败");
+ return Result.error(404).setMessage("邀请码不存在,注册失败");
}
} else {
- return Result.error().setMessage("用户名已存在,注册失败");
+ return Result.error(404).setMessage("用户名已存在,注册失败");
}
diff --git a/src/main/java/com/ptp/ptplatform/entity/HelpComment.java b/src/main/java/com/ptp/ptplatform/entity/HelpComment.java
index 405e91d..5821868 100644
--- a/src/main/java/com/ptp/ptplatform/entity/HelpComment.java
+++ b/src/main/java/com/ptp/ptplatform/entity/HelpComment.java
@@ -1,10 +1,13 @@
package com.ptp.ptplatform.entity;
import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
@Data
@TableName("help_comments")
@@ -12,8 +15,22 @@
@TableId(value = "id", type = IdType.AUTO)
private Integer id; // 使用包装类型以支持 null
private Integer postId;
- private Integer authorId;
+ private String authorId;
private String content;
private Integer likeCount;
private LocalDateTime createTime;
+ private Integer parentId; // 新增字段,用于回复功能,0表示主评论,非0表示回复某条评论
+ private String replyTo;
+
+ @TableField(exist = false)
+ private List<HelpComment> replies = new ArrayList<>(); // 必须初始化
+
+ // 确保有getter和setter
+ public List<HelpComment> getReplies() {
+ return replies;
+ }
+
+ public void setReplies(List<HelpComment> replies) {
+ this.replies = replies;
+ }
}
diff --git a/src/main/java/com/ptp/ptplatform/entity/HelpPost.java b/src/main/java/com/ptp/ptplatform/entity/HelpPost.java
index b77fe0b..be0bd02 100644
--- a/src/main/java/com/ptp/ptplatform/entity/HelpPost.java
+++ b/src/main/java/com/ptp/ptplatform/entity/HelpPost.java
@@ -11,7 +11,7 @@
public class HelpPost {
@TableId(value = "id", type = IdType.AUTO)
private Integer id; // 使用包装类型以支持 null
- private Integer authorId;
+ private String authorId;
private String title;
private String content;
private Integer likeCount;
diff --git a/src/main/java/com/ptp/ptplatform/entity/SeedComment.java b/src/main/java/com/ptp/ptplatform/entity/SeedComment.java
deleted file mode 100644
index 48121b5..0000000
--- a/src/main/java/com/ptp/ptplatform/entity/SeedComment.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.ptp.ptplatform.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-import java.time.LocalDateTime;
-
-@Data
-@TableName("seed_comments")
-public class SeedComment {
- @TableId(value = "id", type = IdType.AUTO)
- private Integer id; // 使用包装类型以支持 null
- private Integer postId;
- private Integer authorId;
- private String content;
- private Integer likeCount;
- private LocalDateTime createTime;
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/entity/SeedPost.java b/src/main/java/com/ptp/ptplatform/entity/SeedPost.java
deleted file mode 100644
index b8f74ef..0000000
--- a/src/main/java/com/ptp/ptplatform/entity/SeedPost.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.ptp.ptplatform.entity;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-import java.time.LocalDateTime;
-
-@Data
-@TableName("seed_posts")
-public class SeedPost {
- @TableId(value = "id", type = IdType.AUTO)
- private Integer id; // 使用包装类型以支持 null
- private Integer authorId;
- private String title;
- private String content;
- private Integer likeCount;
- private Integer replyCount;
- private LocalDateTime createTime;
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/entity/Torrent.java b/src/main/java/com/ptp/ptplatform/entity/Torrent.java
new file mode 100644
index 0000000..2c6c6d3
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/entity/Torrent.java
@@ -0,0 +1,39 @@
+package com.ptp.ptplatform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("torrent")
+public class Torrent {
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+
+ @TableField("torrentName") // 明确指定数据库列名
+ private String torrentName;
+
+ private String description;
+ private String category;
+ private String region;
+ private String resolution;
+ private String subtitle;
+ private Long size;
+ private String hash;
+
+ private LocalDateTime createTime;
+
+ private String username;
+
+ @TableField("filePath") // 明确指定数据库列名
+ private String filePath;
+
+ private Integer likeCount;
+ private Integer replyCount;
+
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/entity/TorrentComment.java b/src/main/java/com/ptp/ptplatform/entity/TorrentComment.java
new file mode 100644
index 0000000..d2b4694
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/entity/TorrentComment.java
@@ -0,0 +1,36 @@
+package com.ptp.ptplatform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+@TableName("torrent_comments")
+public class TorrentComment {
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+ private Integer postId;
+ private String authorId;
+ private String content;
+ private Integer likeCount;
+ private LocalDateTime createTime;
+ private Integer parentId;
+ private String replyTo;
+
+ @TableField(exist = false)
+ private List<TorrentComment> replies = new ArrayList<>(); // 必须初始化
+
+ // 确保有getter和setter
+ public List<TorrentComment> getReplies() {
+ return replies;
+ }
+
+ public void setReplies(List<TorrentComment> replies) {
+ this.replies = replies;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/entity/USER.java b/src/main/java/com/ptp/ptplatform/entity/USER.java
index 84e5c33..a33847c 100644
--- a/src/main/java/com/ptp/ptplatform/entity/USER.java
+++ b/src/main/java/com/ptp/ptplatform/entity/USER.java
@@ -2,13 +2,13 @@
// @GeneratedValue(strategy = GenerationType.IDENTITY) 对于一些需要自动生成的主键id进行注解
package com.ptp.ptplatform.entity;
-
import jakarta.persistence.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
+
@Table(name = "user")
public class USER {
diff --git a/src/main/java/com/ptp/ptplatform/mapper/SeedCommentMapper.java b/src/main/java/com/ptp/ptplatform/mapper/SeedCommentMapper.java
deleted file mode 100644
index d72619b..0000000
--- a/src/main/java/com/ptp/ptplatform/mapper/SeedCommentMapper.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.ptp.ptplatform.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.ptp.ptplatform.entity.SeedComment;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-public interface SeedCommentMapper extends BaseMapper<SeedComment> {}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/mapper/SeedPostMapper.java b/src/main/java/com/ptp/ptplatform/mapper/SeedPostMapper.java
deleted file mode 100644
index 134212d..0000000
--- a/src/main/java/com/ptp/ptplatform/mapper/SeedPostMapper.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.ptp.ptplatform.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.ptp.ptplatform.entity.SeedPost;
-import org.apache.ibatis.annotations.Mapper;
-
-@Mapper
-public interface SeedPostMapper extends BaseMapper<SeedPost> {}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/mapper/TorrentCommentMapper.java b/src/main/java/com/ptp/ptplatform/mapper/TorrentCommentMapper.java
new file mode 100644
index 0000000..b330ce6
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/mapper/TorrentCommentMapper.java
@@ -0,0 +1,8 @@
+package com.ptp.ptplatform.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ptp.ptplatform.entity.TorrentComment;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface TorrentCommentMapper extends BaseMapper<TorrentComment> {}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/mapper/TorrentMapper.java b/src/main/java/com/ptp/ptplatform/mapper/TorrentMapper.java
new file mode 100644
index 0000000..ff612b3
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/mapper/TorrentMapper.java
@@ -0,0 +1,8 @@
+package com.ptp.ptplatform.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ptp.ptplatform.entity.Torrent;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface TorrentMapper extends BaseMapper<Torrent> {}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/HelpCommentService.java b/src/main/java/com/ptp/ptplatform/service/HelpCommentService.java
index dcab060..14622ab 100644
--- a/src/main/java/com/ptp/ptplatform/service/HelpCommentService.java
+++ b/src/main/java/com/ptp/ptplatform/service/HelpCommentService.java
@@ -3,6 +3,9 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.ptp.ptplatform.entity.HelpComment;
+import java.util.List;
+
public interface HelpCommentService extends IService<HelpComment> {
void incrementLike(int commentId);
+ List<HelpComment> getReplies(int parentId); // 新增方法
}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/SeedCommentService.java b/src/main/java/com/ptp/ptplatform/service/SeedCommentService.java
deleted file mode 100644
index dec7f16..0000000
--- a/src/main/java/com/ptp/ptplatform/service/SeedCommentService.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.ptp.ptplatform.service;
-
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.ptp.ptplatform.entity.SeedComment;
-
-public interface SeedCommentService extends IService<SeedComment> {
- void incrementLike(int commentId);
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/SeedPostService.java b/src/main/java/com/ptp/ptplatform/service/SeedPostService.java
deleted file mode 100644
index 40605a8..0000000
--- a/src/main/java/com/ptp/ptplatform/service/SeedPostService.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.ptp.ptplatform.service;
-
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.ptp.ptplatform.entity.SeedPost;
-
-public interface SeedPostService extends IService<SeedPost> {
- void incrementLike(int postId);
- void incrementReplyCount(int postId);
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/TorrentCommentService.java b/src/main/java/com/ptp/ptplatform/service/TorrentCommentService.java
new file mode 100644
index 0000000..3b60257
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/service/TorrentCommentService.java
@@ -0,0 +1,11 @@
+package com.ptp.ptplatform.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ptp.ptplatform.entity.TorrentComment;
+
+import java.util.List;
+
+public interface TorrentCommentService extends IService<TorrentComment> {
+ void incrementLike(int commentId);
+ List<TorrentComment> getReplies(int parentId);
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/TorrentService.java b/src/main/java/com/ptp/ptplatform/service/TorrentService.java
new file mode 100644
index 0000000..f3d0222
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/service/TorrentService.java
@@ -0,0 +1,11 @@
+package com.ptp.ptplatform.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ptp.ptplatform.entity.Torrent;
+
+public interface TorrentService extends IService<Torrent> {
+ Torrent getTorrentById(Integer id); // Add this method
+ void incrementLike(int postId);
+ void incrementReplyCount(int postId);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/impl/HelpCommentServiceImpl.java b/src/main/java/com/ptp/ptplatform/service/impl/HelpCommentServiceImpl.java
index dbaed2a..4f47e78 100644
--- a/src/main/java/com/ptp/ptplatform/service/impl/HelpCommentServiceImpl.java
+++ b/src/main/java/com/ptp/ptplatform/service/impl/HelpCommentServiceImpl.java
@@ -1,14 +1,19 @@
package com.ptp.ptplatform.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ptp.ptplatform.entity.HelpComment;
import com.ptp.ptplatform.mapper.HelpCommentMapper;
import com.ptp.ptplatform.service.HelpCommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.util.List;
@Service
-public class HelpCommentServiceImpl extends ServiceImpl<HelpCommentMapper, HelpComment> implements HelpCommentService {
+public class HelpCommentServiceImpl
+ extends ServiceImpl<HelpCommentMapper, HelpComment>
+ implements HelpCommentService {
+
@Override
@Transactional
public void incrementLike(int commentId) {
@@ -18,4 +23,14 @@
.setSql("like_count = like_count + 1")
);
}
+
+ @Override
+ @Transactional(readOnly = true)
+ public List<HelpComment> getReplies(int parentId) {
+ return this.baseMapper.selectList(
+ new QueryWrapper<HelpComment>()
+ .eq("parent_id", parentId)
+ .orderByAsc("create_time")
+ );
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/impl/SeedCommentServiceImpl.java b/src/main/java/com/ptp/ptplatform/service/impl/SeedCommentServiceImpl.java
deleted file mode 100644
index 537194a..0000000
--- a/src/main/java/com/ptp/ptplatform/service/impl/SeedCommentServiceImpl.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.ptp.ptplatform.service.impl;
-
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ptp.ptplatform.entity.SeedComment;
-import com.ptp.ptplatform.mapper.SeedCommentMapper;
-import com.ptp.ptplatform.service.SeedCommentService;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-@Service
-public class SeedCommentServiceImpl extends ServiceImpl<SeedCommentMapper, SeedComment> implements SeedCommentService {
- @Override
- @Transactional
- public void incrementLike(int commentId) {
- this.update(null,
- new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<SeedComment>()
- .eq("id", commentId)
- .setSql("like_count = like_count + 1")
- );
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/impl/TorrentCommentServiceImpl.java b/src/main/java/com/ptp/ptplatform/service/impl/TorrentCommentServiceImpl.java
new file mode 100644
index 0000000..540df71
--- /dev/null
+++ b/src/main/java/com/ptp/ptplatform/service/impl/TorrentCommentServiceImpl.java
@@ -0,0 +1,34 @@
+package com.ptp.ptplatform.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ptp.ptplatform.entity.TorrentComment;
+import com.ptp.ptplatform.mapper.TorrentCommentMapper;
+import com.ptp.ptplatform.service.TorrentCommentService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+public class TorrentCommentServiceImpl extends ServiceImpl<TorrentCommentMapper, TorrentComment> implements TorrentCommentService {
+ @Override
+ @Transactional
+ public void incrementLike(int commentId) {
+ this.update(null,
+ new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<TorrentComment>()
+ .eq("id", commentId)
+ .setSql("like_count = like_count + 1")
+ );
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public List<TorrentComment> getReplies(int parentId) {
+ return this.baseMapper.selectList(
+ new QueryWrapper<TorrentComment>()
+ .eq("parent_id", parentId)
+ .orderByAsc("create_time")
+ );
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/service/impl/SeedPostServiceImpl.java b/src/main/java/com/ptp/ptplatform/service/impl/TorrentServiceImpl.java
similarity index 64%
rename from src/main/java/com/ptp/ptplatform/service/impl/SeedPostServiceImpl.java
rename to src/main/java/com/ptp/ptplatform/service/impl/TorrentServiceImpl.java
index 05cf06c..a6eba54 100644
--- a/src/main/java/com/ptp/ptplatform/service/impl/SeedPostServiceImpl.java
+++ b/src/main/java/com/ptp/ptplatform/service/impl/TorrentServiceImpl.java
@@ -1,19 +1,24 @@
package com.ptp.ptplatform.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ptp.ptplatform.entity.SeedPost;
-import com.ptp.ptplatform.mapper.SeedPostMapper;
-import com.ptp.ptplatform.service.SeedPostService;
+import com.ptp.ptplatform.entity.Torrent;
+import com.ptp.ptplatform.mapper.TorrentMapper;
+import com.ptp.ptplatform.service.TorrentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
-public class SeedPostServiceImpl extends ServiceImpl<SeedPostMapper, SeedPost> implements SeedPostService {
+public class TorrentServiceImpl extends ServiceImpl<TorrentMapper, Torrent> implements TorrentService {
+
+ @Override
+ public Torrent getTorrentById(Integer id) {
+ return this.getById(id); // 直接调用 MyBatis-Plus 提供的 getById 方法
+ }
@Override
@Transactional
public void incrementLike(int postId) {
this.update(null,
- new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<SeedPost>()
+ new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<Torrent>()
.eq("id", postId)
.setSql("like_count = like_count + 1")
);
@@ -23,9 +28,10 @@
@Transactional
public void incrementReplyCount(int postId) {
this.update(null,
- new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<SeedPost>()
+ new com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<Torrent>()
.eq("id", postId)
.setSql("reply_count = reply_count + 1")
);
}
+
}
\ No newline at end of file
diff --git a/src/main/java/com/ptp/ptplatform/utils/Result.java b/src/main/java/com/ptp/ptplatform/utils/Result.java
index 04a3290..0bda7eb 100644
--- a/src/main/java/com/ptp/ptplatform/utils/Result.java
+++ b/src/main/java/com/ptp/ptplatform/utils/Result.java
@@ -44,7 +44,7 @@
return result;
}
- public static Result error() {
+ public static Result error(int i) {
Result result = new Result();
result.setSuccess(false);
result.setCode(resultCode.ERROR);
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 588221c..730af5c 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -15,10 +15,9 @@
# database setting
spring.datasourse.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-spring.datasource.url=jdbc:mysql://localhost:3306/ptpdata?useUnicode=true&characterEncoding=utf8
-spring.datasource.username=root
-#spring.datasource.password=yumu1412
-spring.datasource.password=root
+spring.datasource.url=jdbc:mysql://202.205.102.121:3306/G2ptpdatadevelop?useUnicode=true&characterEncoding=utf8
+spring.datasource.username=team2
+spring.datasource.password=123456
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
# Hibernate properties