2023-11-08 18:30:30 +01:00
|
|
|
package pagination
|
|
|
|
|
|
|
|
import (
|
2024-06-14 17:24:59 +02:00
|
|
|
"context"
|
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 {
|
2024-06-14 17:24:59 +02:00
|
|
|
FilterQuery(ctx context.Context) mongo.Pipeline
|
|
|
|
Sort(ctx context.Context) 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
|
|
|
}
|
|
|
|
|
2024-06-14 17:24:59 +02:00
|
|
|
func (d dynamicFilter) FilterQuery(ctx context.Context) mongo.Pipeline {
|
2023-11-08 19:01:15 +01:00
|
|
|
return d.pipeline
|
|
|
|
}
|
|
|
|
|
2024-06-14 17:24:59 +02:00
|
|
|
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
|
|
|
}
|