goext/pagination/filter.go

29 lines
504 B
Go
Raw Normal View History

package pagination
import (
2023-11-09 10:00:01 +01:00
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
type Filter interface {
FilterQuery() mongo.Pipeline
2023-11-09 10:00:01 +01:00
Sort() bson.D
}
2023-11-08 19:01:15 +01:00
type dynamicFilter struct {
2023-11-09 10:00:01 +01:00
pipeline mongo.Pipeline
sort bson.D
2023-11-08 19:01:15 +01:00
}
func (d dynamicFilter) FilterQuery() mongo.Pipeline {
return d.pipeline
}
2023-11-09 10:00:01 +01:00
func (d dynamicFilter) Sort() bson.D {
return d.sort
2023-11-08 19:01:15 +01:00
}
2023-11-09 10:00:01 +01:00
func CreateFilter(pipeline mongo.Pipeline, sort bson.D) Filter {
return dynamicFilter{pipeline: pipeline, sort: sort}
2023-11-08 19:01:15 +01:00
}