blob: 83e805161db8e48db062479422eb68bdc021db82 [file] [log] [blame]
ystx89bd5442025-06-07 19:35:27 +08001package com.pt.controller;
2
3import com.pt.entity.TorrentStats;
4import com.pt.service.TorrentStatsService;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.web.bind.annotation.*;
7
8import java.util.List;
9
10@RestController
11@RequestMapping("/api/stats")
Edwardsamaxlaf825a22025-06-09 21:17:29 +080012@CrossOrigin(origins = "*")
ystx89bd5442025-06-07 19:35:27 +080013public class TorrentStatsController {
14
15 @Autowired
16 private TorrentStatsService statsService;
17
18 // 1. 获取单个种子统计
19 @GetMapping("/{torrentId}")
20 public TorrentStats getStats(@PathVariable Long torrentId) {
21 return statsService.getTorrentStats(torrentId);
22 }
23
24 // 2. 获取热门种子(做种人数TOP N)
25 @GetMapping("/top-seeded")
26 public List<TorrentStats> getTopSeeded(
27 @RequestParam(defaultValue = "10") int limit) {
28 return statsService.getTopSeededTorrents(limit);
29 }
30
31 // 3. 获取最近活跃种子
32 @GetMapping("/recent-active")
33 public List<TorrentStats> getRecentActive(
34 @RequestParam(defaultValue = "10") int limit) {
35 return statsService.getRecentActiveTorrents(limit);
36 }
37
38 // 4. 批量获取统计信息
39 @PostMapping("/batch")
40 public List<TorrentStats> getBatchStats(@RequestBody List<Long> torrentIds) {
41 return statsService.getBatchStats(torrentIds);
42 }
43}