goext/pagination/filter.go

30 lines
685 B
Go
Raw Normal View History

package pagination
import (
"go.mongodb.org/mongo-driver/mongo"
ct "gogs.mikescher.com/BlackForestBytes/goext/cursortoken"
)
type Filter interface {
FilterQuery() mongo.Pipeline
Pagination() (string, ct.SortDirection)
}
2023-11-08 19:01:15 +01:00
type dynamicFilter struct {
pipeline mongo.Pipeline
sortField string
sortDir ct.SortDirection
}
func (d dynamicFilter) FilterQuery() mongo.Pipeline {
return d.pipeline
}
func (d dynamicFilter) Pagination() (string, ct.SortDirection) {
return d.sortField, d.sortDir
}
func CreateFilter(pipeline mongo.Pipeline, sortField string, sortdir ct.SortDirection) Filter {
return dynamicFilter{pipeline: pipeline, sortField: sortField, sortDir: sortdir}
}