docs: 添加了不分页可选参数
This commit is contained in:
parent
d73c343722
commit
65584bb8d8
|
|
@ -51,7 +51,7 @@ All endpoints return the following structure:
|
||||||
GET /api/whitelist/list
|
GET /api/whitelist/list
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns paginated list of approved players (status=1).
|
Returns player records (default: approved, status=1).
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
|
|
||||||
|
|
@ -60,14 +60,20 @@ Returns paginated list of approved players (status=1).
|
||||||
| playerName | String | no | — | Filter by player name (partial match) |
|
| playerName | String | no | — | Filter by player name (partial match) |
|
||||||
| page | Integer | no | 1 | Page number |
|
| page | Integer | no | 1 | Page number |
|
||||||
| size | Integer | no | 10 | Items per page |
|
| 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
|
```bash
|
||||||
curl -H "X-API-TOKEN: <token>" \
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
"https://whitelist.r3944realms.top/api/whitelist/list?page=1&size=10&playerName=Steve"
|
"https://whitelist.r3944realms.top/api/whitelist/list?page=1&size=10&playerName=Steve"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**All records (no pagination):**
|
||||||
|
```bash
|
||||||
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
|
"https://whitelist.r3944realms.top/api/whitelist/list?all=true"
|
||||||
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Example response</summary>
|
<summary>Example response</summary>
|
||||||
|
|
||||||
|
|
@ -108,7 +114,7 @@ GET /api/whitelist/pending
|
||||||
|
|
||||||
Returns paginated list of players awaiting review (status=2).
|
Returns paginated list of players awaiting review (status=2).
|
||||||
|
|
||||||
**Parameters:** Same as `/list`.
|
**Parameters:** Same as `/list` (including `all`).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -H "X-API-TOKEN: <token>" \
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
|
|
@ -125,7 +131,7 @@ GET /api/whitelist/rejected
|
||||||
|
|
||||||
Returns paginated list of rejected players (status=0).
|
Returns paginated list of rejected players (status=0).
|
||||||
|
|
||||||
**Parameters:** Same as `/list`.
|
**Parameters:** Same as `/list` (including `all`).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -H "X-API-TOKEN: <token>" \
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ https://your_host_url/api/whitelist
|
||||||
GET /api/whitelist/list
|
GET /api/whitelist/list
|
||||||
```
|
```
|
||||||
|
|
||||||
分页查询已通过审核的玩家(status=1)。
|
查询玩家记录(默认 status=1 已通过)。
|
||||||
|
|
||||||
**请求参数:**
|
**请求参数:**
|
||||||
|
|
||||||
|
|
@ -60,12 +60,20 @@ GET /api/whitelist/list
|
||||||
| playerName | String | 否 | — | 按玩家名筛选 |
|
| playerName | String | 否 | — | 按玩家名筛选 |
|
||||||
| page | Integer | 否 | 1 | 页码 |
|
| page | Integer | 否 | 1 | 页码 |
|
||||||
| size | Integer | 否 | 10 | 每页条数 |
|
| size | Integer | 否 | 10 | 每页条数 |
|
||||||
|
| all | Boolean | 否 | false | `true` 时忽略分页,一次性返回全部数据 |
|
||||||
|
|
||||||
|
**分页查询:**
|
||||||
```bash
|
```bash
|
||||||
curl -H "X-API-TOKEN: <token>" \
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
"https://whitelist.r3944realms.top/api/whitelist/list?page=1&size=10&playerName=Steve"
|
"https://whitelist.r3944realms.top/api/whitelist/list?page=1&size=10&playerName=Steve"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**全部查询(不分页):**
|
||||||
|
```bash
|
||||||
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
|
"https://whitelist.r3944realms.top/api/whitelist/list?all=true"
|
||||||
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>返回示例</summary>
|
<summary>返回示例</summary>
|
||||||
|
|
||||||
|
|
@ -106,7 +114,7 @@ GET /api/whitelist/pending
|
||||||
|
|
||||||
分页查询待审核的玩家(status=2)。
|
分页查询待审核的玩家(status=2)。
|
||||||
|
|
||||||
**请求参数:** 同 `/list`。
|
**请求参数:** 同 `/list`(含 `all` 参数)。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -H "X-API-TOKEN: <token>" \
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
|
|
@ -123,7 +131,7 @@ GET /api/whitelist/rejected
|
||||||
|
|
||||||
分页查询已被拒绝的玩家(status=0)。
|
分页查询已被拒绝的玩家(status=0)。
|
||||||
|
|
||||||
**请求参数:** 同 `/list`。
|
**请求参数:** 同 `/list`(含 `all` 参数)。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -H "X-API-TOKEN: <token>" \
|
curl -H "X-API-TOKEN: <token>" \
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -10,7 +10,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.linearpast</groupId>
|
<groupId>com.linearpast</groupId>
|
||||||
<artifactId>MinecraftManager</artifactId>
|
<artifactId>MinecraftManager</artifactId>
|
||||||
<version>1.1.2</version>
|
<version>1.1.3</version>
|
||||||
<name>MinecraftManager</name>
|
<name>MinecraftManager</name>
|
||||||
<description>MinecraftManager</description>
|
<description>MinecraftManager</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import jakarta.servlet.http.HttpSession;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -24,16 +25,19 @@ public class WhitelistController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取白名单列表(已通过的玩家,status=1)
|
* 获取白名单列表(已通过的玩家,status=1)
|
||||||
|
* all=true 时不分页,返回全部
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Result<?> getWhitelist(
|
public Result<?> getWhitelist(
|
||||||
@RequestParam(required = false) String playerName,
|
@RequestParam(required = false) String playerName,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@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<PlayerInfoView> players = playersService.getPlayers(
|
Page<PlayerInfoView> players = playersService.getPlayers(
|
||||||
playerName, null, null, (byte) 1,
|
playerName, null, null, (byte) 1,
|
||||||
null, null, PageRequest.of(page - 1, size)
|
null, null, pageable
|
||||||
);
|
);
|
||||||
return Result.successPage(players.getContent(), players.getTotalElements());
|
return Result.successPage(players.getContent(), players.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
@ -45,11 +49,13 @@ public class WhitelistController {
|
||||||
public Result<?> getPending(
|
public Result<?> getPending(
|
||||||
@RequestParam(required = false) String playerName,
|
@RequestParam(required = false) String playerName,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@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<PlayerInfoView> players = playersService.getPlayers(
|
Page<PlayerInfoView> players = playersService.getPlayers(
|
||||||
playerName, null, null, (byte) 2,
|
playerName, null, null, (byte) 2,
|
||||||
null, null, PageRequest.of(page - 1, size)
|
null, null, pageable
|
||||||
);
|
);
|
||||||
return Result.successPage(players.getContent(), players.getTotalElements());
|
return Result.successPage(players.getContent(), players.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
@ -61,11 +67,13 @@ public class WhitelistController {
|
||||||
public Result<?> getRejected(
|
public Result<?> getRejected(
|
||||||
@RequestParam(required = false) String playerName,
|
@RequestParam(required = false) String playerName,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@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<PlayerInfoView> players = playersService.getPlayers(
|
Page<PlayerInfoView> players = playersService.getPlayers(
|
||||||
playerName, null, null, (byte) 0,
|
playerName, null, null, (byte) 0,
|
||||||
null, null, PageRequest.of(page - 1, size)
|
null, null, pageable
|
||||||
);
|
);
|
||||||
return Result.successPage(players.getContent(), players.getTotalElements());
|
return Result.successPage(players.getContent(), players.getTotalElements());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,17 @@ class WhitelistControllerTest {
|
||||||
.andExpect(jsonPath("$.code").value(200));
|
.andExpect(jsonPath("$.code").value(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getWhitelist_all_shouldUseUnpaged() throws Exception {
|
||||||
|
Page<PlayerInfoView> 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 ====================
|
// ==================== pending ====================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user