service

package
v0.0.0-...-d05f80c Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package service contains the business logic for wallets application.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatabase                 = httperr.New(http.StatusInternalServerError, "database error")
	ErrEmptyWalletFrom          = httperr.New(http.StatusBadRequest, "empty wallet_from")
	ErrEmptyWalletName          = httperr.New(http.StatusBadRequest, "empty wallet name")
	ErrEmptyWalletTo            = httperr.New(http.StatusBadRequest, "empty wallet_to")
	ErrSameWallets              = httperr.New(http.StatusBadRequest, "same wallets")
	ErrNegativeEndDate          = httperr.New(http.StatusBadRequest, "end_date can't be negative")
	ErrNegativeOffset           = httperr.New(http.StatusBadRequest, "offset can't be negative")
	ErrNegativeStartDate        = httperr.New(http.StatusBadRequest, "start_date can't be negative")
	ErrNotPositiveAmount        = httperr.New(http.StatusBadRequest, "amount must be positive")
	ErrNotPositiveLimit         = httperr.New(http.StatusBadRequest, "limit must be positive")
	ErrUnsupportedOperationType = httperr.New(http.StatusBadRequest, "unsupported operation type")
	ErrWalletNotFound           = httperr.New(http.StatusBadRequest, "wallet not found")
)

Functions

This section is empty.

Types

type Repository

type Repository interface {
	CreateWallet(walletName string) error
	GetWallet(walletName string) (*dto.Wallet, error)
	IncreaseWalletBalance(walletName string, amount uint64) error
	GetOperations(dto.OperationsFilter) ([]dto.Operation, error)

	RunWithTransaction(func(tx *sqlx.Tx) error) error
	GetWalletsForUpdateTx(tx *sqlx.Tx, walletNames []string) ([]dto.Wallet, error)
	TransferTx(tx *sqlx.Tx, walletFrom, walletTo string, amount uint64) error
}

Repository describes the repository methods required for the service.

type Service

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

Service implements the business logic for wallets application.

func NewService

func NewService(logger *zap.SugaredLogger, repo Repository) *Service

NewService creates a service instance.

func (*Service) CreateWallet

func (s *Service) CreateWallet(wallet dto.CreateWalletRequest) error

CreateWallet creates new wallet.

func (*Service) GetOperations

func (s *Service) GetOperations(filter dto.OperationsFilter) ([]dto.Operation, error)

GetOperations provides operations for the specified wallet according to filtering parameters.

func (*Service) IncreaseWalletBalance

func (s *Service) IncreaseWalletBalance(deposit dto.Deposit) error

IncreaseWalletBalance increases wallet balance.

func (*Service) Transfer

func (s *Service) Transfer(transfer dto.Transfer) error

Transfer transfers money from one wallet to another.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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