fixed wallet fetcher

This commit is contained in:
Stephan D
2025-12-26 01:21:16 +01:00
parent 8ee092089f
commit 3bb33b8895
4 changed files with 42 additions and 39 deletions

View File

@@ -14,6 +14,7 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.uber.org/zap"
@@ -110,13 +111,16 @@ func (w *Wallets) Create(ctx context.Context, wallet *model.ManagedWallet) (*mod
return wallet, nil
}
func (w *Wallets) Get(ctx context.Context, walletRef string) (*model.ManagedWallet, error) {
walletRef = strings.TrimSpace(walletRef)
if walletRef == "" {
return nil, merrors.InvalidArgument("walletsStore: empty walletRef")
func (w *Wallets) Get(ctx context.Context, walletID string) (*model.ManagedWallet, error) {
walletID = strings.TrimSpace(walletID)
walletRef, err := primitive.ObjectIDFromHex(walletID)
if err != nil {
w.logger.Warn("Invalid wallet refernce", zap.Error(err), zap.String("wallet_id", walletID))
return nil, err
}
wallet := &model.ManagedWallet{}
if err := w.walletRepo.FindOneByFilter(ctx, repository.Filter("walletRef", walletRef), wallet); err != nil {
if err := w.walletRepo.Get(ctx, walletRef, wallet); err != nil {
w.logger.Warn("Managed wallet not found", zap.Error(err), mzap.ObjRef("wallet_ref", walletRef))
return nil, err
}
return wallet, nil
@@ -142,7 +146,7 @@ func (w *Wallets) List(ctx context.Context, filter model.ManagedWalletFilter) (*
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
query = query.Comparison(repository.IDField(), builder.Gt, oid)
} else {
w.logger.Warn("ignoring invalid wallet cursor", zap.String("cursor", cursor), zap.Error(err))
w.logger.Warn("Ignoring invalid wallet cursor", zap.String("cursor", cursor), zap.Error(err))
}
}
@@ -211,13 +215,13 @@ func (w *Wallets) SaveBalance(ctx context.Context, balance *model.WalletBalance)
}
}
func (w *Wallets) GetBalance(ctx context.Context, walletRef string) (*model.WalletBalance, error) {
walletRef = strings.TrimSpace(walletRef)
if walletRef == "" {
func (w *Wallets) GetBalance(ctx context.Context, walletID string) (*model.WalletBalance, error) {
walletID = strings.TrimSpace(walletID)
if walletID == "" {
return nil, merrors.InvalidArgument("walletsStore: empty walletRef")
}
balance := &model.WalletBalance{}
if err := w.balanceRepo.FindOneByFilter(ctx, repository.Filter("walletRef", walletRef), balance); err != nil {
if err := w.balanceRepo.FindOneByFilter(ctx, repository.Filter("walletRef", walletID), balance); err != nil {
return nil, err
}
return balance, nil