Files
xuanzhi-service/server/api/v1/book/common.go
wdh-home 1e33640629
Some checks failed
CI / init (pull_request) Has been cancelled
CI / Frontend node 18.16.0 (pull_request) Has been cancelled
CI / Backend go (1.22) (pull_request) Has been cancelled
CI / release-pr (pull_request) Has been cancelled
CI / devops-test (1.22, 18.16.0) (pull_request) Has been cancelled
CI / release-please (pull_request) Has been cancelled
CI / devops-prod (1.22, 18.x) (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
基础项目
2026-04-26 15:32:21 +08:00

51 lines
1.4 KiB
Go

package book
import (
"fmt"
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
"github.com/gin-gonic/gin"
)
func bindID(c *gin.Context) (uint, bool) {
var req commonReq.GetById
if err := c.ShouldBindQuery(&req); err != nil {
response.FailWithMessage(err.Error(), c)
return 0, false
}
if err := utils.Verify(req, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return 0, false
}
return req.Uint(), true
}
func bindIDs(c *gin.Context) (commonReq.IdsReq, bool) {
var req commonReq.IdsReq
if err := c.ShouldBindQuery(&req); err != nil {
response.FailWithMessage(err.Error(), c)
return req, false
}
if len(req.Ids) == 0 {
for _, rawID := range c.QueryArray("ids[]") {
var id int
if _, err := fmt.Sscanf(rawID, "%d", &id); err != nil {
response.FailWithMessage(err.Error(), c)
return req, false
}
req.Ids = append(req.Ids, id)
}
}
if len(req.Ids) == 0 {
response.FailWithMessage("ids不能为空", c)
return req, false
}
return req, true
}
func pageResult(c *gin.Context, list interface{}, total int64, page commonReq.PageInfo) {
response.OkWithDetailed(response.PageResult{List: list, Total: total, Page: page.Page, PageSize: page.PageSize}, "获取成功", c)
}