v0.0.248 exerr in wmo package
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 55s
Some checks failed
Build Docker and Deploy / Run goext test-suite (push) Failing after 55s
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int, inTok ct.CursorToken) ([]TData, ct.CursorToken, error) {
|
||||
@@ -35,21 +36,31 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
|
||||
|
||||
paginationPipeline, err := CreatePagination(c, inTok, sortPrimary, sortDirPrimary, sortSecondary, sortDirSecondary, pageSize)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, err
|
||||
return nil, ct.CursorToken{}, exerr.
|
||||
Wrap(err, "failed to create pagination").
|
||||
WithType(exerr.TypeCursorTokenDecode).
|
||||
Str("collection", c.Name()).
|
||||
Any("inTok", inTok).
|
||||
Any("sortPrimary", sortPrimary).
|
||||
Any("sortDirPrimary", sortDirPrimary).
|
||||
Any("sortSecondary", sortSecondary).
|
||||
Any("sortDirSecondary", sortDirSecondary).
|
||||
Any("pageSize", pageSize).
|
||||
Build()
|
||||
}
|
||||
|
||||
pipeline = append(pipeline, paginationPipeline...)
|
||||
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, err
|
||||
return nil, ct.CursorToken{}, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
||||
}
|
||||
|
||||
// fast branch
|
||||
if pageSize == nil {
|
||||
entries, err := c.decodeAll(ctx, cursor)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, err
|
||||
return nil, ct.CursorToken{}, exerr.Wrap(err, "failed to all-decode entities").Build()
|
||||
}
|
||||
return entries, ct.End(), nil
|
||||
}
|
||||
@@ -59,7 +70,7 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
|
||||
var entry TData
|
||||
entry, err = c.decodeSingle(ctx, cursor)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, err
|
||||
return nil, ct.CursorToken{}, exerr.Wrap(err, "failed to decode entity").Build()
|
||||
}
|
||||
entities = append(entities, entry)
|
||||
}
|
||||
@@ -74,7 +85,7 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
|
||||
|
||||
nextToken, err := c.createToken(sortPrimary, sortDirPrimary, sortSecondary, sortDirSecondary, last, pageSize)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, err
|
||||
return nil, ct.CursorToken{}, exerr.Wrap(err, "failed to create (out)-token").Build()
|
||||
}
|
||||
|
||||
return entities, nextToken, nil
|
||||
@@ -91,14 +102,14 @@ func (c *Coll[TData]) Count(ctx context.Context, filter ct.Filter) (int64, error
|
||||
|
||||
cursor, err := c.coll.Aggregate(ctx, pipeline)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build()
|
||||
}
|
||||
|
||||
if cursor.Next(ctx) {
|
||||
v := countRes{}
|
||||
err = cursor.Decode(&v)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, exerr.Wrap(err, "failed to decode entity").Build()
|
||||
}
|
||||
return v.Count, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user