account

package
v0.0.0-...-514f96b Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExist = errors.New("account with given fields already exist")
	ErrNotFound     = errors.New("account not found")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountID int64
	Balance   int64
}

type AddBalanceDTO

type AddBalanceDTO struct {
	AccountID int64
	Amount    int64
}

type Repository

type Repository interface {
	GetAccountByID(ctx context.Context, accountID int64) (Account, error)
	AddBalance(ctx context.Context, dto AddBalanceDTO) (int64, error)
	TransferBalance(ctx context.Context, dto TransferBalanceDTO) (int64, int64, error)
}

type ReserveBalanceDTO

type ReserveBalanceDTO struct {
	AccountID int64
	Amount    int64
}

type ReturnBalanceDTO

type ReturnBalanceDTO struct {
	AccountID int64
	Amount    int64
}

type Service

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

func NewService

func NewService(
	transactor Transactor,
	repository Repository,
	transactionRepository TransactionRepository,
	logger *zap.Logger,
) *Service

func (*Service) AddBalance

func (s *Service) AddBalance(ctx context.Context, dto AddBalanceDTO) (balance int64, err error)

func (*Service) GetBalanceByID

func (s *Service) GetBalanceByID(ctx context.Context, accountID int64) (int64, error)

func (*Service) TransferBalance

func (s *Service) TransferBalance(
	ctx context.Context,
	dto TransferBalanceDTO,
) (senderBalance int64, receiverBalance int64, err error)

type TransactionRepository

type TransactionRepository interface {
	CreateTransaction(ctx context.Context, dto transaction.CreateDTO) error
}

type Transactor

type Transactor interface {
	WithTx(ctx context.Context, txFunc func(ctx context.Context) error) error
}

type TransferBalanceDTO

type TransferBalanceDTO struct {
	SenderID   int64
	ReceiverID int64
	Amount     int64
}

Jump to

Keyboard shortcuts

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