From 4cb6faefdc18dc5f6a1438ae1efc56cb20982871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Fri, 11 Apr 2025 07:23:42 +0800 Subject: [PATCH] feat: update service --- pkg/repository/user_wallet.go | 18 +++++++++ pkg/repository/wallet.go | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 pkg/repository/user_wallet.go create mode 100644 pkg/repository/wallet.go diff --git a/pkg/repository/user_wallet.go b/pkg/repository/user_wallet.go new file mode 100644 index 0000000..eefbd5e --- /dev/null +++ b/pkg/repository/user_wallet.go @@ -0,0 +1,18 @@ +package repository + +import ( + "code.30cm.net/digimon/app-cloudep-wallet-service/pkg/domain/entity" + "github.com/shopspring/decimal" + "gorm.io/gorm" +) + +func NewUserWallet(db *gorm.DB, uid, crypto string) repository.UserWallet { + return &userWallet{ + db: db, + uid: uid, + crypto: crypto, + + localWalletBalance: make(map[domain.WalletType]entity.Wallet, len(domain.WalletAllType)), + localOrderBalance: make(map[int64]decimal.Decimal, len(domain.WalletAllType)), + } +} diff --git a/pkg/repository/wallet.go b/pkg/repository/wallet.go new file mode 100644 index 0000000..500f656 --- /dev/null +++ b/pkg/repository/wallet.go @@ -0,0 +1,70 @@ +package repository + +import ( + "code.30cm.net/digimon/app-cloudep-wallet-service/pkg/domain/entity" + "code.30cm.net/digimon/app-cloudep-wallet-service/pkg/domain/repository" + "context" + "database/sql" + "gorm.io/gorm" +) + +type WalletRepositoryParam struct { + DB *gorm.DB `name:"dbM"` +} + +type WalletRepository struct { + WalletRepositoryParam +} + +func MustCategoryRepository(param WalletRepositoryParam) repository.WalletRepository { + return &WalletRepository{ + param, + } +} + +func (repo *WalletRepository) NewDB() *gorm.DB { + return repo.DB +} + +func (repo *WalletRepository) Transaction(fn func(db *gorm.DB) error) error { + db := repo.DB.Begin(&sql.TxOptions{ + Isolation: sql.LevelReadCommitted, + ReadOnly: false, + }) + defer db.Rollback() + + if err := fn(db); err != nil { + return err + } + + if err := db.Commit().Error; err != nil { + return err + } + + return nil +} + +func (repo *WalletRepository) Session(uid, asset string) repository.UserWalletService { + //TODO implement me + panic("implement me") +} + +func (repo *WalletRepository) SessionWithTx(db *gorm.DB, uid, asset string) repository.UserWalletService { + //TODO implement me + panic("implement me") +} + +func (repo *WalletRepository) InitWallets(ctx context.Context, param []repository.Wallet) error { + //TODO implement me + panic("implement me") +} + +func (repo *WalletRepository) QueryBalances(ctx context.Context, req repository.BalanceQuery) ([]entity.Wallet, error) { + //TODO implement me + panic("implement me") +} + +func (repo *WalletRepository) QueryBalancesByUIDs(ctx context.Context, uids []string, req repository.BalanceQuery) ([]entity.Wallet, error) { + //TODO implement me + panic("implement me") +}