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"
|
|
|
|
)
|
|
|
|
|
2024-01-13 21:36:47 +01:00
|
|
|
type MongoFilter interface {
|
2023-11-08 18:30:30 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-01-13 21:36:47 +01:00
|
|
|
func CreateFilter(pipeline mongo.Pipeline, sort bson.D) MongoFilter {
|
2023-11-09 10:00:01 +01:00
|
|
|
return dynamicFilter{pipeline: pipeline, sort: sort}
|
2023-11-08 19:01:15 +01:00
|
|
|
}
|