v0.0.473 add ctx to wmo.FilterQuery|Sort|Pagination
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m23s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m23s
This commit is contained in:
parent
94a7bf250d
commit
fc4bed4b9f
@ -1,14 +1,15 @@
|
|||||||
package cursortoken
|
package cursortoken
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RawFilter interface {
|
type RawFilter interface {
|
||||||
FilterQuery() mongo.Pipeline
|
FilterQuery(ctx context.Context) mongo.Pipeline
|
||||||
}
|
}
|
||||||
|
|
||||||
type Filter interface {
|
type Filter interface {
|
||||||
FilterQuery() mongo.Pipeline
|
FilterQuery(ctx context.Context) mongo.Pipeline
|
||||||
Pagination() (string, SortDirection, string, SortDirection)
|
Pagination(ctx context.Context) (string, SortDirection, string, SortDirection)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.472"
|
const GoextVersion = "0.0.473"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-06-14T14:56:41+0200"
|
const GoextVersionTimestamp = "2024-06-14T17:24:59+0200"
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package pagination
|
package pagination
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MongoFilter interface {
|
type MongoFilter interface {
|
||||||
FilterQuery() mongo.Pipeline
|
FilterQuery(ctx context.Context) mongo.Pipeline
|
||||||
Sort() bson.D
|
Sort(ctx context.Context) bson.D
|
||||||
}
|
}
|
||||||
|
|
||||||
type dynamicFilter struct {
|
type dynamicFilter struct {
|
||||||
@ -15,11 +16,11 @@ type dynamicFilter struct {
|
|||||||
sort bson.D
|
sort bson.D
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dynamicFilter) FilterQuery() mongo.Pipeline {
|
func (d dynamicFilter) FilterQuery(ctx context.Context) mongo.Pipeline {
|
||||||
return d.pipeline
|
return d.pipeline
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dynamicFilter) Sort() bson.D {
|
func (d dynamicFilter) Sort(ctx context.Context) bson.D {
|
||||||
return d.sort
|
return d.sort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
|
|||||||
pd2 := ct.SortASC
|
pd2 := ct.SortASC
|
||||||
|
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
pipeline = filter.FilterQuery()
|
pipeline = filter.FilterQuery(ctx)
|
||||||
pf1, pd1, pf2, pd2 = filter.Pagination()
|
pf1, pd1, pf2, pd2 = filter.Pagination(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
sortPrimary := pf1
|
sortPrimary := pf1
|
||||||
@ -109,7 +109,7 @@ func (c *Coll[TData]) Count(ctx context.Context, filter ct.RawFilter) (int64, er
|
|||||||
Count int64 `bson:"c"`
|
Count int64 `bson:"c"`
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline := filter.FilterQuery()
|
pipeline := filter.FilterQuery(ctx)
|
||||||
|
|
||||||
pipeline = append(pipeline, bson.D{{Key: "$count", Value: "c"}})
|
pipeline = append(pipeline, bson.D{{Key: "$count", Value: "c"}})
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func (c *Coll[TData]) ListAllIDs(ctx context.Context, filter ct.RawFilter) ([]st
|
|||||||
pipelineFilter := mongo.Pipeline{}
|
pipelineFilter := mongo.Pipeline{}
|
||||||
|
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
pipelineFilter = filter.FilterQuery()
|
pipelineFilter = filter.FilterQuery(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
extrModPipelineResolved := mongo.Pipeline{}
|
extrModPipelineResolved := mongo.Pipeline{}
|
||||||
|
@ -23,8 +23,8 @@ func (c *Coll[TData]) Paginate(ctx context.Context, filter pag.MongoFilter, page
|
|||||||
sort := bson.D{}
|
sort := bson.D{}
|
||||||
|
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
pipelineFilter = filter.FilterQuery()
|
pipelineFilter = filter.FilterQuery(ctx)
|
||||||
sort = filter.Sort()
|
sort = filter.Sort(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sort) != 0 {
|
if len(sort) != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user