refactor AccountFilter into databasePackage
This commit is contained in:
parent
489137b24e
commit
7c19e9d87c
3 changed files with 32 additions and 30 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue