stillbox/internal/common/pagination.go
Daniel Ponte 77a08679d4 Call store and list calls endpoint (#78)
Reviewed-on: #78
Co-authored-by: Daniel Ponte <amigan@gmail.com>
Co-committed-by: Daniel Ponte <amigan@gmail.com>
2024-12-19 16:14:41 -05:00

44 lines
713 B
Go

package common
type Pagination struct {
Page *int `json:"page"`
PerPage *int `json:"perPage"`
}
func (p Pagination) OffsetPerPage(perPageDefault int) (offset int32, perPage int32) {
page := int32(DefaultIfNilOrZero(p.Page, 1))
perPage = int32(DefaultIfNilOrZero(p.PerPage, perPageDefault))
offset = (page - 1) * perPage
return
}
type SortDirection string
const (
DirAsc SortDirection = "asc"
DirDesc SortDirection = "desc"
)
func (t *SortDirection) DirString(def SortDirection) string {
if t == nil {
return string(def)
}
return string(*t)
}
func (t *SortDirection) IsValid() bool {
if t == nil {
return true
}
switch *t {
case DirAsc, DirDesc:
return true
}
return false
}