bank

package
v0.0.0-...-6e596f9 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddUserParams

type AddUserParams struct {
	db.CreateUserParams
	AfterCreate func(user db.User) error
}

type AddUserResult

type AddUserResult struct {
	User db.User `json:"user"`
}

type Bank

type Bank interface {
	db.Querier
	Transfer(ctx context.Context, arg TransferParams) (TransferResult, error)
	AddUser(ctx context.Context, arg AddUserParams) (AddUserResult, error)
}

Bank defines all functions to execute db queries and transactions

type SQLBank

type SQLBank struct {
	*db.Queries
	// contains filtered or unexported fields
}

SQLBank a composition that provides transactions over multiple database queries. Composition allows you to build complex types by combining simpler types, promoting code modularity and flexibility.

func NewBank

func NewBank(connPool *pgxpool.Pool) *SQLBank

func (*SQLBank) AddUser

func (store *SQLBank) AddUser(ctx context.Context, arg AddUserParams) (AddUserResult, error)

func (*SQLBank) Transfer

func (bank *SQLBank) Transfer(ctx context.Context, transfer TransferParams) (TransferResult, error)

Transfer performs a money transfer from one account to the other. It creates the transfer, add account entries, and update accounts' balance within a database transaction.

type TransferParams

type TransferParams struct {
	FromAccountID int64 `json:"from_account_id"`
	ToAccountID   int64 `json:"to_account_id"`
	Amount        int64 `json:"amount"`
}

TransferParams contains the input parameters of the transfer transaction

type TransferResult

type TransferResult struct {
	// Created transfer record
	Transfer db.Transfer `json:"transfer"`
	// From account after its balance is updated
	FromAccount db.Account `json:"from_account"`
	// To account after its balance is updated
	ToAccount db.Account `json:"to_account"`
	// From entry records that money is moving out
	FromEntry db.Entry `json:"from_entry"`
	// To entry records that money is moving in
	ToEntry db.Entry `json:"to_entry"`
}

TransferResult is the result of the transfer transaction

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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