Organize backend into product executable and shared Go modules
This commit is contained in:
1 parent
981e84a4b4
commit
f0720ec66b
382 files changed
+1944
-6989
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package mutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
sharedmodel "git.sendico.io/tech/sxchnge/shared/model"
|
||||
|
||||
"git.sendico.io/tech/sxchnge/shared/database/repository"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/repository/builder"
|
||||
"git.sendico.io/tech/sxchnge/shared/logging"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func GetObjects[T any](ctx context.Context, logger mlogger.Logger, filter builder.Query, cursor *sharedmodel.ViewCursor, repo repository.Repository) ([]T, error) {
|
||||
entities := make([]T, 0)
|
||||
decoder := func(cur *mongo.Cursor) error {
|
||||
var next T
|
||||
if e := cur.Decode(&next); e != nil {
|
||||
logger.Warn("Failed to decode entity", zap.Error(e))
|
||||
return e
|
||||
}
|
||||
entities = append(entities, next)
|
||||
return nil
|
||||
}
|
||||
return entities, repo.FindManyByFilter(ctx, repository.ApplyCursor(filter, cursor), decoder)
|
||||
}
|
||||
Reference in new issue
Block a user