balance

package
v0.0.0-...-6375eca Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficientFunds = errors.Forbidden("insufficient funds")
)

Functions

func RegisterProviders

func RegisterProviders(container *dig.Container) error

Types

type Balance

type Balance struct {
	ID             uint
	UserID         uint
	Amount         float64
	AmountInFlight float64
}

func NewBalance

func NewBalance(input NewBalanceInput) *Balance

func (*Balance) Confirm

func (b *Balance) Confirm(amount float64) error

func (*Balance) Release

func (b *Balance) Release(amount float64) error

func (*Balance) Reserve

func (b *Balance) Reserve(amount float64) error

func (*Balance) Rollback

func (b *Balance) Rollback(amount float64) error

type BalanceGetResponse

type BalanceGetResponse struct {
	Amount         float64 `json:"amount"`
	AmountInFlight float64 `json:"amountInFlight"`
}

type BalanceTransactionRequest

type BalanceTransactionRequest struct {
	UserID uint    `json:"userId"`
	Amount float64 `json:"amount"`
}

type CreateBalanceRequest

type CreateBalanceRequest struct {
	UserID uint    `json:"userId"`
	Amount float64 `json:"amount"`
}

type NewBalanceInput

type NewBalanceInput struct {
	UserID uint
	Amount float64
}

type Repository

type Repository interface {
	GetWithUserID(userID uint) (*Balance, error)
	PerformTransaction(userID uint, transaction func(balance *Balance) error) (*Balance, error)
	Delete(balance *Balance) error
}

type Service

type Service interface {
	FindByUserID(userID uint) (*BalanceGetResponse, error)
	Reserve(request BalanceTransactionRequest) (*BalanceGetResponse, error)
	Release(request BalanceTransactionRequest) (*BalanceGetResponse, error)
	Commit(request BalanceTransactionRequest) (*BalanceGetResponse, error)
	Rollback(request BalanceTransactionRequest) (*BalanceGetResponse, error)
}

func NewService

func NewService(params ServiceParams) Service

type ServiceParams

type ServiceParams struct {
	dig.In
	Repository Repository
}

Jump to

Keyboard shortcuts

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