diff --git a/docs/whitelist-api-en.md b/docs/whitelist-api-en.md index 1ed7175..36ac30c 100644 --- a/docs/whitelist-api-en.md +++ b/docs/whitelist-api-en.md @@ -51,7 +51,7 @@ All endpoints return the following structure: GET /api/whitelist/list ``` -Returns paginated list of approved players (status=1). +Returns player records (default: approved, status=1). **Parameters:** @@ -60,14 +60,20 @@ Returns paginated list of approved players (status=1). | playerName | String | no | — | Filter by player name (partial match) | | page | Integer | no | 1 | Page number | | size | Integer | no | 10 | Items per page | +| all | Boolean | no | false | When `true`, returns all records without pagination | -**Response `data`:** Array of `PlayerInfo` objects. - +**Paginated query:** ```bash curl -H "X-API-TOKEN: " \ "https://whitelist.r3944realms.top/api/whitelist/list?page=1&size=10&playerName=Steve" ``` +**All records (no pagination):** +```bash +curl -H "X-API-TOKEN: " \ + "https://whitelist.r3944realms.top/api/whitelist/list?all=true" +``` +
Example response @@ -108,7 +114,7 @@ GET /api/whitelist/pending Returns paginated list of players awaiting review (status=2). -**Parameters:** Same as `/list`. +**Parameters:** Same as `/list` (including `all`). ```bash curl -H "X-API-TOKEN: " \ @@ -125,7 +131,7 @@ GET /api/whitelist/rejected Returns paginated list of rejected players (status=0). -**Parameters:** Same as `/list`. +**Parameters:** Same as `/list` (including `all`). ```bash curl -H "X-API-TOKEN: " \ diff --git a/docs/whitelist-api-zh.md b/docs/whitelist-api-zh.md index da7e48b..9a17c93 100644 --- a/docs/whitelist-api-zh.md +++ b/docs/whitelist-api-zh.md @@ -51,7 +51,7 @@ https://your_host_url/api/whitelist GET /api/whitelist/list ``` -分页查询已通过审核的玩家(status=1)。 +查询玩家记录(默认 status=1 已通过)。 **请求参数:** @@ -60,12 +60,20 @@ GET /api/whitelist/list | playerName | String | 否 | — | 按玩家名筛选 | | page | Integer | 否 | 1 | 页码 | | size | Integer | 否 | 10 | 每页条数 | +| all | Boolean | 否 | false | `true` 时忽略分页,一次性返回全部数据 | +**分页查询:** ```bash curl -H "X-API-TOKEN: " \ "https://whitelist.r3944realms.top/api/whitelist/list?page=1&size=10&playerName=Steve" ``` +**全部查询(不分页):** +```bash +curl -H "X-API-TOKEN: " \ + "https://whitelist.r3944realms.top/api/whitelist/list?all=true" +``` +
返回示例 @@ -106,7 +114,7 @@ GET /api/whitelist/pending 分页查询待审核的玩家(status=2)。 -**请求参数:** 同 `/list`。 +**请求参数:** 同 `/list`(含 `all` 参数)。 ```bash curl -H "X-API-TOKEN: " \ @@ -123,7 +131,7 @@ GET /api/whitelist/rejected 分页查询已被拒绝的玩家(status=0)。 -**请求参数:** 同 `/list`。 +**请求参数:** 同 `/list`(含 `all` 参数)。 ```bash curl -H "X-API-TOKEN: " \ diff --git a/pom.xml b/pom.xml index 2c18e6f..6274536 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.linearpast MinecraftManager - 1.1.2 + 1.1.3 MinecraftManager MinecraftManager diff --git a/src/main/java/com/linearpast/minecraftmanager/controller/WhitelistController.java b/src/main/java/com/linearpast/minecraftmanager/controller/WhitelistController.java index bc8f0bf..7de9b14 100644 --- a/src/main/java/com/linearpast/minecraftmanager/controller/WhitelistController.java +++ b/src/main/java/com/linearpast/minecraftmanager/controller/WhitelistController.java @@ -9,6 +9,7 @@ import jakarta.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.*; import java.util.HashMap; @@ -24,16 +25,19 @@ public class WhitelistController { /** * 获取白名单列表(已通过的玩家,status=1) + * all=true 时不分页,返回全部 */ @GetMapping("/list") public Result getWhitelist( @RequestParam(required = false) String playerName, @RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer size + @RequestParam(defaultValue = "10") Integer size, + @RequestParam(defaultValue = "false") boolean all ) { + Pageable pageable = all ? Pageable.unpaged() : PageRequest.of(page - 1, size); Page players = playersService.getPlayers( playerName, null, null, (byte) 1, - null, null, PageRequest.of(page - 1, size) + null, null, pageable ); return Result.successPage(players.getContent(), players.getTotalElements()); } @@ -45,11 +49,13 @@ public class WhitelistController { public Result getPending( @RequestParam(required = false) String playerName, @RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer size + @RequestParam(defaultValue = "10") Integer size, + @RequestParam(defaultValue = "false") boolean all ) { + Pageable pageable = all ? Pageable.unpaged() : PageRequest.of(page - 1, size); Page players = playersService.getPlayers( playerName, null, null, (byte) 2, - null, null, PageRequest.of(page - 1, size) + null, null, pageable ); return Result.successPage(players.getContent(), players.getTotalElements()); } @@ -61,11 +67,13 @@ public class WhitelistController { public Result getRejected( @RequestParam(required = false) String playerName, @RequestParam(defaultValue = "1") Integer page, - @RequestParam(defaultValue = "10") Integer size + @RequestParam(defaultValue = "10") Integer size, + @RequestParam(defaultValue = "false") boolean all ) { + Pageable pageable = all ? Pageable.unpaged() : PageRequest.of(page - 1, size); Page players = playersService.getPlayers( playerName, null, null, (byte) 0, - null, null, PageRequest.of(page - 1, size) + null, null, pageable ); return Result.successPage(players.getContent(), players.getTotalElements()); } diff --git a/src/test/java/com/linearpast/minecraftmanager/controller/WhitelistControllerTest.java b/src/test/java/com/linearpast/minecraftmanager/controller/WhitelistControllerTest.java index c7cf10a..8bbff36 100644 --- a/src/test/java/com/linearpast/minecraftmanager/controller/WhitelistControllerTest.java +++ b/src/test/java/com/linearpast/minecraftmanager/controller/WhitelistControllerTest.java @@ -78,6 +78,17 @@ class WhitelistControllerTest { .andExpect(jsonPath("$.code").value(200)); } + @Test + void getWhitelist_all_shouldUseUnpaged() throws Exception { + Page page = new PageImpl<>(Collections.emptyList()); + when(playersService.getPlayers(isNull(), isNull(), isNull(), eq((byte) 1), + isNull(), isNull(), eq(Pageable.unpaged()))).thenReturn(page); + + mockMvc.perform(get("/api/whitelist/list").param("all", "true")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)); + } + // ==================== pending ==================== @Test