Documentation ¶
Index ¶
- type AccountService
- func (a *AccountService) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error)
- func (a *AccountService) CreateAsset(amount, price float32, time time.Time) (*domain.Asset, error)
- func (a *AccountService) Deposit(amount float32) error
- func (a *AccountService) FindAllAssets() (*[]domain.Asset, error)
- func (a *AccountService) FindPendingAssets() (*[]domain.Asset, error)
- func (a *AccountService) GetAmount() (float32, error)
- func (a *AccountService) GetBalance(startDate, endDate time.Time) (float32, error)
- func (a *AccountService) SellAsset(assetID string, price float32, time time.Time) error
- func (a *AccountService) Withdraw(amount float32) error
- type AccountServiceInMemory
- func (a *AccountServiceInMemory) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error)
- func (a *AccountServiceInMemory) CreateAsset(amount, price float32, time time.Time) (*domain.Asset, error)
- func (a *AccountServiceInMemory) Deposit(amount float32) error
- func (a *AccountServiceInMemory) FindAllAssets() (*[]domain.Asset, error)
- func (a *AccountServiceInMemory) FindPendingAssets() (*[]domain.Asset, error)
- func (a *AccountServiceInMemory) GetAmount() (float32, error)
- func (a *AccountServiceInMemory) GetBalance(startDate, endDate time.Time) (float32, error)
- func (a *AccountServiceInMemory) SellAsset(assetID string, price float32, time time.Time) error
- func (a *AccountServiceInMemory) Withdraw(amount float32) error
- type Repository
- func (r *Repository) Create(broker string, amount float32) (*domain.Account, error)
- func (r *Repository) Deposit(id string, amount float32) error
- func (r *Repository) FindByBroker(broker string) (*domain.Account, error)
- func (r *Repository) FindById(id string) (*domain.Account, error)
- func (r *Repository) Withdraw(id string, amount float32) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountService ¶
type AccountService struct { ID string // contains filtered or unexported fields }
AccountService interacts with accounts and assets repositories
func NewAccountService ¶
func NewAccountService(ID string, repository *Repository, assetsRepository domain.AssetsRepository) (*AccountService, error)
NewAccountService returns an instance of account service
func (*AccountService) CheckAssetWithCloserPriceExists ¶
func (a *AccountService) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error)
CheckAssetWithCloserPriceExists verifies whether account already has asset with a price close to the one passed by argument
func (*AccountService) CreateAsset ¶
CreateAsset creates an asset hold by the account
func (*AccountService) Deposit ¶
func (a *AccountService) Deposit(amount float32) error
Deposit increments an amount to an account
func (*AccountService) FindAllAssets ¶
func (a *AccountService) FindAllAssets() (*[]domain.Asset, error)
FindAllAssets returns all assets hold by the account
func (*AccountService) FindPendingAssets ¶
func (a *AccountService) FindPendingAssets() (*[]domain.Asset, error)
FindPendingAssets returns account assets awaiting to be sold
func (*AccountService) GetAmount ¶
func (a *AccountService) GetAmount() (float32, error)
GetAmount returns the amount hold by the account
func (*AccountService) GetBalance ¶
func (a *AccountService) GetBalance(startDate, endDate time.Time) (float32, error)
GetBalance returns the balance between two dates
func (*AccountService) Withdraw ¶
func (a *AccountService) Withdraw(amount float32) error
Withdraw decrements an amount from an account
type AccountServiceInMemory ¶
type AccountServiceInMemory struct { Amount float32 ID string // contains filtered or unexported fields }
AccountServiceInMemory emulates an account service by saving data in memory
func NewAccountServiceInMemory ¶
func NewAccountServiceInMemory(initialAmount float32, assetsRepository domain.AssetsRepository) *AccountServiceInMemory
NewAccountServiceInMemory returns an instance of AccountServiceInMemory
func (*AccountServiceInMemory) CheckAssetWithCloserPriceExists ¶
func (a *AccountServiceInMemory) CheckAssetWithCloserPriceExists(price, limit float32) (bool, error)
func (*AccountServiceInMemory) CreateAsset ¶
func (*AccountServiceInMemory) Deposit ¶
func (a *AccountServiceInMemory) Deposit(amount float32) error
Deposit increases account amount
func (*AccountServiceInMemory) FindAllAssets ¶
func (a *AccountServiceInMemory) FindAllAssets() (*[]domain.Asset, error)
func (*AccountServiceInMemory) FindPendingAssets ¶
func (a *AccountServiceInMemory) FindPendingAssets() (*[]domain.Asset, error)
func (*AccountServiceInMemory) GetAmount ¶
func (a *AccountServiceInMemory) GetAmount() (float32, error)
GetAmount returns amount value
func (*AccountServiceInMemory) GetBalance ¶
func (a *AccountServiceInMemory) GetBalance(startDate, endDate time.Time) (float32, error)
func (*AccountServiceInMemory) Withdraw ¶
func (a *AccountServiceInMemory) Withdraw(amount float32) error
Withdraw decreases account amount
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository stores and gets accounts from database
func NewRepository ¶
func NewRepository(repo domain.Repository) *Repository
NewRepository returns an instance of accounts repository
func (*Repository) Deposit ¶
func (r *Repository) Deposit(id string, amount float32) error
Deposit increments an amount to the account
func (*Repository) FindByBroker ¶
func (r *Repository) FindByBroker(broker string) (*domain.Account, error)
FindByBroker returns an account with the broker passed by argument