fix some api

Change-Id: I7179a115c9ed3e7d3473c1761df1bb4f2bf3711e
diff --git a/src/main/java/com/example/g8backend/controller/TorrentController.java b/src/main/java/com/example/g8backend/controller/TorrentController.java
index ea7fdf2..e9216f8 100644
--- a/src/main/java/com/example/g8backend/controller/TorrentController.java
+++ b/src/main/java/com/example/g8backend/controller/TorrentController.java
@@ -16,6 +16,8 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/torrent")
@@ -29,7 +31,7 @@
 
     // 处理种子文件上传
     @PostMapping("/upload")
-    public ApiResponse<String> handleTorrentUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
+    public ApiResponse<Map> handleTorrentUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
         long userId = (long) authentication.getPrincipal();
 
@@ -50,9 +52,9 @@
 
         File tempFile = File.createTempFile("upload-", ".torrent");
         multipartFile.transferTo(tempFile);
-
+        Torrent newTorrent;
         try {
-            torrentService.handleTorrentUpload(tempFile, fileName, userId, passkey);
+            newTorrent = torrentService.handleTorrentUpload(tempFile, fileName, userId, passkey);
         } catch (IllegalArgumentException e) {
             return ApiResponse.error(400, e.getMessage());
         }
@@ -61,7 +63,9 @@
         if (!tempFile.delete()) {
             throw new IOException("Failed to delete temporary file: " + tempFile.getAbsolutePath());
         }
-        return ApiResponse.success("种子上传成功");
+        HashMap<String, Long> response = new HashMap<>();
+        response.put("torrentId", newTorrent.getTorrentId());
+        return ApiResponse.success(response);
     }
 
     // 下载种子文件
diff --git a/src/main/java/com/example/g8backend/controller/UserController.java b/src/main/java/com/example/g8backend/controller/UserController.java
index f9d0de4..a41e4d7 100644
--- a/src/main/java/com/example/g8backend/controller/UserController.java
+++ b/src/main/java/com/example/g8backend/controller/UserController.java
@@ -9,6 +9,7 @@
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.parameters.P;
 import org.springframework.web.bind.annotation.*;
 import com.example.g8backend.service.ISigningService;
 
@@ -23,14 +24,42 @@
     @Autowired
     private IUserService userService;
 
-    // 获取已登录的用户信息
     @GetMapping
-    public ApiResponse<User> getUserInfo(){
-        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
-        long userId = (long) authentication.getPrincipal();
+    public ApiResponse<Map<String, Object>> getCurrentUserInfo() {
+        Long userId = getCurrentUserId();
+        return getUserInfo(userId);
+    }
+
+    @GetMapping("/{userId}")
+    public ApiResponse<Map<String, Object>> getOtherUserInfo(@PathVariable(required = false) Long userId){
+        return getUserInfo(userId);
+    }
+
+    @GetMapping("/{userId}/follow-status")
+    public ApiResponse<Map<String, Boolean>> getFollowStatus(@PathVariable Long userId) {
+        Long currentUserId = getCurrentUserId();
+        boolean isFollowing = userService.isFollowing(currentUserId, userId);
+        return ApiResponse.success(Map.of("isFollowing", isFollowing));
+    }
+
+    private ApiResponse<Map<String, Object>> getUserInfo(Long userId) {
         User user = userService.getById(userId);
-        user.setPassword(null);  // 不返回密码
-        return ApiResponse.success(user);
+        if (user == null) {
+            return ApiResponse.error(404, "用户不存在");
+        }
+        user.setPassword(null);
+        user.setPasskey(null);
+
+        int followingCount = userService.getFollowingsCount(userId);
+        int followersCount = userService.getFollowersCount(userId);
+
+        return ApiResponse.success(Map.of(
+                "userInfo", user,
+                "statistics", Map.of(
+                        "followingCount", followingCount,
+                        "followersCount", followersCount
+                )
+        ));
     }
 
     // ==================== 关注功能 ====================