apply .gitignore clean-up
Change-Id: Idd0b57a7340f0e62c85090d84c4fdb8cb5d6fe00
diff --git a/src/main/java/com/example/myproject/controller/RecommendationController.java b/src/main/java/com/example/myproject/controller/RecommendationController.java
new file mode 100644
index 0000000..d99c4d0
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/RecommendationController.java
@@ -0,0 +1,39 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.entity.TorrentEntity;
+import com.example.myproject.service.PopularSeedService;
+import com.example.myproject.service.RecommendationService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/echo/recommendation")
+@Api("推荐接口")
+public class RecommendationController {
+
+ @Autowired
+ private RecommendationService recommendationService;
+
+ @Autowired
+ private PopularSeedService popularSeedService;
+
+ @GetMapping("/seeds/{userId}")
+ @ApiOperation("获取基于内容的种子推荐")
+ public List<TorrentEntity> getRecommendedSeeds(@PathVariable Long userId) {
+ return recommendationService.getRecommendedSeeds(userId);
+ }
+
+ @GetMapping("/popular")
+ @ApiOperation("获取热门种子推荐")
+ public List<TorrentEntity> getPopularSeeds(
+ @ApiParam(value = "返回数量", defaultValue = "16")
+ @RequestParam(defaultValue = "16") int limit
+ ) {
+ return popularSeedService.getPopularSeeds(limit);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/myproject/controller/SeedRatingController.java b/src/main/java/com/example/myproject/controller/SeedRatingController.java
new file mode 100644
index 0000000..16e0b22
--- /dev/null
+++ b/src/main/java/com/example/myproject/controller/SeedRatingController.java
@@ -0,0 +1,26 @@
+package com.example.myproject.controller;
+
+import com.example.myproject.service.SeedRatingService;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/echo/ratings")
+public class SeedRatingController {
+
+ private final SeedRatingService ratingService;
+
+ public SeedRatingController(SeedRatingService ratingService) {
+ this.ratingService = ratingService;
+ }
+
+ @PostMapping
+ public Map<String, Object> submitRating(
+ @RequestParam("userId") Long userId,
+ @RequestParam("seedId") Long seedId,
+ @RequestParam("score") Integer score
+ ) {
+ return ratingService.rateSeed(userId, seedId, score);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/myproject/controller/TorrentLikesController.java b/src/main/java/com/example/myproject/controller/TorrentLikesController.java
deleted file mode 100644
index 7419faf..0000000
--- a/src/main/java/com/example/myproject/controller/TorrentLikesController.java
+++ /dev/null
@@ -1,32 +0,0 @@
-//package com.example.myproject.controller;
-//
-//import com.example.myproject.service.TorrentLikesService;
-//import org.springframework.web.bind.annotation.*;
-//
-//import java.util.Map;
-//
-//@RestController
-//@RequestMapping("/echo/torrent")
-//public class TorrentLikesController {
-//
-// private final TorrentLikesService service;
-//
-// public TorrentLikesController(TorrentLikesService service) {
-// this.service = service;
-// }
-//
-// /**
-// * 点赞接口
-// * @param userId 用户ID(请求参数:user_id)
-// * @param torrentId 种子ID(请求参数:torrent_id)
-// * @return 操作结果:{"status": 1/0}
-// */
-// @PostMapping("/{userId}/{torrentId}")
-// public Map<String, Object> toggleLike(
-// @PathVariable Integer userId,
-// @PathVariable Long torrentId) {
-// return service.toggleLike(userId, torrentId);
-// }
-//
-//
-//}
\ 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 41a3350..dc4073b 100644
--- a/src/main/java/com/example/myproject/controller/UserController.java
+++ b/src/main/java/com/example/myproject/controller/UserController.java
@@ -1,3 +1,362 @@
+//// package com.example.myproject.controller;
+//
+//// import com.example.myproject.entity.Users;
+//// import com.example.myproject.repository.UserRepository;
+//// import com.example.myproject.service.DynamicService;
+//// import com.example.myproject.service.TaskService;
+//// import com.example.myproject.service.UserService;
+//// 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 javax.servlet.http.HttpServletRequest;
+//// import java.util.Map;
+//// import java.util.Optional;
+//
+//// import java.util.List;
+//// import java.util.ArrayList;
+//
+//
+//// @RestController
+//// @RequestMapping("/echo/user")
+//// public class UserController {
+//
+//// @Autowired
+//// private UserService userService;
+//
+//// @Autowired
+//// private UserRepository userRepository;
+//
+//// @Autowired
+//// private DynamicService dynamicService;
+//
+//// // 接口:生成邀请码
+//// @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")
+//// 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 Map.of("msg", resultMessage);
+//// }
+//// }
+//
+//// //修改密码
+//// @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");
+//
+//// // 调用服务层的修改密码方法
+//// String resultMessage = userService.changePassword(userId, oldPassword, newPassword, confirmPassword);
+//
+//// // 返回修改结果
+//// return Map.of("message", resultMessage, "status", resultMessage.equals("密码修改成功") ? "success" : "error");
+//// }
+//
+//// // 获取用户个人资料
+//// @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 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, nickname, gender, description, hobbies);
+//
+//// // 返回操作结果消息
+//// if (updated) {
+//// return Map.of("message", "用户资料更新成功");
+//// } else {
+//// return Map.of("message", "用户不存在");
+//// }
+//// }
+//
+//// // 计算分享率
+//// @GetMapping("/{user_id}/calculate-share-rate")
+//// public Map<String, Object> calculateShareRate(@PathVariable("user_id") Long userId) {
+//// return userService.calculateShareRate(userId);
+//// }
+//
+//// // 获取用户所有好友的基本信息
+//// @GetMapping("/{userId}/friends")
+//// public List<Map<String, Object>> getUserFriends(@PathVariable("userId") Long userId) {
+//// List<Long> friendIds = dynamicService.getAllFriendIds(userId); // 注意这里用的是实例对象
+//// List<Map<String, Object>> friends = new ArrayList<>();
+//
+//// for (Long friendId : friendIds) {
+//// Optional<Users> userOpt = userRepository.findById(friendId);
+//// if (userOpt.isPresent()) {
+//// Users user = userOpt.get();
+//// Map<String, Object> friendInfo = Map.of(
+//// "id", user.getUserId(),
+//// "avatar", user.getAvatarUrl() != null ? user.getAvatarUrl() : "https://example.com/default-avatar.jpg",
+//// "nickname", user.getUsername() != null ? user.getUsername() : "未知用户",
+//// "email", user.getEmail() != null ? user.getEmail() : "未填写"
+//// );
+//// friends.add(friendInfo);
+//// }
+//// }
+//
+//// return friends;
+//// }
+//
+//// @PostMapping("/{userId}/uploadAvatar")
+//// public Map<String, Object> uploadAvatar(
+//// @PathVariable Long userId,
+//// @RequestParam("file") MultipartFile file) {
+//// return userService.uploadUserAvatar(userId, file);
+//// }
+//
+//
+//
+//// }
+//
+//package com.example.myproject.controller;
+//
+//import com.example.myproject.entity.FriendRelation;
+//import com.example.myproject.entity.Users;
+//import com.example.myproject.repository.FriendRelationRepository;
+//import com.example.myproject.repository.UserRepository;
+//import com.example.myproject.service.DynamicService;
+//import com.example.myproject.service.UserService;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.web.bind.annotation.*;
+//import org.springframework.web.multipart.MultipartFile;
+//
+//import java.util.*;
+//
+//
+//@RestController
+//@RequestMapping("/echo/user")
+//public class UserController {
+//
+// @Autowired
+// private UserService userService;
+//
+// @Autowired
+// private UserRepository userRepository;
+//
+// @Autowired
+// private DynamicService dynamicService;
+//
+// @Autowired
+// private FriendRelationRepository friendRelationRepository;
+//
+//
+// @PostMapping ("/addFriend")
+// public Map<String, Object> addFriend(@RequestBody Map<String, Object> request) {
+// //邮箱查用户
+// Optional<Users> userOptional = userRepository.findByEmail(request.get("email").toString());
+// // 如果用户不存在,返回null或者可以抛出异常
+// if (userOptional.isEmpty()) {
+// return Map.of("msg", "没有找到该用户"); // 可以返回 null 或者根据需要返回错误信息
+// }
+// Long userId = Long.parseLong(request.get("userid").toString()); //id查用户
+// Map<String, Object> users = userService.getProfile(userId);
+// // 如果用户不存在,返回null或者可以抛出异常
+// if (users.isEmpty()) {
+// return Map.of("msg", "当前登录账号异常"); // 可以返回 null 或者根据需要返回错误信息
+// }
+//
+// FriendRelation newFriendRelation = new FriendRelation();
+// newFriendRelation.setUserId(userId);
+// newFriendRelation.setCreateTime(new Date());
+// newFriendRelation.setFriendId(userOptional.get().getUserId());
+//
+// FriendRelation newFriendRelations = new FriendRelation();
+// newFriendRelations.setCreateTime(new Date());
+// newFriendRelations.setUserId(userOptional.get().getUserId());
+// newFriendRelations.setFriendId(userId);
+//
+// friendRelationRepository.save(newFriendRelation);
+// friendRelationRepository.save(newFriendRelations);
+//
+// return Map.of("msg", "添加成功");
+// }
+//
+// // 接口:生成邀请码
+// @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")
+// 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 Map.of("msg", resultMessage);
+// }
+// }
+//
+// //修改密码
+// @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");
+//
+// // 调用服务层的修改密码方法
+// String resultMessage = userService.changePassword(userId, oldPassword, newPassword, confirmPassword);
+//
+// // 返回修改结果
+// return Map.of("message", resultMessage, "status", resultMessage.equals("密码修改成功") ? "success" : "error");
+// }
+//
+// // 获取用户个人资料
+// @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 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, nickname, gender, description, hobbies);
+//
+// // 返回操作结果消息
+// if (updated) {
+// return Map.of("message", "用户资料更新成功");
+// } else {
+// return Map.of("message", "用户不存在");
+// }
+// }
+//
+// // 计算分享率
+// @GetMapping("/{user_id}/calculate-share-rate")
+// public Map<String, Object> calculateShareRate(@PathVariable("user_id") Long userId) {
+// return userService.calculateShareRate(userId);
+// }
+//
+// // 获取用户所有好友的基本信息
+// @GetMapping("/{userId}/friends")
+// public List<Map<String, Object>> getUserFriends(@PathVariable("userId") Long userId) {
+// List<Long> friendIds = dynamicService.getAllFriendIds(userId); // 注意这里用的是实例对象
+// List<Map<String, Object>> friends = new ArrayList<>();
+//
+// for (Long friendId : friendIds) {
+// Optional<Users> userOpt = userRepository.findById(friendId);
+// if (userOpt.isPresent()) {
+// Users user = userOpt.get();
+// Map<String, Object> friendInfo = Map.of(
+// "id", user.getUserId(),
+// "avatar", user.getAvatarUrl() != null ? user.getAvatarUrl() : "https://example.com/default-avatar.jpg",
+// "nickname", user.getUsername() != null ? user.getUsername() : "未知用户",
+// "email", user.getEmail() != null ? user.getEmail() : "未填写"
+// );
+// friends.add(friendInfo);
+// }
+// }
+//
+// return friends;
+// }
+//
+// @PostMapping("/{userId}/uploadAvatar")
+// public Map<String, Object> uploadAvatar(
+// @PathVariable Long userId,
+// @RequestParam("file") MultipartFile file) {
+// return userService.uploadUserAvatar(userId, file);
+// }
+//
+//
+//
+//}
+//
+
// package com.example.myproject.controller;
// import com.example.myproject.entity.Users;
@@ -352,6 +711,10 @@
return userService.uploadUserAvatar(userId, file);
}
+ @GetMapping("/users/{userId}/share-rate")
+ public String checkUserShareRate(@PathVariable Long userId) {
+ return userService.checkUserShareRate(userId);
+ }
}