- 新增 respondError:JSON 安全编码,客户端错误返回 400,服务端错误返回 500 - 收编 book/content/media/category 中 13 处 fmt.Fprintf 内联 JSON,修复错误信息含引号/换行时产出非法 JSON 的问题 - search/detail/catalog/multi-detail/content/multi-content/item-summary/audio/video 补必需参数校验,缺参返回 400 - search 的 offset/tab_type 非数字时返回 400,不再静默置 0 - 补齐 multi-detail/multi-content 的请求统计计数 - 新增 error_response_test.go:3 个测试锁定错误响应行为 - openapi.yaml 新增 ServerError 响应组件,15 个业务接口补 400/500 响应定义 BREAKING CHANGE: 业务接口错误不再返回 HTTP 200,缺参返回 400,上游失败返回 500
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fanqie/internal/fqapi"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// HandleCategoryFront 分类列表处理
|
|
func HandleCategoryFront(w http.ResponseWriter, r *http.Request) {
|
|
incrementStat("total", "category")
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
|
tab := r.URL.Query().Get("tab")
|
|
|
|
result, err := fqapi.HandleCategoryFront(tab)
|
|
if err != nil {
|
|
respondError(w, "获取分类列表失败: "+err.Error(), false)
|
|
return
|
|
}
|
|
|
|
fmt.Fprint(w, result)
|
|
}
|
|
|
|
// HandleCategoryLanding 分类详情处理
|
|
func HandleCategoryLanding(w http.ResponseWriter, r *http.Request) {
|
|
incrementStat("total", "category")
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
|
|
categoryID := r.URL.Query().Get("category_id")
|
|
offset := r.URL.Query().Get("offset")
|
|
wordNumber := r.URL.Query().Get("word_number")
|
|
bookStatus := r.URL.Query().Get("book_status")
|
|
sortBy := r.URL.Query().Get("sort_by")
|
|
|
|
result, err := fqapi.HandleCategoryLanding(categoryID, offset, wordNumber, bookStatus, sortBy)
|
|
if err != nil {
|
|
respondError(w, "获取分类详情失败: "+err.Error(), false)
|
|
return
|
|
}
|
|
|
|
fmt.Fprint(w, result)
|
|
}
|
|
|