admin page updates

This commit is contained in:
2026-02-14 14:54:06 +11:00
parent 55f79176cc
commit 0fc3bb0c94
22 changed files with 2136 additions and 318 deletions

View File

@@ -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
}