refactor AccountFilter into databasePackage

This commit is contained in:
dhax 2019-01-01 19:59:20 +01:00
parent 489137b24e
commit 7c19e9d87c
3 changed files with 32 additions and 30 deletions

View file

@ -1,7 +1,6 @@
package pwdless
import (
"net/url"
"strings"
"time"
@ -60,7 +59,7 @@ func (a *Account) Validate() error {
)
}
// CanLogin returns true if is user is allowed to login.
// CanLogin returns true if user is allowed to login.
func (a *Account) CanLogin() bool {
return a.Active
}
@ -73,27 +72,3 @@ func (a *Account) Claims() jwtauth.Claims {
"roles": a.Roles,
}
}
// AccountFilter provides pagination and filtering options on accounts.
type AccountFilter struct {
orm.Pager
Filters url.Values
Order []string
}
// Filter applies an AccountFilter on an orm.Query.
func (f *AccountFilter) Filter(q *orm.Query) (*orm.Query, error) {
q = q.Apply(f.Pager.Paginate)
q = q.Apply(orm.URLFilters(f.Filters))
q = q.Order(f.Order...)
return q, nil
}
// NewAccountFilter returns an AccountFilter with options parsed from request url values.
func NewAccountFilter(v url.Values) AccountFilter {
var f AccountFilter
f.SetURLValues(v)
f.Filters = v
f.Order = v["order"]
return f
}