获取种子列表功能

Change-Id: I7d31c3cadd2e9e6bfad55d6874e3ddece0c6a087
diff --git a/src/main/java/com/pt5/pthouduan/controller/TorrentController.java b/src/main/java/com/pt5/pthouduan/controller/TorrentController.java
index 3150258..a57b06d 100644
--- a/src/main/java/com/pt5/pthouduan/controller/TorrentController.java
+++ b/src/main/java/com/pt5/pthouduan/controller/TorrentController.java
@@ -57,6 +57,75 @@
 
 
 
+//    @GetMapping("/{infoHash}/seeders")
+//    public ResponseEntity<List<PeerInfo>> getSeedersByInfoHash(@PathVariable String infoHash) {
+//        List<PeerInfo> seeders = peerService.getSeedersByInfoHash(infoHash.toUpperCase());
+//        System.out.println("Response: " + seeders);
+//        return ResponseEntity.ok(seeders);
+//    }
+//
+//    //添加搜索
+//    @GetMapping("/search")
+//    public ResponseEntity<List<Torrent>> searchTorrents(@RequestParam("keyword") String keyword) {
+//        List<Torrent> result = torrentService.searchByKeyword(keyword);
+//        return ResponseEntity.ok(result);
+//    }
+//
+//    @PostMapping("/addcredit")
+//    public ResponseEntity<?> addCredit(@RequestParam("manageid") Long manageid,@RequestParam("userid") Long userid,@RequestParam("credit") Integer credit,@RequestParam("helpedId") Long helpedId) {
+//        try {
+//            torrentService.addcredit(manageid,userid,credit);
+//            torrentService.deducecredit(manageid,helpedId,credit);
+//        } catch (Exception e) {
+//            return ResponseEntity.internalServerError().body(Map.of(
+//                    "success", false,
+//                    "message", "服务器错误: " + e.getMessage()
+//            ));
+//        }
+//        return ResponseEntity.ok(credit);  //成功返回保种积分
+//    }
+//
+//    @PostMapping("/deducecredit")
+//    public ResponseEntity<?> duduceCredit(@RequestParam("manageid") Long manageid,@RequestParam("userid") Long userid,@RequestParam("credit") Integer credit) {
+//        try {
+//            torrentService.deducecredit(manageid,userid,credit);
+//        } catch (Exception e) {
+//            return ResponseEntity.internalServerError().body(Map.of(
+//                    "success", false,
+//                    "message", "服务器错误: " + e.getMessage()
+//            ));
+//        }
+//        return ResponseEntity.ok(credit);  //成功返回保种积分
+//    }
+
+
+   //显示所有种子
+    @GetMapping("/list")
+    public List<Torrent> getAllTorrents() {
+        return torrentService.getAllTorrents();
+    }
+
+//    // 按分类获取种子(带 category 参数)
+//    @GetMapping("/listByCategory")
+//    public List<Torrent> getTorrentsByCategory(@RequestParam(required = false) Integer categoryid) {
+//        if (categoryid == null) {
+//            return torrentService.getAllTorrents();
+//        }
+//        return torrentService.getTorrentsByCategory(categoryid); // 否则按分类过滤
+//    }
+//
+//    @GetMapping("/listByCategorywithfilter")
+//    public List<Torrent> getTorrentsByCategorywithFilter(
+//            @RequestParam Integer categoryid,
+//            @RequestParam Map<String, String> filters
+//    ){
+//        filters.remove("categoryid");
+//        List<Torrent> torrents = torrentService.getTorrentsByCategorywithfilters(categoryid,filters);
+//        return torrents;
+//    }
+
+
+
     // 获取单个种子详情
     @GetMapping("/{id}")
     public ResponseEntity<?> getTorrentById(@PathVariable Long id) {
diff --git a/src/test/java/com/pt5/pthouduan/ControllerTest/TorrentListControllerTest.java b/src/test/java/com/pt5/pthouduan/ControllerTest/TorrentListControllerTest.java
new file mode 100644
index 0000000..582e753
--- /dev/null
+++ b/src/test/java/com/pt5/pthouduan/ControllerTest/TorrentListControllerTest.java
@@ -0,0 +1,66 @@
+package com.pt5.pthouduan.ControllerTest;
+
+
+import com.pt5.pthouduan.controller.TorrentController;
+import com.pt5.pthouduan.entity.Torrent;
+import com.pt5.pthouduan.service.TorrentService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
+class TorrentListControllerTest {
+
+    @Mock
+    private TorrentService torrentService;
+
+    @InjectMocks
+    private TorrentController torrentController;
+
+    private MockMvc mockMvc;
+
+    @BeforeEach
+    void setUp() {
+        MockitoAnnotations.openMocks(this);
+        mockMvc = MockMvcBuilders.standaloneSetup(torrentController).build();
+    }
+
+    @Test
+    void getAllTorrents_ShouldReturnAllTorrents() throws Exception {
+        // Arrange
+        Torrent torrent1 = new Torrent();
+        Torrent torrent2 = new Torrent();
+        List<Torrent> torrents = Arrays.asList(torrent1, torrent2);
+
+        when(torrentService.getAllTorrents()).thenReturn(torrents);
+
+        // Act & Assert
+        mockMvc.perform(get("/torrent/list"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$").isArray())
+                .andExpect(jsonPath("$.length()").value(2));
+    }
+
+    @Test
+    void getAllTorrents_ShouldReturnEmptyListWhenNoTorrents() throws Exception {
+        // Arrange
+        when(torrentService.getAllTorrents()).thenReturn(Collections.emptyList());
+
+        // Act & Assert
+        mockMvc.perform(get("/torrent/list"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$").isArray())
+                .andExpect(jsonPath("$.length()").value(0));
+    }
+}
\ No newline at end of file