This commit is contained in:
Mike Schwörer 2023-06-07 10:42:56 +02:00
parent 5fb2f8a312
commit b16d5152c7
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 18 additions and 2 deletions

View File

@ -6,5 +6,5 @@ import (
type Filter interface {
FilterQuery() mongo.Pipeline
Pagination() (string, SortDirection, *string, *SortDirection)
Pagination() (string, SortDirection, string, SortDirection)
}

View File

@ -1,5 +1,11 @@
package wmo
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
func (c *Coll[TData]) DeleteOne(ctx context.Context, id EntityID) error {
_, err := c.coll.DeleteOne(ctx, bson.M{"_id": id})
if err != nil {

View File

@ -13,7 +13,17 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
pipeline := filter.FilterQuery()
sortPrimary, sortDirPrimary, sortSecondary, sortDirSecondary := filter.Pagination()
pf1, pd1, pf2, pd2 := filter.Pagination()
sortPrimary := pf1
sortDirPrimary := pd1
sortSecondary := &pf2
sortDirSecondary := &pd2
if pf1 == pf2 {
sortSecondary = nil
sortDirSecondary = nil
}
paginationPipeline, err := CreatePagination(c, inTok, sortPrimary, sortDirPrimary, sortSecondary, sortDirSecondary, pageSize)
if err != nil {