feat(user):基本完成用户分页查询列表功能,待测。

This commit is contained in:
徐涛
2022-08-12 15:22:34 +08:00
parent cba0968e18
commit dd38fd6d6f
4 changed files with 96 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package response
import (
"electricity_bill_calc/config"
"net/http"
"github.com/gin-gonic/gin"
@@ -16,9 +17,9 @@ type BaseResponse struct {
}
type PagedResponse struct {
Page int `json:"page"`
Size int `json:"pageSize"`
Total int `json:"total"`
Page int `json:"current"`
Size int `json:"pageSize"`
Total int64 `json:"total"`
}
func NewResult(ctx *gin.Context) *Result {
@@ -96,3 +97,15 @@ func (r *Result) Json(status, code int, msg string, payloads ...map[string]inter
r.Ctx.JSON(status, finalPayload)
}
func NewPagedResponse(page int, total int64) *PagedResponse {
return &PagedResponse{page, config.ServiceSettings.ItemsPageSize, total}
}
func (r PagedResponse) ToMap() map[string]interface{} {
return gin.H{
"current": r.Page,
"pageSize": r.Size,
"total": r.Total,
}
}