From 623c021689df3947978be6458a7908fe81dc8b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 9 Nov 2023 10:02:31 +0100 Subject: [PATCH] v0.0.308 --- goextVersion.go | 4 ++-- wmo/queryPaginate.go | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index ba66dd9..d604dbe 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.307" +const GoextVersion = "0.0.308" -const GoextVersionTimestamp = "2023-11-09T10:00:01+0100" +const GoextVersionTimestamp = "2023-11-09T10:02:31+0100" diff --git a/wmo/queryPaginate.go b/wmo/queryPaginate.go index fd2309b..fd02462 100644 --- a/wmo/queryPaginate.go +++ b/wmo/queryPaginate.go @@ -4,7 +4,6 @@ import ( "context" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" - ct "gogs.mikescher.com/BlackForestBytes/goext/cursortoken" "gogs.mikescher.com/BlackForestBytes/goext/exerr" "gogs.mikescher.com/BlackForestBytes/goext/langext" pag "gogs.mikescher.com/BlackForestBytes/goext/pagination" @@ -21,18 +20,15 @@ func (c *Coll[TData]) Paginate(ctx context.Context, filter pag.Filter, page int, pipelineSort := mongo.Pipeline{} pipelineFilter := mongo.Pipeline{} - pf1 := "_id" - pd1 := ct.SortASC + sort := bson.D{} if filter != nil { pipelineFilter = filter.FilterQuery() - pf1, pd1 = filter.Pagination() + sort = filter.Sort() } - if pd1 == ct.SortASC { - pipelineSort = append(pipelineSort, bson.D{{Key: "$sort", Value: bson.D{{Key: pf1, Value: +1}}}}) - } else if pd1 == ct.SortDESC { - pipelineSort = append(pipelineSort, bson.D{{Key: "$sort", Value: bson.D{{Key: pf1, Value: -1}}}}) + if len(sort) != 0 { + pipelineSort = append(pipelineSort, bson.D{{Key: "$sort", Value: sort}}) } pipelinePaginate := mongo.Pipeline{}