forked from ebhomengo/niki
41 lines
673 B
Go
41 lines
673 B
Go
package param
|
|
|
|
const (
|
|
defaultPageNumber = 1
|
|
dafaultPageSize = 10
|
|
)
|
|
|
|
type PaginationRequest struct {
|
|
PageSize uint
|
|
PageNumber uint
|
|
}
|
|
|
|
type PaginationResponse struct {
|
|
PageSize uint
|
|
PageNumber uint
|
|
Total uint
|
|
}
|
|
|
|
func (p *PaginationRequest) GetPageNumber() uint {
|
|
if p.PageNumber <= 0 {
|
|
p.PageNumber = defaultPageNumber
|
|
}
|
|
|
|
return p.PageNumber
|
|
}
|
|
|
|
func (p *PaginationRequest) GetOffset() uint {
|
|
return (p.GetPageNumber() - 1) * p.GetPageSize()
|
|
}
|
|
|
|
func (p *PaginationRequest) GetPageSize() uint {
|
|
validPageSizes := []uint{10, 25, 50, 100}
|
|
for _, size := range validPageSizes {
|
|
if p.PageSize == size {
|
|
return size
|
|
}
|
|
}
|
|
|
|
return dafaultPageSize
|
|
}
|