Skip to content

Commit 0a4411b

Browse files
committed
fix: 修复orderBy等请求参数不生效的问题
1 parent 745605b commit 0a4411b

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed

src/main/kotlin/plus/maa/backend/controller/CopilotController.kt

+13
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ class CopilotController(
7474
fun queriesCopilot(
7575
@ParameterObject parsed: @Valid CopilotQueriesRequest
7676
): MaaResult<CopilotPageInfo> {
77+
// FIXME 请求对下划线的处理存在问题,需要更正
78+
if (parsed.copilotIds == null) {
79+
parsed.copilotIds = parsed.copilot_ids
80+
}
81+
if (parsed.levelKeyword == null) {
82+
parsed.levelKeyword = parsed.level_keyword
83+
}
84+
if (parsed.orderBy == null) {
85+
parsed.orderBy = parsed.order_by
86+
}
87+
if (parsed.uploaderId == null) {
88+
parsed.uploaderId = parsed.uploader_id
89+
}
7790
// 三秒防抖,缓解前端重复请求问题
7891
response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=3, must-revalidate")
7992
return success(copilotService.queriesCopilot(helper.userId, parsed))
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package plus.maa.backend.controller.request.copilot
22

3-
import com.fasterxml.jackson.annotation.JsonIgnore
43
import jakarta.validation.constraints.Max
54

65
/**
@@ -11,43 +10,41 @@ data class CopilotQueriesRequest(
1110
val page: Int = 0,
1211
val limit: @Max(value = 50, message = "单页大小不得超过50") Int = 10,
1312
var levelKeyword: String? = null,
13+
val level_keyword: String? = null,
1414
val operator: String? = null,
1515
val content: String? = null,
1616
val document: String? = null,
1717
var uploaderId: String? = null,
18+
val uploader_id: String? = null,
1819
val desc: Boolean = true,
1920
var orderBy: String? = null,
21+
val order_by: String? = null,
2022
val language: String? = null,
21-
var copilotIds: List<Long>? = null
23+
var copilotIds: List<Long>? = null,
24+
val copilot_ids: List<Long>? = null
2225
) {
2326

24-
/*
25-
* 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名
26-
* 因为 Get 请求传入的参数不是 JSON,所以没办法使用 Jackson 的注解直接实现别名
27-
* 添加 @JsonAlias 和 @JsonIgnore 注解只是为了保障 Swagger 的文档正确显示
28-
* (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名)
29-
*/
30-
@JsonIgnore
31-
@Suppress("unused")
32-
fun setLevel_keyword(levelKeyword: String?) {
33-
this.levelKeyword = levelKeyword
34-
}
35-
36-
@JsonIgnore
37-
@Suppress("unused")
38-
fun setUploader_id(uploaderId: String?) {
39-
this.uploaderId = uploaderId
40-
}
41-
42-
@JsonIgnore
43-
@Suppress("unused")
44-
fun setOrder_by(orderBy: String?) {
45-
this.orderBy = orderBy
46-
}
47-
48-
@JsonIgnore
49-
@Suppress("unused")
50-
fun setCopilot_ids(copilotIds: List<Long>?) {
51-
this.copilotIds = copilotIds
52-
}
27+
// /*
28+
// * 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名
29+
// * 因为 Get 请求传入的参数不是 JSON,所以没办法使用 Jackson 的注解直接实现别名
30+
// * 添加 @JsonAlias 和 @JsonIgnore 注解只是为了保障 Swagger 的文档正确显示
31+
// * (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名)
32+
// */
33+
// @JsonIgnore
34+
// @Suppress("unused")
35+
// fun setLevel_keyword(levelKeyword: String?) {
36+
// this.levelKeyword = levelKeyword
37+
// }
38+
//
39+
// @JsonIgnore
40+
// @Suppress("unused")
41+
// fun setUploader_id(uploaderId: String?) {
42+
// this.uploaderId = uploaderId
43+
// }
44+
//
45+
// @JsonIgnore
46+
// @Suppress("unused")
47+
// fun setCopilot_ids(copilotIds: List<Long>?) {
48+
// this.copilotIds = copilotIds
49+
// }
5350
}

0 commit comments

Comments
 (0)