2023-11-08 18:30:30 +01:00
|
|
|
package pagination
|
|
|
|
|
|
|
|
import (
|
2023-11-09 10:00:01 +01:00
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
2023-11-08 18:30:30 +01:00
|
|
|
"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 18:30:30 +01:00
|
|
|
}
|
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
|
|
|
}
|