forked from free-lancers/electricity_bill_calc_service
feat(user):基本完成用户分页查询列表功能,待测。
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user