提交 0a49d8b4 authored 作者: mooncake9527's avatar mooncake9527

change page response

上级 55456d37
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity" "gitlab.wanzhuangkj.com/tush/xpkg/httpcli/entity"
"gitlab.wanzhuangkj.com/tush/xpkg/sgorm/query"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
...@@ -164,26 +163,51 @@ func Success(c *gin.Context, data ...interface{}) { ...@@ -164,26 +163,51 @@ func Success(c *gin.Context, data ...interface{}) {
respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), data...) respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), data...)
} }
// SuccessWithPage return success
//
// func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
// currPage := 1
// pageSize := 10
// if req, ok := c.Get("reqbody"); ok {
// if pagination, ok := req.(query.IPagination); ok {
// currPage = pagination.GetPageIndex()
// pageSize = pagination.GetPageSize()
// }
// }
// totalPage := total / int64(pageSize)
// if total%int64(pageSize) > 0 {
// totalPage = totalPage + 1
// }
// c.Set(ctxUtils.KeyRspCode, 1)
// if list == nil {
// list = []*T{}
// }
// respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), gin.H{
// "list": list, "totalCount": total, "currPage": currPage, "pageSize": pageSize, "totalPage": totalPage,
// })
// }
//
// SuccessWithPage return success // SuccessWithPage return success
func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) { func SuccessWithPage[T any](c *gin.Context, list []*T, total int64) {
currPage := 1 // currPage := 1
pageSize := 10 // pageSize := 10
if req, ok := c.Get("reqbody"); ok { // if req, ok := c.Get("reqbody"); ok {
if pagination, ok := req.(query.IPagination); ok { // if pagination, ok := req.(query.IPagination); ok {
currPage = pagination.GetPageIndex() // currPage = pagination.GetPageIndex()
pageSize = pagination.GetPageSize() // pageSize = pagination.GetPageSize()
} // }
} // }
totalPage := total / int64(pageSize) // totalPage := total / int64(pageSize)
if total%int64(pageSize) > 0 { // if total%int64(pageSize) > 0 {
totalPage = totalPage + 1 // totalPage = totalPage + 1
} // }
c.Set(ctxUtils.KeyRspCode, 1) c.Set(ctxUtils.KeyRspCode, 1)
if list == nil { if list == nil {
list = []*T{} list = []*T{}
} }
respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), gin.H{ respJSONWith200(c, errcode.Success.Code(), errcode.Success.Msg(), gin.H{
"list": list, "totalCount": total, "currPage": currPage, "pageSize": pageSize, "totalPage": totalPage, "list": list, "total": total,
}) })
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论