balance

package
v0.0.0-...-8b1a3a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDepositID

func CreateDepositID(ctx context.Context) string

func CreateUserID

func CreateUserID(ctx context.Context, id int64) string

func RandomOpen

func RandomOpen() map[string]bool

func RandomTags

func RandomTags() []string

func RandomUserID

func RandomUserID(ctx context.Context) string

func SetUserAccountIDMax

func SetUserAccountIDMax(v int64)

SetUserAccountIDMax is default値から変更する場合、アプリケーション起動時に一度だけ呼ぶ

func UserAccountIDMax

func UserAccountIDMax() int64

Types

type DepositAlloyRunner

type DepositAlloyRunner struct {
	Store          *StoreAlloy
	OperationStore *operation.StoreAlloy
}

func (*DepositAlloyRunner) Run

type DepositDMLRunner

type DepositDMLRunner struct {
	BalanceStore   *Store
	OperationStore *operation.Store
}

func (*DepositDMLRunner) Run

func (r *DepositDMLRunner) Run(ctx context.Context) error

type DepositRunner

type DepositRunner struct {
	BalanceStore   *Store
	OperationStore *operation.Store
}

func (*DepositRunner) Run

func (r *DepositRunner) Run(ctx context.Context) error

type DepositType

type DepositType int
const (
	// DepositTypeBank is 銀行
	DepositTypeBank DepositType = iota

	// DepositTypeCampaignPoint is キャンペーンポイント
	DepositTypeCampaignPoint

	// DepositTypeRefund is 返金
	DepositTypeRefund

	// DepositTypeSales is 売上
	DepositTypeSales
)

func RandomDepositType

func RandomDepositType(ctx context.Context) DepositType

func (DepositType) ToIntn

func (t DepositType) ToIntn() int64

type FindUserDepositHistoriesAlloyRunner

type FindUserDepositHistoriesAlloyRunner struct {
	Store *StoreAlloy
}

func (*FindUserDepositHistoriesAlloyRunner) Run

type FindUserDepositHistoriesRunner

type FindUserDepositHistoriesRunner struct {
	BalanceStore *Store
}

func (*FindUserDepositHistoriesRunner) Run

type ReadUserBalancesAlloyRunner

type ReadUserBalancesAlloyRunner struct {
	Store *StoreAlloy
}

func (*ReadUserBalancesAlloyRunner) Run

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(ctx context.Context, sc *spanner.Client) (*Store, error)

func (*Store) CreateUserAccount

func (s *Store) CreateUserAccount(ctx context.Context, userAccount *UserAccount) (resultUserAccount *UserAccount, err error)

func (*Store) Deposit

func (s *Store) Deposit(ctx context.Context, userID string, depositID string, depositType DepositType, amount int64, point int64) (userBalance *UserBalance, userDepositHistories *UserDepositHistory, err error)

func (*Store) DepositDML

func (s *Store) DepositDML(ctx context.Context, userID string, depositID string, depositType DepositType, amount int64, point int64) (userBalance *UserBalance, userDepositHistories *UserDepositHistory, err error)

func (*Store) FindUserDepositHistories

func (s *Store) FindUserDepositHistories(ctx context.Context, userID string) (models []*UserDepositHistory, err error)

FindUserDepositHistories is 指定したuserIDのUserDepositHistoryの最新100件を取得する SQLで最初から取得すれば良いが、GetMultiをやるめたにワンクッション置いている

func (*Store) InsertOrUpdateUserDepositHistorySum

func (s *Store) InsertOrUpdateUserDepositHistorySum(ctx context.Context, tx *spanner.ReadWriteTransaction, value *UserDepositHistorySum) (err error)

InsertOrUpdateUserDepositHistorySum is UserDepositHistorySum TableにInsertOrUpdateする

func (*Store) SelectUserDepositHistory

func (s *Store) SelectUserDepositHistory(ctx context.Context, userID string, limit int) (list []*UserDepositHistory, err error)

func (*Store) UserAccountTable

func (s *Store) UserAccountTable() string

func (*Store) UserBalanceTable

func (s *Store) UserBalanceTable() string

func (*Store) UserDepositHistoryTable

func (s *Store) UserDepositHistoryTable() string

type StoreAlloy

type StoreAlloy struct {
	// contains filtered or unexported fields
}

func NewStoreAlloy

func NewStoreAlloy(pool *pgxpool.Pool, readReplicaPool []*pgxpool.Pool) *StoreAlloy

func (*StoreAlloy) Deposit

func (s *StoreAlloy) Deposit(ctx context.Context, userID string, depositID string, depositType DepositType, amount int64, point int64) (err error)

func (*StoreAlloy) FindUserDepositHistories

func (s *StoreAlloy) FindUserDepositHistories(ctx context.Context, userID string, primary bool) (models []*UserDepositHistory, err error)

FindUserDepositHistories is 指定したuserIDのUserDepositHistoryを100件取得する SQLだと本来普通にSELECTすれば良いだけだが、GetMultiをするためにPKだけ取得した後、INで再度取得している

func (*StoreAlloy) InsertUserBalance

func (s *StoreAlloy) InsertUserBalance(ctx context.Context, model *UserBalance) (err error)

func (*StoreAlloy) ReadUserBalances

func (s *StoreAlloy) ReadUserBalances(ctx context.Context, userIDs []string, primary bool) (models []*UserBalance, err error)

ReadUserBalances is 指定した複数のUserIDのBalanceを取得する defaultではReadReplicaから取得される。primary=trueにするとprimary instanceから取得される

func (*StoreAlloy) UserBalanceTable

func (s *StoreAlloy) UserBalanceTable() string

func (*StoreAlloy) UserDepositHistoryTable

func (s *StoreAlloy) UserDepositHistoryTable() string

type SupplementaryInformation

type SupplementaryInformation struct {
	Name   string      `json:"name"`
	Rating float64     `json:"rating"`
	Open   interface{} `json:"open"`
	Tags   []string    `json:"tags"`
}

type UserAccount

type UserAccount struct {
	UserID    string
	Age       int64
	Height    int64
	Weight    int64
	CreatedAt time.Time
	UpdatedAt time.Time
}

type UserBalance

type UserBalance struct {
	UserID    string
	Amount    int64
	Point     int64
	CreatedAt time.Time
	UpdatedAt time.Time
}

type UserDepositHistory

type UserDepositHistory struct {
	UserID                   string
	DepositID                string
	DepositType              DepositType `spanner:"-"`
	Amount                   int64
	Point                    int64
	SumVersion               string
	SupplementaryInformation *SupplementaryInformation `spanner:"-"`
	CreatedAt                time.Time
}

func (*UserDepositHistory) FromRow

func (v *UserDepositHistory) FromRow(row *spanner.Row) (*UserDepositHistory, error)

func (*UserDepositHistory) ToMutationMap

func (v *UserDepositHistory) ToMutationMap() map[string]interface{}

type UserDepositHistorySum

type UserDepositHistorySum struct {
	UserID    string
	Amount    int64
	Point     int64
	Count     int64
	Note      string
	UpdatedAt time.Time
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL