models

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is the database used by the backend.

Functions

func ConnectDatabase added in v0.1.0

func ConnectDatabase() error

ConnectDatabase connects to the database DB.

Types

type Account added in v0.1.0

type Account struct {
	Model
	Name     string          `json:"name,omitempty"`
	BudgetID uint64          `json:"budgetId"`
	Budget   Budget          `json:"-"`
	OnBudget bool            `json:"onBudget"` // Always false when external: true
	External bool            `json:"external"`
	Balance  decimal.Decimal `json:"balance" gorm:"-"`
}

Account represents an asset account, e.g. a bank account.

func (*Account) BeforeSave added in v0.5.0

func (a *Account) BeforeSave(tx *gorm.DB) (err error)

BeforeSave sets OnBudget to false when External is true.

func (Account) Transactions added in v0.1.0

func (a Account) Transactions() []Transaction

Transactions returns all transactions for this account.

func (Account) WithBalance added in v0.1.0

func (a Account) WithBalance() (*Account, error)

WithBalance returns a pointer to the account with the balance calculated.

type Allocation added in v0.1.0

type Allocation struct {
	Model
	Month      uint8           `json:"month" gorm:"uniqueIndex:year_month;check:month_valid,month >= 1 AND month <= 12"`
	Year       uint            `json:"year" gorm:"uniqueIndex:year_month"`
	Amount     decimal.Decimal `json:"amount" gorm:"type:DECIMAL(20,8)"`
	EnvelopeID uint64          `json:"envelopeId,omitempty"`
	Envelope   Envelope        `json:"-"`
}

Allocation represents the allocation of money to an Envelope for a specific month.

type Budget

type Budget struct {
	Model
	Name string `json:"name,omitempty"`
	Note string `json:"note,omitempty"`
}

Budget represents a budget

A budget is the highest level of organization in Envelope Zero, all other resources reference it directly or transitively.

type Category added in v0.1.0

type Category struct {
	Model
	Name     string `json:"name,omitempty"`
	BudgetID uint64 `json:"budgetId"`
	Budget   Budget `json:"-"`
	Note     string `json:"note,omitempty"`
}

Category represents a category of envelopes.

type Envelope added in v0.1.0

type Envelope struct {
	Model
	Name       string   `json:"name,omitempty"`
	CategoryID uint64   `json:"categoryId"`
	Category   Category `json:"-"`
	Note       string   `json:"note,omitempty"`
}

Envelope represents an envelope in your budget.

type Model added in v0.1.0

type Model struct {
	ID        uint64          `json:"id"`
	CreatedAt time.Time       `json:"createdAt"`
	UpdatedAt time.Time       `json:"updatedAt"`
	DeletedAt *gorm.DeletedAt `json:"deletedAt,omitempty" gorm:"index"`
}

Model is the base model for all other models in Envelope Zero.

func (*Model) AfterFind added in v0.5.0

func (m *Model) AfterFind(tx *gorm.DB) (err error)

AfterFind updates the timestamps to use UTC as timezone, not +0000. Yes, this is different.

We already store them in UTC, but somehow reading them from the database returns them as +0000.

type Transaction added in v0.1.0

type Transaction struct {
	Model
	Date                 time.Time       `json:"date,omitempty"`
	Amount               decimal.Decimal `json:"amount" gorm:"type:DECIMAL(20,8)"`
	Note                 string          `json:"note,omitempty"`
	BudgetID             uint64          `json:"budgetId,omitempty"`
	Budget               Budget          `json:"-"`
	SourceAccountID      uint64          `json:"sourceAccountId,omitempty"`
	SourceAccount        Account         `json:"-"`
	DestinationAccountID uint64          `json:"destinationAccountId,omitempty"`
	DestinationAccount   Account         `json:"-"`
	EnvelopeID           uint64          `json:"envelopeId,omitempty"`
	Envelope             Envelope        `json:"-"`
	Reconciled           bool            `json:"reconciled"`
}

Transaction represents a transaction between two accounts.

func (*Transaction) AfterFind added in v0.5.0

func (t *Transaction) AfterFind(tx *gorm.DB) (err error)

AfterFind updates the timestamps to use UTC as timezone, not +0000. Yes, this is different.

We already store them in UTC, but somehow reading them from the database returns them as +0000.

func (*Transaction) BeforeSave added in v0.5.0

func (t *Transaction) BeforeSave(tx *gorm.DB) (err error)

BeforeSave sets the timezone for the Date for UTC.

Jump to

Keyboard shortcuts

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