accounts

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const FmtYearMonth = "2006-01"

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	datastore.Model
	User *users.User `gorm:"embedded;embeddedPrefix:user_"`
	Name string      `gorm:"notNull"`
}

Account represents an account entity.

func NewAccount

func NewAccount(u *users.User, name string) *Account

NewAccount initializes a new account.

type AccountCollection

type AccountCollection []*Account

AccountCollection represents a collection of account entities.

type AccountStore

type AccountStore interface {
	// CreateAccount saves account entity into the DB.
	CreateAccount(ctx context.Context, acc *Account) error
	// UpdateAccount updates existing account entity.
	UpdateAccount(ctx context.Context, acc *Account) error
	// DeleteAccount deletes account entity from the DB.
	DeleteAccount(ctx context.Context, acc *Account) error
	// GetAccount retrieves accounts by its UUID.
	GetAccount(ctx context.Context, UUID uuid.UUID) (*Account, error)
	// GetUserAccounts retrieves all user accounts.
	GetUserAccounts(ctx context.Context, u *users.User) (AccountCollection, error)
	// SetAccountAmount sets the amount of funds on the account.
	SetAccountAmount(ctx context.Context, acc *Account, month string, currency Currency, amount float64) error
	// GetAccountAmounts retrieves amount of funds for each currency on the account for the specified month.
	GetAccountAmounts(ctx context.Context, acc *Account, month string) (AmountCollection, error)
}

AccountStore is an interface for accounts DB API.

func NewGormStore

func NewGormStore(db *gorm.DB) AccountStore

NewGormStore initializes GORM implementation of AccountStore.

type Amount

type Amount struct {
	AccountUUID  uuid.UUID `gorm:"primaryKey"`
	Account      *Account  `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	YearMonth    string    `gorm:"primaryKey;type:varchar(7);notNull"`
	CurrencyCode Currency  `gorm:"primaryKey;notNull"`
	Amount       float64
}

Amount represents account's amount entity.

type AmountCollection

type AmountCollection []*Amount

AmountCollection represents a collection of account's amounts.

func (AmountCollection) GetCurrencyAmounts added in v0.2.0

func (a AmountCollection) GetCurrencyAmounts() CurrencyAmounts

GetCurrencyAmounts extracts amounts for each currency in the collection.

type Currency added in v0.4.0

type Currency string

type CurrencyAmounts added in v0.2.0

type CurrencyAmounts map[Currency]float64

CurrencyAmounts contains amount per currency.

func NewCurrencyAmounts added in v0.2.0

func NewCurrencyAmounts() CurrencyAmounts

NewCurrencyAmounts creates new currency amounts instance.

func (CurrencyAmounts) Add added in v0.5.0

func (a CurrencyAmounts) Add(from CurrencyAmounts)

Add adds provided amounts to current one.

func (CurrencyAmounts) Diff added in v0.2.0

Diff gets the difference from provided amounts.

type Service

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

Service is a service responsible for managing accounts.

func NewService

func NewService(db AccountStore) *Service

NewService initializes a new accounts service.

func (*Service) CreateAccount

func (s *Service) CreateAccount(ctx context.Context, u *users.User, name string) (*Account, error)

func (*Service) DeleteAccount

func (s *Service) DeleteAccount(ctx context.Context, acc *Account) error

func (*Service) GetAccount

func (s *Service) GetAccount(ctx context.Context, UUID uuid.UUID) (*Account, error)

func (*Service) GetAccountAmounts

func (s *Service) GetAccountAmounts(ctx context.Context, acc *Account, month string) (CurrencyAmounts, error)

func (*Service) GetAccountCurrentAmounts

func (s *Service) GetAccountCurrentAmounts(ctx context.Context, acc *Account) (CurrencyAmounts, error)

func (*Service) GetUserAccounts

func (s *Service) GetUserAccounts(ctx context.Context, u *users.User) (AccountCollection, error)

func (*Service) SetAccountAmount added in v0.3.0

func (s *Service) SetAccountAmount(ctx context.Context, acc *Account, month string, currency Currency, amount float64) error

func (*Service) SetAccountCurrentAmount

func (s *Service) SetAccountCurrentAmount(ctx context.Context, acc *Account, currency Currency, amount float64) error

func (*Service) UpdateAccount

func (s *Service) UpdateAccount(ctx context.Context, acc *Account) error

Jump to

Keyboard shortcuts

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