chore: rename some request param

pull/1604/head
Noah Hsu 2022-08-14 23:46:30 +08:00
parent 8cd05275f0
commit 02e2c809a8
6 changed files with 14 additions and 14 deletions

View File

@ -1,8 +1,8 @@
package common
type PageReq struct {
PageIndex int `json:"page_index" form:"page_index"`
PageSize int `json:"page_size" form:"page_size"`
Page int `json:"page_index" form:"page"`
PerPage int `json:"page_size" form:"per_page"`
}
const MaxUint = ^uint(0)
@ -11,10 +11,10 @@ const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1
func (p *PageReq) Validate() {
if p.PageIndex < 1 {
p.PageIndex = 1
if p.Page < 1 {
p.Page = 1
}
if p.PageSize < 1 {
p.PageSize = MaxInt
if p.PerPage < 1 {
p.PerPage = MaxInt
}
}

View File

@ -230,9 +230,9 @@ func FsPut(c *gin.Context) {
common.SuccessResp(c)
}
// Link return real link, just for proxy program, it may contain cookie
// Link return real link, just for proxy program, it may contain cookie, so just allowed for admin
func Link(c *gin.Context) {
var req FsGetOrLinkReq
var req MkdirOrLinkReq
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
return

View File

@ -153,7 +153,7 @@ func canAccess(user *model.User, meta *model.Meta, path string, password string)
}
func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
pageIndex, pageSize := req.PageIndex, req.PageSize
pageIndex, pageSize := req.Page, req.PerPage
total := len(objs)
start := (pageIndex - 1) * pageSize
if start > total {
@ -190,7 +190,7 @@ func toObjResp(objs []model.Obj) []ObjResp {
return resp
}
type FsGetOrLinkReq struct {
type FsGetReq struct {
Path string `json:"path" form:"path"`
Password string `json:"password" form:"password"`
}
@ -204,7 +204,7 @@ type FsGetResp struct {
}
func FsGet(c *gin.Context) {
var req FsGetOrLinkReq
var req FsGetReq
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
return

View File

@ -22,7 +22,7 @@ func ListMetas(c *gin.Context) {
}
req.Validate()
log.Debugf("%+v", req)
metas, total, err := db.GetMetas(req.PageIndex, req.PageSize)
metas, total, err := db.GetMetas(req.Page, req.PerPage)
if err != nil {
common.ErrorResp(c, err, 500, true)
return

View File

@ -19,7 +19,7 @@ func ListStorages(c *gin.Context) {
}
req.Validate()
log.Debugf("%+v", req)
storages, total, err := db.GetStorages(req.PageIndex, req.PageSize)
storages, total, err := db.GetStorages(req.Page, req.PerPage)
if err != nil {
common.ErrorResp(c, err, 500)
return

View File

@ -18,7 +18,7 @@ func ListUsers(c *gin.Context) {
}
req.Validate()
log.Debugf("%+v", req)
users, total, err := db.GetUsers(req.PageIndex, req.PageSize)
users, total, err := db.GetUsers(req.Page, req.PerPage)
if err != nil {
common.ErrorResp(c, err, 500, true)
return