Skip to content

Commit

Permalink
Merge pull request #167 from Lixuhuilll/BindParam
Browse files Browse the repository at this point in the history
使用@BindParam以同时适配驼峰和SnakeCase
  • Loading branch information
Handiwork authored Mar 2, 2024
2 parents 0a4411b + 883f67c commit 936f65c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 47 deletions.
13 changes: 0 additions & 13 deletions src/main/kotlin/plus/maa/backend/controller/CopilotController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,6 @@ 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,7 @@
package plus.maa.backend.controller.request.copilot

import jakarta.validation.constraints.Max
import org.springframework.web.bind.annotation.BindParam

/**
* @author LoMu
Expand All @@ -9,42 +10,13 @@ import jakarta.validation.constraints.Max
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,
@BindParam("level_keyword") var levelKeyword: String? = null,
val operator: String? = null,
val content: String? = null,
val document: String? = null,
var uploaderId: String? = null,
val uploader_id: String? = null,
@BindParam("uploader_id") var uploaderId: String? = null,
val desc: Boolean = true,
var orderBy: String? = null,
val order_by: String? = null,
@BindParam("order_by") var orderBy: String? = null,
val language: String? = 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 setCopilot_ids(copilotIds: List<Long>?) {
// this.copilotIds = copilotIds
// }
}
@BindParam("copilot_ids") var copilotIds: List<Long>? = null,
)

0 comments on commit 936f65c

Please sign in to comment.