22 lines
575 B
Go
22 lines
575 B
Go
|
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
|
||
|
|
"github.com/user-management-system/internal/pagination"
|
||
|
|
)
|
||
|
|
|
||
|
|
// parsePageAndSize extracts and validates page & page_size from query parameters.
|
||
|
|
// Returns page (>=1) and pageSize (clamped to [1, MaxPageSize]).
|
||
|
|
func parsePageAndSize(c *gin.Context) (page, pageSize int) {
|
||
|
|
page, _ = strconv.Atoi(c.DefaultQuery("page", "1"))
|
||
|
|
if page < 1 {
|
||
|
|
page = 1
|
||
|
|
}
|
||
|
|
pageSize, _ = strconv.Atoi(c.DefaultQuery("page_size", strconv.Itoa(pagination.DefaultPageSize)))
|
||
|
|
pageSize = pagination.ClampPageSize(pageSize)
|
||
|
|
return
|
||
|
|
}
|