Documentation ¶
Index ¶
- Constants
- type Account
- type AccountCollection
- type AccountStore
- type Amount
- type AmountCollection
- type Currency
- type CurrencyAmounts
- type Service
- func (s *Service) CreateAccount(ctx context.Context, u *users.User, name string) (*Account, error)
- func (s *Service) DeleteAccount(ctx context.Context, acc *Account) error
- func (s *Service) GetAccount(ctx context.Context, UUID uuid.UUID) (*Account, error)
- func (s *Service) GetAccountAmounts(ctx context.Context, acc *Account, month string) (CurrencyAmounts, error)
- func (s *Service) GetAccountCurrentAmounts(ctx context.Context, acc *Account) (CurrencyAmounts, error)
- func (s *Service) GetUserAccounts(ctx context.Context, u *users.User) (AccountCollection, error)
- func (s *Service) SetAccountAmount(ctx context.Context, acc *Account, month string, currency Currency, ...) error
- func (s *Service) SetAccountCurrentAmount(ctx context.Context, acc *Account, currency Currency, amount float64) error
- func (s *Service) UpdateAccount(ctx context.Context, acc *Account) error
Constants ¶
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.
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 CurrencyAmounts ¶ added in v0.2.0
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
func (a CurrencyAmounts) Diff(from CurrencyAmounts) CurrencyAmounts
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.