feat: update service

This commit is contained in:
王性驊 2025-04-11 07:23:42 +08:00
parent 2f5b04de29
commit 4cb6faefdc
2 changed files with 88 additions and 0 deletions

View File

@ -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)),
}
}

70
pkg/repository/wallet.go Normal file
View File

@ -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")
}