more refactors
This commit is contained in:
@@ -19,21 +19,25 @@ type OrderOpts struct {
|
||||
Label string
|
||||
}
|
||||
|
||||
func setPageOpts(q *bun.SelectQuery, p *PageOpts, page, perpage int, order bun.Order, orderby string) (*bun.SelectQuery, *PageOpts) {
|
||||
func setPageOpts(q *bun.SelectQuery, p, d *PageOpts, totalitems int) (*bun.SelectQuery, *PageOpts) {
|
||||
if p == nil {
|
||||
p = new(PageOpts)
|
||||
}
|
||||
if p.Page == 0 {
|
||||
p.Page = page
|
||||
if p.Page <= 0 {
|
||||
p.Page = d.Page
|
||||
}
|
||||
if p.PerPage == 0 {
|
||||
p.PerPage = perpage
|
||||
p.PerPage = d.PerPage
|
||||
}
|
||||
maxpage := p.TotalPages(totalitems)
|
||||
if p.Page > maxpage {
|
||||
p.Page = maxpage
|
||||
}
|
||||
if p.Order == "" {
|
||||
p.Order = order
|
||||
p.Order = d.Order
|
||||
}
|
||||
if p.OrderBy == "" {
|
||||
p.OrderBy = orderby
|
||||
p.OrderBy = d.OrderBy
|
||||
}
|
||||
p.OrderBy = sanitiseOrderBy(p.OrderBy)
|
||||
q = q.OrderBy(p.OrderBy, p.Order).
|
||||
|
||||
Reference in New Issue
Block a user