admin page updates
This commit is contained in:
@@ -33,6 +33,7 @@ const (
|
||||
LessEqual Comparator = "<="
|
||||
Greater Comparator = ">"
|
||||
GreaterEqual Comparator = ">="
|
||||
In Comparator = "IN"
|
||||
)
|
||||
|
||||
type ListFilter struct {
|
||||
@@ -63,6 +64,10 @@ func (f *ListFilter) GreaterEqualThan(field string, value any) {
|
||||
f.filters = append(f.filters, Filter{field, value, GreaterEqual})
|
||||
}
|
||||
|
||||
func (f *ListFilter) In(field string, values any) {
|
||||
f.filters = append(f.filters, Filter{field, values, In})
|
||||
}
|
||||
|
||||
func GetList[T any](tx bun.Tx) *listgetter[T] {
|
||||
l := &listgetter[T]{
|
||||
items: new([]*T),
|
||||
@@ -89,7 +94,11 @@ func (l *listgetter[T]) Relation(name string, apply ...func(*bun.SelectQuery) *b
|
||||
|
||||
func (l *listgetter[T]) Filter(filters ...Filter) *listgetter[T] {
|
||||
for _, filter := range filters {
|
||||
l.q = l.q.Where("? ? ?", bun.Ident(filter.Field), bun.Safe(filter.Comparator), filter.Value)
|
||||
if filter.Comparator == In {
|
||||
l.q = l.q.Where("? IN (?)", bun.Ident(filter.Field), bun.In(filter.Value))
|
||||
} else {
|
||||
l.q = l.q.Where("? ? ?", bun.Ident(filter.Field), bun.Safe(filter.Comparator), filter.Value)
|
||||
}
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user