1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/server/router/middleware/session/pagination.go
qwerty287 0f9188597e
Initiate Pagination Implementation for API and Infinite Scroll in UI (#1651)
- Add pagination support to the API endpoints that return lists of items
- Adjust UI to enable infinite scrolling via pagination
2023-04-30 03:40:13 +02:00

26 lines
523 B
Go

package session
import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/woodpecker-ci/woodpecker/server/model"
)
const maxPageSize = 50
func Pagination(c *gin.Context) *model.ListOptions {
page, err := strconv.ParseInt(c.Query("page"), 10, 64)
if err != nil || page < 1 {
page = 1
}
perPage, err := strconv.ParseInt(c.Query("perPage"), 10, 64)
if err != nil || perPage < 1 || perPage > maxPageSize {
perPage = maxPageSize
}
return &model.ListOptions{
Page: int(page),
PerPage: int(perPage),
}
}