Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
45031b05cf
|
|||
7413ea045d
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.301"
|
const GoextVersion = "0.0.303"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2023-11-08T18:30:30+0100"
|
const GoextVersionTimestamp = "2023-11-08T19:01:15+0100"
|
||||||
|
@@ -9,3 +9,21 @@ type Filter interface {
|
|||||||
FilterQuery() mongo.Pipeline
|
FilterQuery() mongo.Pipeline
|
||||||
Pagination() (string, ct.SortDirection)
|
Pagination() (string, ct.SortDirection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dynamicFilter struct {
|
||||||
|
pipeline mongo.Pipeline
|
||||||
|
sortField string
|
||||||
|
sortDir ct.SortDirection
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dynamicFilter) FilterQuery() mongo.Pipeline {
|
||||||
|
return d.pipeline
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dynamicFilter) Pagination() (string, ct.SortDirection) {
|
||||||
|
return d.sortField, d.sortDir
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateFilter(pipeline mongo.Pipeline, sortField string, sortdir ct.SortDirection) Filter {
|
||||||
|
return dynamicFilter{pipeline: pipeline, sortField: sortField, sortDir: sortdir}
|
||||||
|
}
|
||||||
|
@@ -36,9 +36,11 @@ func (c *Coll[TData]) Paginate(ctx context.Context, filter pag.Filter, page int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pipelinePaginate := mongo.Pipeline{}
|
pipelinePaginate := mongo.Pipeline{}
|
||||||
pipelinePaginate = append(pipelinePaginate, bson.D{{Key: "$skip", Value: page - 1}})
|
|
||||||
if limit != nil {
|
if limit != nil {
|
||||||
|
pipelinePaginate = append(pipelinePaginate, bson.D{{Key: "$skip", Value: *limit * (page - 1)}})
|
||||||
pipelinePaginate = append(pipelinePaginate, bson.D{{Key: "$limit", Value: *limit}})
|
pipelinePaginate = append(pipelinePaginate, bson.D{{Key: "$limit", Value: *limit}})
|
||||||
|
} else {
|
||||||
|
page = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
pipelineCount := mongo.Pipeline{}
|
pipelineCount := mongo.Pipeline{}
|
||||||
|
Reference in New Issue
Block a user