update: database records for all resources.

This commit is contained in:
Andrey Melnikov
2020-04-27 09:32:45 -07:00
parent d42bffa0e2
commit 1920eb5ed0
18 changed files with 851 additions and 303 deletions

View File

@@ -0,0 +1,46 @@
package pagination
import (
"github.com/Masterminds/squirrel"
"math"
)
type PaginationRequest struct {
Page uint64
PageSize uint64
}
func NewRequest(page, pageSize int32) PaginationRequest {
if page == 0 {
page = 1
}
if pageSize == 0 {
pageSize = 15
}
return PaginationRequest{
Page: uint64(page),
PageSize: uint64(pageSize),
}
}
func (pr *PaginationRequest) Offset() uint64 {
// start at page 1.
return (pr.Page - 1) * pr.PageSize
}
func (pr *PaginationRequest) CalculatePages(count int) int32 {
return int32(math.Ceil(float64(count) / float64(pr.PageSize)))
}
func (pr *PaginationRequest) ApplyToSelect(sb *squirrel.SelectBuilder) *squirrel.SelectBuilder {
if pr == nil {
return sb
}
result := sb.Limit(pr.PageSize).
Offset(pr.Offset())
return &result
}