注册登录,用户等级,社交,动态,新手任务
Change-Id: I1d3183526517fb3c0dab665e0e7547eefa5c9d76
diff --git a/src/main/java/com/example/myproject/controller/CommentController.java b/src/main/java/com/example/myproject/controller/CommentController.java
new file mode 100644
index 0000000..f8eb135
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/CommentController.java
@@ -0,0 +1,33 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.Comments;
+import com.example.myproject.service.CommentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/forum/posts")
+public class CommentController {
+
+ @Autowired
+ private CommentService commentService;
+
+ // 添加评论
+ @PostMapping("/{post_id}/comments")
+ public String addComment(@PathVariable("post_id") Long postId, @RequestBody Comments comment) {
+ // 添加评论
+ commentService.addComment(postId, comment);
+ return "Comment added successfully!";
+ }
+
+ //获取所有评论
+ @GetMapping("/{post_id}/getAllComments")
+ public List<Map<String, Object>> getCommentsByPostId(@PathVariable("post_id") Long postId) {
+ // 获取评论并填充用户信息
+ return commentService.getCommentsByPostId(postId);
+ }
+
+}
diff --git a/src/main/java/com/example/myproject/controller/DynamicController.java b/src/main/java/com/example/myproject/controller/DynamicController.java
new file mode 100644
index 0000000..db1d0a2
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/DynamicController.java
@@ -0,0 +1,107 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.UserDynamic;
+import com.example.myproject.service.DynamicService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/dynamic")
+public class DynamicController {
+
+ @Autowired
+ private DynamicService dynamicService;
+
+ // 创建好友动态接口
+ @PostMapping("/{user_id}/createDynamic")
+ public Map<String, Object> createDynamic(@PathVariable("user_id") Long userId,
+ @RequestParam(value = "title", required = false) String title,
+ @RequestParam(value = "content") String content,
+ @RequestParam(value = "image_url", required = false) MultipartFile[] imageFiles) {
+ return dynamicService.createDynamic(userId, title, content, imageFiles);
+ }
+
+ //删除好友动态
+ @DeleteMapping("/me/deleteDynamic/{dynamic_id}")
+ public ResponseEntity<String> deleteDynamic(@PathVariable("dynamic_id") Long dynamicId) {
+ dynamicService.deleteDynamic(dynamicId);
+ return ResponseEntity.ok("动态删除成功");
+ }
+
+ //好友动态评论
+ @PostMapping("/{user_id}/feeds/{dynamic_id}/comments")
+ public ResponseEntity<Map<String, Object>> addComment(
+ @PathVariable("user_id") Long userId,
+ @PathVariable("dynamic_id") Long dynamicId,
+ @RequestBody Map<String, String> content) {
+
+ String commentContent = content.get("content"); // 获取评论内容
+ Map<String, Object> response = dynamicService.addComment(userId, dynamicId, commentContent);
+
+ return ResponseEntity.ok(response);
+ }
+
+ //获取某个好友的所有动态
+ @GetMapping("/{user_id}/getAdynamic")
+ public ResponseEntity<Map<String, Object>> getAllUserDynamics(@PathVariable("user_id") Long userId) {
+ Map<String, Object> response = dynamicService.getAllUserDynamics(userId);
+
+ if (response == null || response.isEmpty()) {
+ return ResponseEntity.noContent().build();
+ }
+
+ // 返回响应
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping("/{user_id}/getAllDynamics")
+ public ResponseEntity<Map<String, Object>> getAllUserAndFriendsDynamics(@PathVariable("user_id") Long userId) {
+ // 获取当前用户所有好友的ID
+ List<Long> friendIds = dynamicService.getAllFriendIds(userId);
+ friendIds.add(userId);
+ Map<String, Object> response = dynamicService.getAllUserAndFriendsDynamics(friendIds);
+
+ if (response == null || response.isEmpty()) {
+ return ResponseEntity.noContent().build();
+ }
+
+ return ResponseEntity.ok(response);
+ }
+
+ //点赞好友动态
+ @PostMapping("/like")
+ public ResponseEntity<String> likeDynamic(@RequestBody Map<String, Long> request) {
+ Long userId = request.get("userId");
+ Long dynamicId = request.get("dynamicId");
+ // 执行点赞
+ boolean success = dynamicService.likeDynamic(userId, dynamicId);
+
+ if (success) {
+ return ResponseEntity.ok("Like successful");
+ } else {
+ return ResponseEntity.badRequest().body("Like failed");
+ }
+ }
+
+ @DeleteMapping("/unlike")
+ public ResponseEntity<String> unlikeDynamic(@RequestBody Map<String, Long> request) {
+ Long userId = request.get("userId");
+ Long dynamicId = request.get("dynamicId");
+
+ // 执行取消点赞
+ boolean success = dynamicService.unlikeDynamic(userId, dynamicId);
+
+ if (success) {
+ return ResponseEntity.ok("Unlike successful");
+ } else {
+ return ResponseEntity.badRequest().body("Unlike failed");
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/example/myproject/controller/GroupController.java b/src/main/java/com/example/myproject/controller/GroupController.java
new file mode 100644
index 0000000..a0830b6
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/GroupController.java
@@ -0,0 +1,105 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.Group;
+import com.example.myproject.entity.GroupComments;
+import com.example.myproject.service.GroupService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/groups")
+public class GroupController {
+
+ @Autowired
+ private GroupService groupService;
+
+ @PostMapping("/createGroup")
+ public ResponseEntity<Map<String, Object>> createGroup(@RequestBody Group groupRequest) {
+ // 调用服务层方法创建小组
+ System.out.println("Received group name: " + groupRequest.getGroupName());
+ return groupService.createGroup(groupRequest);
+ }
+
+
+ // 加入小组接口
+ @PostMapping("/{group_id}/join")
+ public ResponseEntity<Map<String, Object>> joinGroup(@PathVariable("group_id") Long groupId,
+ @RequestBody Map<String, Long> requestBody) {
+ Long userId = requestBody.get("user_id");
+ return groupService.joinGroup(groupId, userId);
+ }
+
+ // 退出小组接口
+ @PostMapping("/{group_id}/leave")
+ public ResponseEntity<Map<String, Object>> leaveGroup(@PathVariable("group_id") Long groupId,
+ @RequestBody Map<String, Long> requestBody) {
+ Long userId = requestBody.get("user_id");
+ return groupService.leaveGroup(groupId, userId);
+ }
+
+ // 获取小组成员接口
+ @GetMapping("/{group_id}/members")
+ public ResponseEntity<Map<String, Object>> getGroupMembers(@PathVariable("group_id") Long groupId) {
+ return groupService.getGroupMembers(groupId);
+ }
+
+ //发布帖子
+ @PostMapping("/{group_id}/createPost")
+ public ResponseEntity<Map<String, Object>> createPost(
+ @PathVariable("group_id") Long groupId,
+ @RequestParam("user_id") Long userId,
+ @RequestParam("content") String content,
+ @RequestParam("title") String title,
+ @RequestParam(value = "images", required = false) MultipartFile[] imageFiles) {
+
+ Map<String, Object> response = groupService.createPost(groupId, userId, content, title, imageFiles);
+ return ResponseEntity.ok(response);
+ }
+
+ //获取某个小组内的所有帖子
+ @GetMapping("/{group_id}/getAllPosts")
+ public ResponseEntity<Map<String, Object>> getAllPosts(@PathVariable("group_id") Long groupId) {
+ Map<String, Object> response = groupService.getAllPosts(groupId);
+ return ResponseEntity.ok(response);
+ }
+
+ //获取所有小组名称
+ @PostMapping("/getAllGroups")
+ public ResponseEntity<Map<String, Object>> searchGroups(@RequestBody Map<String, Object> params) {
+ Map<String, Object> response = groupService.searchGroups(params);
+ return ResponseEntity.ok(response);
+ }
+
+ // 点赞帖子
+ @PostMapping("/{group_post_id}/like")
+ public ResponseEntity<Map<String, Object>> likePost(
+ @PathVariable("group_post_id") Long groupPostId) {
+ Map<String, Object> response = groupService.likePost(groupPostId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 取消点赞
+ @PostMapping("/{group_post_id}/unlike")
+ public ResponseEntity<Map<String, Object>> unlikePost(
+ @PathVariable("group_post_id") Long groupPostId) {
+ Map<String, Object> response = groupService.unlikePost(groupPostId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 添加评论接口
+ @PostMapping("/{group_post_id}/comment")
+ public ResponseEntity<Map<String, Object>> addComment(
+
+ @PathVariable("group_post_id") Long postId,
+ @RequestBody GroupComments comment) {
+
+ Map<String, Object> response = groupService.addComment(postId, comment);
+ return ResponseEntity.ok(response);
+ }
+
+}
diff --git a/src/main/java/com/example/myproject/controller/LevelController.java b/src/main/java/com/example/myproject/controller/LevelController.java
new file mode 100644
index 0000000..8781246
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/LevelController.java
@@ -0,0 +1,42 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.service.LevelService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RequestMapping("/echo/level")
+@RestController
+public class LevelController {
+
+ @Autowired
+ private LevelService levelService;
+
+ @GetMapping("/getExperience")
+ public Map<String, Object> getExperience(@RequestParam Long user_id) {
+ return levelService.getUserExperience(user_id);
+ }
+
+ @PostMapping("/updateExperience")
+ public Map<String, Object> updateExperience(@RequestBody Map<String, Object> params) {
+ Long userId = Long.valueOf(params.get("user_id").toString());
+ Integer experience = Integer.valueOf(params.get("experience").toString());
+ String source = params.get("source").toString();
+
+ return levelService.updateExperience(userId, experience, source);
+ }
+
+ // 检查用户是否满足升级条件
+ @GetMapping("/upgrade-check")
+ public Map<String, Object> checkUpgrade(@RequestParam Long user_id) {
+ return levelService.checkUpgrade(user_id);
+ }
+
+ @PostMapping("/upgrades")
+ public Map<String, Object> upgradeUserLevel(@RequestBody Map<String, Object> request) {
+ Long userId = Long.valueOf(request.get("user_id").toString());
+ Boolean canUpgrade = (Boolean) request.get("can_upgrade");
+ return levelService.upgradeUserLevel(userId, canUpgrade);
+ }
+}
diff --git a/src/main/java/com/example/myproject/controller/PostController.java b/src/main/java/com/example/myproject/controller/PostController.java
new file mode 100644
index 0000000..4233028
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/PostController.java
@@ -0,0 +1,100 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.Post;
+import com.example.myproject.service.PostService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+@RestController
+@RequestMapping("/echo/forum/posts")
+public class PostController {
+
+ @Autowired
+ private PostService postService;
+
+ //创建新帖子(已完成)
+ @PostMapping("/{user_id}/createPost")
+ public Map<String, Object> createPost(
+ @PathVariable("user_id") Long userId,
+ @RequestParam(value = "postContent") String postContent,
+ @RequestParam(value = "title", required = false) String title,
+ @RequestParam(value = "imageUrl") MultipartFile[] imageFiles) {
+ return postService.createPost(userId, postContent, title, imageFiles);
+ }
+
+ //编辑帖子(已完成)
+ @PutMapping("/{post_id}/editPost")
+ public String updatePost(@PathVariable("post_id") Long postId, @RequestBody Post post) {
+ postService.updatePost(postId, post);
+ return "Post updated successfully!";
+ }
+
+ //删除帖子(已完成)
+ @DeleteMapping("/{post_id}/deletePost")
+ public String deletePost(@PathVariable("post_id") Long postId) {
+ postService.deletePost(postId);
+ return "Post deleted successfully!";
+ }
+
+ //点赞帖子(已完成)
+ @PostMapping("/{post_id}/like")
+ public String likePost(@PathVariable("post_id") Long postId, @RequestBody Map<String, Long> requestBody) {
+
+ Long userId = requestBody.get("user_id");
+ postService.likePost(postId, userId);
+
+ return "Post liked successfully!";
+ }
+
+ //取消点赞(已完成)
+ @PostMapping("/{post_id}/unlike")
+ public String unlikePost(@PathVariable("post_id") Long postId, @RequestBody Map<String, Long> requestBody) {
+ Long userId = requestBody.get("user_id");
+ postService.unlikePost(postId, userId);
+
+ return "Post unliked successfully!";
+ }
+
+ //获取帖子列表(已完成)
+ @GetMapping("/getAllPosts")
+ public Map<String, Object> getAllPosts() {
+ return postService.getAllPosts(); // 调用服务层的 getAllPosts 方法
+ }
+
+ @GetMapping("/{postId}/getPost")
+ public Map<String, Object> getPostById(@PathVariable Long postId) {
+ return postService.getPostById(postId);
+ }
+
+
+ //收藏帖子(已完成)
+ @PostMapping("/{post_id}/collect")
+ public String collectPost(@PathVariable("post_id") Long postId, @RequestBody Map<String, Long> requestBody) {
+ Long userId = requestBody.get("user_id");
+ postService.collectPost(postId, userId);
+
+ return "Post collected successfully!";
+ }
+
+
+ //取消收藏(已完成)
+ @DeleteMapping("/{post_id}/uncollect")
+ public String uncollectPost(@PathVariable("post_id") Long postId, @RequestBody Map<String, Long> requestBody) {
+ Long userId = requestBody.get("user_id");
+ postService.uncollectPost(postId, userId);
+ return "Post uncollected successfully!";
+ }
+
+ // 获取用户收藏的所有帖子
+ @GetMapping("/{userId}/getAllcollections")
+ public List<Map<String, Object>> getAllCollections(@PathVariable("userId") Long userId) {
+ return postService.getAllCollections(userId);
+ }
+
+
+}
diff --git a/src/main/java/com/example/myproject/controller/SeedCommentController.java b/src/main/java/com/example/myproject/controller/SeedCommentController.java
new file mode 100644
index 0000000..344b56c
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/SeedCommentController.java
@@ -0,0 +1,39 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.SeedComment;
+import com.example.myproject.service.SeedCommentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/seeds")
+public class SeedCommentController {
+
+ @Autowired
+ private SeedCommentService seedCommentService;
+
+ @PostMapping("/{seed_id}/comments")
+ public String publishComment(@PathVariable("seed_id") int seedId,
+ @RequestBody SeedComment seedComment) {
+ // 调用服务类的逻辑处理评论发布
+ return seedCommentService.publishComment(seedId, seedComment);
+ }
+
+ @GetMapping("/{seed_id}/getAllComments")
+ public Map<String, Object> getAllComments(@PathVariable("seed_id") int seedId) {
+ // 调用服务层获取所有评论数据
+ return seedCommentService.getAllCommentsForSeed(seedId);
+ }
+
+ // 点赞切换接口
+ @PutMapping("/{comment_id}/like-toggle")
+ public Map<String, Object> toggleLike(@PathVariable("comment_id") Long commentId,
+ @RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ return seedCommentService.toggleLike(commentId, userId);
+ }
+
+
+}
diff --git a/src/main/java/com/example/myproject/controller/TaskController.java b/src/main/java/com/example/myproject/controller/TaskController.java
new file mode 100644
index 0000000..ab4b7ea
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/TaskController.java
@@ -0,0 +1,67 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.service.TaskService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/task/tutorial")
+public class TaskController {
+
+ @Autowired
+ private TaskService taskService;
+
+ @GetMapping("/getAllTasks")
+ public Map<String, Object> getAllTasks(@RequestParam("user_id") Long userId) {
+ return taskService.getAllTasksForUser(userId);
+ }
+
+
+ @PostMapping("/updateStatus")
+ public Map<String, Object> updateTaskStatus(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ String taskId = request.get("task_id").toString();
+ return taskService.updateTaskStatus(userId, taskId);
+ }
+
+ //获取当前经验和任务奖励
+ @GetMapping("/getExperience")
+ public Map<String, Object> getExperience(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ return taskService.getUserExperience(userId);
+ }
+
+ //获取当前的指引步骤
+ @GetMapping("/getNewStep")
+ public Map<String, Object> getNewStep(@RequestParam("user_id") Long userId) {
+ return taskService.getNewStep(userId);
+ }
+
+
+ //更新进度
+ @PostMapping("/updateProgress")
+ public Map<String, Object> updateProgress(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ String taskId = request.get("task_id").toString();
+ Integer progress = Integer.parseInt(request.get("progress").toString());
+ return taskService.updateTaskProgress(userId, taskId, progress);
+ }
+
+ //领取任务奖励
+ @PostMapping("/rewardClaim")
+ public Map<String, Object> rewardClaim(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ String taskId = request.get("task_id").toString();
+ return taskService.claimReward(userId, taskId);
+ }
+
+ //检查任务奖励状态
+ @PostMapping("/rewardReview")
+ public Map<String, Object> rewardReview(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ String taskId = request.get("task_id").toString();
+ return taskService.checkRewardStatus(userId, taskId);
+ }
+}
diff --git a/src/main/java/com/example/myproject/controller/TorrentController.java b/src/main/java/com/example/myproject/controller/TorrentController.java
deleted file mode 100644
index cea2ccf..0000000
--- a/src/main/java/com/example/myproject/controller/TorrentController.java
+++ /dev/null
@@ -1,293 +0,0 @@
-package com.example.myproject.controller;
-
-import com.example.myproject.common.base.PageUtil;
-import com.example.myproject.entity.TorrentEntity;
-import com.example.myproject.service.TorrentService;
-import com.example.myproject.service.PromotionService;
-import com.example.myproject.dto.param.TorrentParam;
-import com.example.myproject.dto.vo.TorrentVO;
-import com.example.myproject.common.base.Result;
-import com.example.myproject.dto.param.TorrentUploadParam;
-import com.example.myproject.dto.TorrentUpdateDTO;
-import com.example.myproject.dto.PromotionCreateDTO;
-import com.example.myproject.entity.Promotion;
-import com.example.myproject.service.UserService;
-
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.List;
-
-import cn.dev33.satoken.annotation.SaCheckLogin;
-import cn.dev33.satoken.stp.StpUtil;
-
-@RestController
-@RequestMapping("/seeds")
-public class TorrentController {
-
- @Autowired
- private TorrentService torrentService;
-
- @Autowired
- private PromotionService promotionService;
-
- @Autowired
- private UserService userService;
-
-
- @SaCheckLogin
- @Operation(summary = "种子列表查询", description = "种子列表条件查询-分页-排序")
- @ApiResponse(responseCode = "0", description = "操作成功",
- content = {@Content(mediaType = "application/json",
- schema = @Schema(implementation = TorrentVO.class))
- })
- @PostMapping("/list")
- public Result list(@RequestBody TorrentParam param) {
- // 构建排序和模糊查询条件
- param.validOrder(param.getOrderKey(TorrentEntity.class));
- param.buildLike();
-
- PageUtil.startPage(param);
-
- // 查询数据
- List<TorrentEntity> list = torrentService.search(param);
-
- // 返回分页结果
- return Result.ok(list, PageUtil.getPage(list));
- }
-
- @SaCheckLogin
- @Operation(summary = "种子详情查询")
- @ApiResponse(responseCode = "0", description = "操作成功", content = {
- @Content(mediaType = "application/json", schema = @Schema(implementation =
- TorrentEntity.class))
- })
- @PostMapping("/info/{id}")
- public Result info(@PathVariable("id")Long id) {
-
- TorrentEntity entity = torrentService.selectBySeedId(id);
- return Result.ok(entity);
- }
-
-@Operation(summary = "上传种子")
-
- @PostMapping("/upload")
- public Result uploadTorrent(
- @RequestParam("file") MultipartFile file,
- @ModelAttribute @Validated TorrentUploadParam param) throws IOException {
- try {
- // 验证用户权限
- // Long userId = StpUtil.getLoginIdAsLong();
- String userId = String.valueOf(param.getUploader());
- param.setUploader(userId);
-
- // 验证文件大小和类型
- if (file.isEmpty() || file.getSize() > 10 * 1024 * 1024) { // 10MB限制
- return Result.error("文件大小不符合要求");
- }
-
- if (!file.getOriginalFilename().toLowerCase().endsWith(".torrent")) {
- return Result.error("只支持.torrent文件");
- }
-
- torrentService.uploadTorrent(file, param);
- return Result.ok();
- } catch (Exception e) {
- return Result.error("种子上传失败: " + e.getMessage());
- }
- }
-
- /**
- * 获取种子文件
- */
- @GetMapping("/{seed_id}/download")
- public void downloadTorrent(
- @PathVariable("seed_id") Long seedId,
- @RequestParam("passkey") String passkey,
- HttpServletResponse response) throws IOException {
-
- // 获取种子实体
- TorrentEntity entity = torrentService.selectBySeedId(seedId);
- if (entity == null) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND, "种子不存在");
- return;
- }
-
- // 获取并处理种子文件内容(需在service中实现passkey注入)
- byte[] torrentBytes = torrentService.fetch(seedId, passkey);
-
- // 设置下载文件名
- String filename = entity.getFileName();
- if (filename == null || filename.isBlank()) {
- filename = seedId + ".torrent";
- }
- if (!filename.toLowerCase().endsWith(".torrent")) {
- filename = filename + ".torrent";
- }
- filename = java.net.URLEncoder.encode(filename, java.nio.charset.StandardCharsets.UTF_8).replaceAll("\\+",
- "%20");
-
- // 设置响应头
- response.setCharacterEncoding(java.nio.charset.StandardCharsets.UTF_8.name());
- response.setContentLength(torrentBytes.length);
- response.setContentType("application/x-bittorrent");
- response.setHeader("Content-Disposition", "attachment;filename=" + filename);
-
- // 写入文件内容
- response.getOutputStream().write(torrentBytes);
- response.getOutputStream().flush();
- }
-
- /**
- * 收藏或者取消收藏
- */
- @PostMapping("/{seed_id}/favorite-toggle")
- public Result favorite(
- @PathVariable("seed_id") Long seedId,
- @RequestParam("user_id") Long userId) {
- try {
-
- return torrentService.favorite(seedId, userId);
- } catch (Exception e) {
- return Result.error("失败: ");
- }
- }
-
- @SaCheckLogin
- @Operation(summary = "删除种子")
- @DeleteMapping("/{torrentId}")
- public Result deleteTorrent(@PathVariable Long torrentId) {
- try {
- // 验证用户权限
- Long userId = StpUtil.getLoginIdAsLong();
- if (!torrentService.canUserDeleteTorrent(torrentId, userId)) {
- return Result.error("没有权限删除此种子");
- }
-
- torrentService.deleteTorrent(torrentId);
- return Result.ok();
- } catch (Exception e) {
- return Result.error("删除失败: " + e.getMessage());
- }
- }
-
- @SaCheckLogin
- @Operation(summary = "修改种子信息")
- @PutMapping("/{torrentId}")
- public Result updateTorrent(
- @PathVariable Long torrentId,
- @RequestBody @Validated TorrentUpdateDTO updateDTO) {
- try {
- // 验证用户权限
- Long userId = StpUtil.getLoginIdAsLong();
- if (!torrentService.canUserUpdateTorrent(torrentId, userId)) {
- return Result.error("没有权限修改此种子");
- }
-
- torrentService.updateTorrent(torrentId, updateDTO);
- return Result.ok();
- } catch (Exception e) {
- return Result.error("更新失败: " + e.getMessage());
- }
- }
-
- @SaCheckLogin
- @Operation(summary = "创建促销活动")
- @PostMapping("/promotions")
- public Result createPromotion(@RequestBody @Validated PromotionCreateDTO promotionDTO) {
- try {
- // 验证用户权限(只有管理员可以创建促销)
-// if (!StpUtil.hasRole("admin")) {
-// return Result.error("没有权限创建促销活动");
-// }
-//
- Promotion promotion = promotionService.createPromotion(promotionDTO);
- return Result.ok(promotion);
- } catch (Exception e) {
- return Result.error("创建促销失败: " + e.getMessage());
- }
- }
-
- @SaCheckLogin
- @Operation(summary = "获取促销活动列表")
- @GetMapping("/promotions")
- public Result getPromotions() {
- try {
- List<Promotion> promotions = promotionService.getAllActivePromotions();
- return Result.ok(promotions);
- } catch (Exception e) {
- return Result.error("获取促销列表失败: " + e.getMessage());
- }
- }
-
- @SaCheckLogin
- @Operation(summary = "获取促销详情")
- @GetMapping("/promotions/{promotionId}")
- public Result getPromotionDetails(@PathVariable Long promotionId) {
- try {
- Promotion promotion = promotionService.getPromotionById(promotionId);
- if (promotion == null) {
- return Result.error("促销活动不存在");
- }
- return Result.ok(promotion);
- } catch (Exception e) {
- return Result.error("获取促销详情失败: " + e.getMessage());
- }
- }
-
- @SaCheckLogin
- @Operation(summary = "删除促销活动")
- @DeleteMapping("/promotions/{promotionId}")
- public Result deletePromotion(@PathVariable Long promotionId) {
- try {
- // 验证用户权限(只有管理员可以删除促销)
- if (!StpUtil.hasRole("admin")) {
- return Result.error("没有权限删除促销活动");
- }
-
- promotionService.deletePromotion(promotionId);
- return Result.ok();
- } catch (Exception e) {
- return Result.error("删除促销失败: " + e.getMessage());
- }
- }
-
- // 下载种子(包含反作弊机制)
- @PostMapping("/{torrentId}/download")
- public ResponseEntity<?> downloadTorrent(@PathVariable Long torrentId,
- @RequestParam Long userId) {
-// // 验证用户身份和权限
-// if (!userService.validateUser(userId)) {
-// return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
-// }
-
- // 检查用户上传量是否足够
- if (!torrentService.checkUserUploadRatio(userId)) {
- return ResponseEntity.status(HttpStatus.FORBIDDEN)
- .body("上传量不足,无法下载");
- }
-
- // 应用促销折扣(如果有)
- double downloadSize = torrentService.calculateDownloadSize(torrentId, userId);
-
- // 记录下载
- torrentService.recordDownload(torrentId, userId, downloadSize);
-
- return ResponseEntity.ok().build();
- }
-
-
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/example/myproject/controller/UserController.java b/src/main/java/com/example/myproject/controller/UserController.java
index acda403..e96df8f 100644
--- a/src/main/java/com/example/myproject/controller/UserController.java
+++ b/src/main/java/com/example/myproject/controller/UserController.java
@@ -1,190 +1,122 @@
package com.example.myproject.controller;
-import cn.dev33.satoken.annotation.SaCheckLogin;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.example.myproject.common.base.PageUtil;
-import com.example.myproject.dto.param.TorrentParam;
-import com.example.myproject.dto.vo.TorrentVO;
-import com.example.myproject.entity.TorrentEntity;
-import com.example.myproject.mapper.UserMapper;
-import com.example.myproject.mapper.VerificationTokenMapper;
-import com.example.myproject.entity.User;
-import com.example.myproject.entity.VerificationToken;
-import com.example.myproject.service.EmailService;
+import com.example.myproject.entity.Users;
+import com.example.myproject.repository.UserRepository;
+import com.example.myproject.service.TaskService;
import com.example.myproject.service.UserService;
-import com.example.myproject.common.base.Result;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
-import javax.annotation.Resource;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
-import java.util.List;
+import java.util.Map;
+import java.util.Optional;
@RestController
-@RequestMapping("/user")
-@Api(value = "用户管理接口", tags = {"用户管理"})
+@RequestMapping("/echo/user")
public class UserController {
- @Resource
+ @Autowired
private UserService userService;
@Autowired
- private AuthenticationManager authenticationManager;
+ private UserRepository userRepository;
- @Autowired
- private UserMapper userMapper; // 使用 MyBatis-Plus
-
- @Autowired
- private VerificationTokenMapper verificationTokenMapper; // 替换 JPA
-
- private static final Logger logger = LoggerFactory.getLogger(UserController.class);
-
- @PostMapping("/login")
- @ApiOperation(value = "用户登录", notes = "使用用户名和密码进行登录")
- public Result loginController(@RequestParam @ApiParam(value = "用户名", required = true) String username,
- @RequestParam @ApiParam(value = "密码", required = true) String password) {
- try {
- Authentication authentication = authenticationManager.authenticate(
- new UsernamePasswordAuthenticationToken(username, password)
- );
- SecurityContextHolder.getContext().setAuthentication(authentication);
-
- // 使用 MyBatis-Plus 查询
- User user = userMapper.selectOne(new QueryWrapper<User>().eq("username", username));
-
- System.out.println("Login successful for user: " + username);
- return Result.ok(user);
- } catch (AuthenticationException e) {
- return Result.error("登录失败");
- }
+ // 接口:生成邀请码
+ @PostMapping("/getInviteCode")
+ public Map<String, Object> generateInviteCode(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ return userService.generateInviteCode(userId);
}
+ //注册
@PostMapping("/register")
- @ApiOperation(value = "用户注册", notes = "使用用户信息进行注册")
- public Result registerController(@RequestBody @ApiParam(value = "新用户信息", required = true) User newUser) {
- if (userService.checkEmailExists(newUser.getEmail())) {
- return Result.error( "邮箱已被使用,请使用其他邮箱注册或找回密码!");
- }
- boolean success = userService.preRegisterUser(newUser);
- if (success) {
- User responseUser = new User();
- responseUser.setEmail(newUser.getEmail());
- return Result.ok();
+ public Map<String, Object> register(@RequestBody Map<String, Object> request) {
+ String username = (String) request.get("username");
+ String email = (String) request.get("email");
+ String password = (String) request.get("password");
+ String role = (String) request.get("role");
+ String inviteCode = (String) request.get("inviteCode");
+
+ // 调用服务层的注册方法
+ String resultMessage = userService.registerUser(username, email, password, role, inviteCode);
+
+ // 返回注册结果
+ return Map.of("msg", resultMessage);
+ }
+
+ //登录
+ @PostMapping("/login")
+ public Map<String, Object> login(@RequestBody Map<String, Object> request) {
+ String username = (String) request.get("username");
+ String password = (String) request.get("password");
+
+ // 调用服务层的登录方法
+ String resultMessage = userService.loginUser(username, password);
+
+ // 根据登录结果返回不同的响应
+ if (resultMessage.equals("登录成功")) {
+ // 查询用户信息
+ Optional<Users> user = userRepository.findByUsername(username);
+ if (user.isPresent()) {
+ // 将用户的所有信息作为返回值
+ return Map.of("msg", resultMessage, "user", user.get());
+ } else {
+ return Map.of("msg", "用户信息查询失败");
+ }
} else {
- return Result.error("账号已存在或注册失败!");
+ return Map.of("msg", resultMessage);
}
}
- public static class VerificationRequest {
- private String email;
- private String code;
+ //修改密码
+ @PostMapping("/password")
+ public Map<String, Object> changePassword(@RequestBody Map<String, Object> request) {
+ Long userId = Long.parseLong(request.get("user_id").toString());
+ String oldPassword = (String) request.get("old_password");
+ String newPassword = (String) request.get("new_password");
+ String confirmPassword = (String) request.get("confirm_password");
- public String getEmail() { return email; }
- public void setEmail(String email) { this.email = email; }
- public String getCode() { return code; }
- public void setCode(String code) { this.code = code; }
+ // 调用服务层的修改密码方法
+ String resultMessage = userService.changePassword(userId, oldPassword, newPassword, confirmPassword);
+
+ // 返回修改结果
+ return Map.of("message", resultMessage, "status", resultMessage.equals("密码修改成功") ? "success" : "error");
}
- @PostMapping("/verify-code")
- @ApiOperation(value = "验证邮箱验证码", notes = "验证用户邮箱的验证码")
- public Result verifyEmailCode(@RequestBody @ApiParam(value = "验证请求信息", required = true) VerificationRequest verificationRequest) {
- String email = verificationRequest.getEmail();
- String code = verificationRequest.getCode();
- boolean isVerified = userService.verifyEmail(email, code);
- if (isVerified) {
- return Result.ok();
+ // 获取用户个人资料
+ @GetMapping("/{userId}/getProfile")
+ public Map<String, Object> getProfile(@PathVariable("userId") Long userId) {
+ return userService.getProfile(userId);
+ }
+
+ // 修改用户个人资料
+ @PutMapping("/{userId}/editProfile")
+ public Map<String, String> editProfile(
+ @PathVariable("userId") Long userId,
+ @RequestBody Map<String, Object> profileData) {
+
+ // 获取请求体中的修改数据
+ String avatarUrl = (String) profileData.get("avatarUrl");
+ String nickname = (String) profileData.get("nickname");
+ String gender = (String) profileData.get("gender");
+ String description = (String) profileData.get("description");
+ String hobbies = (String) profileData.get("hobbies");
+
+ // 调用服务层方法进行修改
+ boolean updated = userService.editProfile(userId, avatarUrl, nickname, gender, description, hobbies);
+
+ // 返回操作结果消息
+ if (updated) {
+ return Map.of("message", "用户资料更新成功");
} else {
- return Result.error( "验证码错误或已过期!");
+ return Map.of("message", "用户不存在");
}
}
- @Autowired
- private EmailService emailService;
-
- public static class EmailRequest {
- private String email;
- public String getEmail() { return email; }
- public void setEmail(String email) { this.email = email; }
+ // 计算分享率
+ @GetMapping("/{user_id}/calculate-share-rate")
+ public Map<String, Object> calculateShareRate(@PathVariable("user_id") Long userId) {
+ return userService.calculateShareRate(userId);
}
- @PostMapping("/get-verification-email")
- @ApiOperation(value = "发送验证邮件", notes = "通过电子邮件发送验证邮件")
- public ResponseEntity<Result> sendVerificationEmail(@RequestBody @ApiParam(value = "发送验证请求", required = true) EmailRequest emailVerificationRequest) {
- String email = emailVerificationRequest.getEmail();
- User user = userMapper.selectOne(new QueryWrapper<User>().eq("email", email));
- if (user == null) {
- logger.error("未找到与该邮箱地址相关联的用户: {}", email);
- return ResponseEntity.status(HttpStatus.BAD_REQUEST)
- .body(Result.error("未找到与该邮箱地址相关联的用户"));
- }
-
- // 生成验证码
- String token = RandomStringUtils.randomNumeric(6);
- Instant expiryDate = Instant.now().plus(1, ChronoUnit.HOURS);
- logger.info("生成的验证令牌: {}, 过期时间: {}", token, expiryDate);
-
- VerificationToken verificationToken = new VerificationToken(token, user.getUsername(), email, user.getPassword(), expiryDate);
-
- // 保存到 MyBatis-Plus 数据库
- verificationTokenMapper.insert(verificationToken);
-
- logger.info("验证令牌已保存,用户: {}", user.getUsername());
- emailService.sendVerificationEmail(email, token);
-
- return ResponseEntity.ok(Result.ok());
- }
- @PostMapping("/checkPassword")
- public Result<String> checkPassword(@RequestParam Long userId, @RequestParam String password) {
- boolean isPasswordCorrect = userService.checkPassword(userId, password);
- if (isPasswordCorrect) {
- return Result.ok();
- } else {
- return Result.error("原始密码输入错误");
- }
- }
-
-
-// @SaCheckLogin
-// @Operation(summary = "用户收藏列表", description = "获取用户收藏的种子列表-分页-排序")
-// @ApiResponse(responseCode = "0", description = "操作成功",
-// content = {@Content(mediaType = "application/json",
-// schema = @Schema(implementation = TorrentVO.class))
-// })
-// @PostMapping("/favorite/list")
-// public Result listFavorites(@RequestBody FavoriteParam param) {
-// if (param.getUserId() == null) {
-// return Result.error("缺少 userId");
-// }
-//
-// // 校验排序字段是否合理(可选)
-// param.validOrder(param.getOrderKey(TorrentEntity.class));
-//
-// PageUtil.startPage(param);
-//
-// List<TorrentEntity> list = favoriteService.getUserFavoritesPaged(param.getUserId());
-//
-// return Result.ok(list, PageUtil.getPage(list));
-// }
-//
-
-
}
diff --git a/src/main/java/com/example/myproject/controller/UserFollowController.java b/src/main/java/com/example/myproject/controller/UserFollowController.java
new file mode 100644
index 0000000..f550beb
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/UserFollowController.java
@@ -0,0 +1,47 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.service.UserFollowService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/users")
+public class UserFollowController {
+
+ @Autowired
+ private UserFollowService userFollowService;
+
+ // 用户关注接口
+ @PostMapping("/{followed_id}/follow")
+ public ResponseEntity<Map<String, Object>> follow(@PathVariable("followed_id") Long followedId,
+ @RequestBody Map<String, Long> request) {
+ Long followerId = request.get("follower_id");
+ Map<String, Object> response = userFollowService.follow(followerId, followedId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 取消关注接口
+ @PostMapping("/{followed_id}/unfollow")
+ public ResponseEntity<Map<String, Object>> unfollow(@PathVariable("followed_id") Long followedId,
+ @RequestBody Map<String, Long> request) {
+ Long followerId = request.get("follower_id");
+ Map<String, Object> response = userFollowService.unfollow(followerId, followedId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 获取某个用户的粉丝列表
+ @GetMapping("/{user_id}/followers")
+ public ResponseEntity<Map<String, Object>> getFollowers(@PathVariable("user_id") Long userId) {
+ Map<String, Object> response = userFollowService.getFollowers(userId);
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping("/{user_id}/following")
+ public ResponseEntity<Map<String, Object>> getFollowing(@PathVariable("user_id") Long userId) {
+ Map<String, Object> response = userFollowService.getFollowing(userId);
+ return ResponseEntity.ok(response);
+ }
+}
diff --git a/src/main/java/com/example/myproject/controller/UserMessageController.java b/src/main/java/com/example/myproject/controller/UserMessageController.java
new file mode 100644
index 0000000..c7014a7
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/UserMessageController.java
@@ -0,0 +1,39 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.service.UserMessageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/message")
+public class UserMessageController {
+
+ @Autowired
+ private UserMessageService userMessageService;
+
+ @PostMapping("/sendMessages")
+ public ResponseEntity<Map<String, Object>> sendMessage(@RequestBody Map<String, Object> params) {
+ // 将参数转换为 Long 类型
+ Long senderId = Long.valueOf(params.get("sender_id").toString());
+ Long receiverId = Long.valueOf(params.get("receiver_id").toString());
+ String content = (String) params.get("content");
+ Map<String, Object> response = userMessageService.sendMessage(senderId, receiverId, content);
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping("/{user_id}/getUserMessages")
+ public ResponseEntity<Map<String, Object>> getUserMessages(@PathVariable("user_id") Long userId) {
+ Map<String, Object> response = userMessageService.getUserMessages(userId);
+ return ResponseEntity.ok(response);
+ }
+
+ // 获取单条消息的详情
+ @GetMapping("/{message_id}/getAMessage")
+ public ResponseEntity<Map<String, Object>> getMessage(@PathVariable("message_id") Long messageId) {
+ Map<String, Object> response = userMessageService.getMessage(messageId);
+ return ResponseEntity.ok(response);
+ }
+}