Closed bonedaddy closed 4 years ago
Example
// TODO(bonedaddy): add tests
if c.Param("paged") == "true" {
page := c.Param("page")
if page == "" {
page = "1"
}
limit := c.Param("limit")
if limit == "" {
limit = "10"
}
pageInt, err := strconv.Atoi(page)
if err != nil {
Fail(c, err, http.StatusBadRequest)
return
}
limitInt, err := strconv.Atoi(limit)
if err != nil {
Fail(c, err, http.StatusBadRequest)
return
}
var uploads []models.Upload
paged, err := gpaginator.Paging(
&gpaginator.Param{
DB: api.upm.DB.Where("user_name = ?", username),
Page: pageInt,
Limit: limitInt,
},
&uploads,
)
if err != nil {
api.LogError(c, err, "failed to get paged user upload")
return
}
Respond(c, http.StatusOK, gin.H{"response": paged})
return
}
Why are you submitting this feature request Certain APIs can have massive payloads, for example accounts that have thousands of uploads.
Describe the solution you'd like Be able to return paginated results from APIs that return large payloads
Describe alternatives you've considered
N/A
Additional context
~https://github.com/biezhi/gorm-paginator~ Use our fork https://github.com/RTradeLtd/gpaginator