goext/pagination/filter.go

30 lines
601 B
Go
Raw Normal View History

package pagination
import (
"context"
2023-11-09 10:00:01 +01:00
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
2024-01-13 21:36:47 +01:00
type MongoFilter interface {
FilterQuery(ctx context.Context) mongo.Pipeline
Sort(ctx context.Context) 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(ctx context.Context) mongo.Pipeline {
2023-11-08 19:01:15 +01:00
return d.pipeline
}
func (d dynamicFilter) Sort(ctx context.Context) bson.D {
2023-11-09 10:00:01 +01:00
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
}