Skip to content

Commit

Permalink
fix: 修复orderBy等请求参数不生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Mar 2, 2024
1 parent 745605b commit 0a4411b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
13 changes: 13 additions & 0 deletions src/main/kotlin/plus/maa/backend/controller/CopilotController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ class CopilotController(
fun queriesCopilot(
@ParameterObject parsed: @Valid CopilotQueriesRequest
): MaaResult<CopilotPageInfo> {
// FIXME 请求对下划线的处理存在问题,需要更正
if (parsed.copilotIds == null) {
parsed.copilotIds = parsed.copilot_ids
}
if (parsed.levelKeyword == null) {
parsed.levelKeyword = parsed.level_keyword
}
if (parsed.orderBy == null) {
parsed.orderBy = parsed.order_by
}
if (parsed.uploaderId == null) {
parsed.uploaderId = parsed.uploader_id
}
// 三秒防抖,缓解前端重复请求问题
response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=3, must-revalidate")
return success(copilotService.queriesCopilot(helper.userId, parsed))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package plus.maa.backend.controller.request.copilot

import com.fasterxml.jackson.annotation.JsonIgnore
import jakarta.validation.constraints.Max

/**
Expand All @@ -11,43 +10,41 @@ data class CopilotQueriesRequest(
val page: Int = 0,
val limit: @Max(value = 50, message = "单页大小不得超过50") Int = 10,
var levelKeyword: String? = null,
val level_keyword: String? = null,
val operator: String? = null,
val content: String? = null,
val document: String? = null,
var uploaderId: String? = null,
val uploader_id: String? = null,
val desc: Boolean = true,
var orderBy: String? = null,
val order_by: String? = null,
val language: String? = null,
var copilotIds: List<Long>? = null
var copilotIds: List<Long>? = null,
val copilot_ids: List<Long>? = null
) {

/*
* 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名
* 因为 Get 请求传入的参数不是 JSON,所以没办法使用 Jackson 的注解直接实现别名
* 添加 @JsonAlias 和 @JsonIgnore 注解只是为了保障 Swagger 的文档正确显示
* (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名)
*/
@JsonIgnore
@Suppress("unused")
fun setLevel_keyword(levelKeyword: String?) {
this.levelKeyword = levelKeyword
}

@JsonIgnore
@Suppress("unused")
fun setUploader_id(uploaderId: String?) {
this.uploaderId = uploaderId
}

@JsonIgnore
@Suppress("unused")
fun setOrder_by(orderBy: String?) {
this.orderBy = orderBy
}

@JsonIgnore
@Suppress("unused")
fun setCopilot_ids(copilotIds: List<Long>?) {
this.copilotIds = copilotIds
}
// /*
// * 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名
// * 因为 Get 请求传入的参数不是 JSON,所以没办法使用 Jackson 的注解直接实现别名
// * 添加 @JsonAlias 和 @JsonIgnore 注解只是为了保障 Swagger 的文档正确显示
// * (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名)
// */
// @JsonIgnore
// @Suppress("unused")
// fun setLevel_keyword(levelKeyword: String?) {
// this.levelKeyword = levelKeyword
// }
//
// @JsonIgnore
// @Suppress("unused")
// fun setUploader_id(uploaderId: String?) {
// this.uploaderId = uploaderId
// }
//
// @JsonIgnore
// @Suppress("unused")
// fun setCopilot_ids(copilotIds: List<Long>?) {
// this.copilotIds = copilotIds
// }
}

0 comments on commit 0a4411b

Please sign in to comment.