models

package
v0.0.0-...-c869e04 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CategorySortOrder = map[string]int{
	"Charity":        0,
	"Saving":         1,
	"Housing":        2,
	"Utilities":      3,
	"Food":           4,
	"Clothing":       5,
	"Transportation": 6,
	"Medical/Health": 7,
	"Insurance":      8,
	"Personal":       9,
	"Recreation":     10,
	"Debts":          11,
}

DB is a connection to your database to be used throughout your application.

Functions

func S3Upload

func S3Upload(path string, file *bytes.Buffer) error

Types

type AnnualBudget

type AnnualBudget struct {
	ID                int                `json:"id" db:"id"`
	UserID            int                `json:"userId" db:"user_id"`
	Year              int                `json:"year" db:"year"`
	CreatedAt         time.Time          `json:"-" db:"created_at"`
	UpdatedAt         time.Time          `json:"-" db:"updated_at"`
	AnnualBudgetItems []AnnualBudgetItem `json:"annualBudgetItems" db:"-"`
}

func (*AnnualBudget) FindOrCreate

func (ab *AnnualBudget) FindOrCreate()

type AnnualBudgetItem

type AnnualBudgetItem struct {
	ID             int         `json:"id" db:"id"`
	AnnualBudgetID int         `json:"annualBudgetId" db:"annual_budget_id"`
	Name           string      `json:"name" db:"name"`
	Amount         json.Number `json:"amount" db:"amount"`
	DueDate        string      `json:"dueDate" db:"due_date"`
	Interval       int         `json:"interval" db:"payment_intervals"`
	Paid           bool        `json:"paid" db:"paid"`
	CreatedAt      time.Time   `json:"-" db:"created_at"`
	UpdatedAt      time.Time   `json:"-" db:"updated_at"`
}

func (*AnnualBudgetItem) MarshalJSON

func (a *AnnualBudgetItem) MarshalJSON() ([]byte, error)

func (*AnnualBudgetItem) Update

func (item *AnnualBudgetItem) Update(params *AnnualBudgetItem) error

type AnnualBudgetItems

type AnnualBudgetItems []AnnualBudgetItem

type AnnualBudgets

type AnnualBudgets []AnnualBudget

type AssetLiability

type AssetLiability struct {
	ID        int       `json:"id" db:"id"`
	UserID    int       `json:"userId" db:"user_id"`
	Name      string    `json:"name" db:"name"`
	IsAsset   bool      `json:"isAsset" db:"is_asset"`
	CreatedAt time.Time `json:"-" db:"created_at"`
	UpdatedAt time.Time `json:"-" db:"updated_at"`
}

AssetLiability is a db model

func (*AssetLiability) DestroyAllNetWorthItems

func (al *AssetLiability) DestroyAllNetWorthItems(tx *pop.Connection, logger buffalo.Logger) error

DestroyAllNetWorthItems deletes all child records

func (AssetLiability) TableName

func (al AssetLiability) TableName() string

TableName overrides the table name used by Pop.

type AssetsLiabilities

type AssetsLiabilities []AssetLiability

AssetsLiabilities is a slice of AssetLiability

func (*AssetsLiabilities) Partition

Partition Takes a slice of assets and liabilities and partition them based on type

func (AssetsLiabilities) TableName

func (als AssetsLiabilities) TableName() string

TableName overrides the table name used by Pop.

type Budget

type Budget struct {
	ID               int              `json:"id" db:"id"`
	UserID           int              `json:"-" db:"user_id"`
	Month            int              `json:"month" db:"month"`
	Year             int              `json:"year" db:"year"`
	Income           json.Number      `json:"income" db:"monthly_income"`
	CreatedAt        time.Time        `json:"-" db:"created_at"`
	UpdatedAt        time.Time        `json:"-" db:"updated_at"`
	BudgetCategories []BudgetCategory `json:"" db:"-"`
}

func (*Budget) CreateDefaultCategories

func (b *Budget) CreateDefaultCategories() error

func (*Budget) FindOrCreate

func (b *Budget) FindOrCreate() error

func (*Budget) MonthlyView

type BudgetCategories

type BudgetCategories []BudgetCategory

func (BudgetCategories) Len

func (s BudgetCategories) Len() int

func (BudgetCategories) Less

func (s BudgetCategories) Less(i, j int) bool

func (BudgetCategories) Swap

func (s BudgetCategories) Swap(i, j int)

type BudgetCategory

type BudgetCategory struct {
	ID          int          `json:"id" db:"id"`
	BudgetId    int          `json:"budgetId" db:"budget_id"`
	Name        string       `json:"name" db:"name"`
	Percentage  string       `json:"percentage" db:"percentage"`
	CreatedAt   time.Time    `json:"-" db:"created_at"`
	UpdatedAt   time.Time    `json:"-" db:"updated_at"`
	BudgetItems []BudgetItem `json:"" db:"-"`
}

func (*BudgetCategory) ImportPreviousItems

func (budgetCategory *BudgetCategory) ImportPreviousItems() (string, BudgetItems)

type BudgetItem

type BudgetItem struct {
	ID                 int                 `json:"id" db:"id"`
	BudgetCategoryId   int                 `json:"budgetCategoryId" db:"budget_category_id"`
	Name               string              `json:"name" db:"name"`
	Amount             json.Number         `json:"amount" db:"amount_budgeted"`
	CreatedAt          time.Time           `json:"-" db:"created_at"`
	UpdatedAt          time.Time           `json:"-" db:"updated_at"`
	BudgetItemExpenses []BudgetItemExpense `json:"" db:"-"`
}

func (*BudgetItem) DestroyAllExpenses

func (budgetItem *BudgetItem) DestroyAllExpenses(tx *pop.Connection, logger buffalo.Logger) error

func (*BudgetItem) DestroyAllExpensesSilently

func (budgetItem *BudgetItem) DestroyAllExpensesSilently(tx *pop.Connection) error

func (*BudgetItem) Update

func (budgetItem *BudgetItem) Update(params *BudgetItem) error

type BudgetItemExpense

type BudgetItemExpense struct {
	ID           int         `json:"id" db:"id"`
	BudgetItemId int         `json:"budgetItemId" db:"budget_item_id"`
	Name         string      `json:"name" db:"name"`
	Amount       json.Number `json:"amount" db:"amount"`
	Date         time.Time   `json:"date" db:"date"`
	CreatedAt    time.Time   `json:"-" db:"created_at"`
	UpdatedAt    time.Time   `json:"-" db:"updated_at"`
}

func (*BudgetItemExpense) MarshalJSON

func (e *BudgetItemExpense) MarshalJSON() ([]byte, error)

func (*BudgetItemExpense) UnmarshalJSON

func (e *BudgetItemExpense) UnmarshalJSON(data []byte) error

func (*BudgetItemExpense) Update

func (e *BudgetItemExpense) Update(params *BudgetItemExpense) error

type BudgetItemExpenses

type BudgetItemExpenses []BudgetItemExpense

type BudgetItems

type BudgetItems []BudgetItem

type Budgets

type Budgets []Budget

type MonthlyStatistic

type MonthlyStatistic struct {
	ID           string `json:"id" db:"id"`
	UserID       int    `json:"-" db:"user_id"`
	Month        int    `json:"month" db:"month"`
	Year         int    `json:"year" db:"year"`
	Name         string `json:"name" db:"name"`
	AmountSpent  string `json:"amountSpent" db:"amount_spent"`
	TotalSpent   string `json:"totalSpent" db:"total_spent"`
	PercentSpent string `json:"percentSpent" db:"percent_spent"`
}

MonthlyStatistic is a db model

func FindMonthlyStatistics

func FindMonthlyStatistics(month, year, userID int) ([]MonthlyStatistic, error)

FindMonthlyStatistics loads stats for a calendar month

type NetWorth

type NetWorth struct {
	ID            int           `json:"id" db:"id"`
	UserID        int           `json:"userId" db:"user_id"`
	Year          int           `json:"year" db:"year"`
	Month         int           `json:"month" db:"month"`
	Items         NetWorthItems `json:"items" fk_id:"net_worth_id" has_many:"net_worth_items"`
	NetWorthItems NetWorthItems `json:"-" db:"-"`
	CreatedAt     time.Time     `json:"-" db:"created_at"`
	UpdatedAt     time.Time     `json:"-" db:"updated_at"`
}

NetWorth db model

func (*NetWorth) ImportPreviousItems

func (nw *NetWorth) ImportPreviousItems() (string, NetWorthItems)

func (*NetWorth) LoadItems

func (nw *NetWorth) LoadItems()

LoadItems loads all net worth items for a single month

type NetWorthItem

type NetWorthItem struct {
	ID               int            `json:"id" db:"id"`
	NetWorthID       int            `json:"netWorthId" db:"net_worth_id"`
	AssetLiabilityID int            `json:"assetId" db:"asset_liability_id"`
	Asset            AssetLiability `json:"-" db:"-"`
	Amount           json.Number    `json:"amount" db:"amount"`
	CreatedAt        time.Time      `json:"-" db:"created_at"`
	UpdatedAt        time.Time      `json:"-" db:"updated_at"`
}

NetWorthItem is a db model

type NetWorthItemGraph

type NetWorthItemGraph struct {
	ID               int         `json:"id" db:"id"`
	NetWorthID       int         `json:"netWorthId" db:"net_worth_id"`
	AssetLiabilityID int         `json:"assetLiabilityId" db:"asset_liability_id"`
	Amount           json.Number `json:"amount" db:"amount"`
	CreatedAt        time.Time   `json:"-" db:"created_at"`
	UpdatedAt        time.Time   `json:"-" db:"updated_at"`
}

func FindNetWorthItemsByYear

func FindNetWorthItemsByYear(year, userID int) []NetWorthItemGraph

FindNetWorthItemsByYear returns formatted data structure for API

type NetWorthItems

type NetWorthItems []NetWorthItem

NetWorthItems is a slice of NetWorthItem

type NetWorths

type NetWorths []NetWorth

NetWorths db model

func (*NetWorths) FindOrCreateYearTemplates

func (nw *NetWorths) FindOrCreateYearTemplates(userID, year int)

FindOrCreateYearTemplates finds or creates 12 months of net worths

func (*NetWorths) LoadItems

func (nw *NetWorths) LoadItems()

LoadItems loads all net worth items in one trip to the database, avoiding n+1 issues

type PushNotification

type PushNotification struct {
	To    string `json:"to"`
	Title string `json:"title"`
	Body  string `json:"body"`
	Sound string `json:"sound"`
}

type Session

type Session struct {
	AuthenticationKey     uuid.UUID    `json:"authenticationKey" db:"authentication_key"`
	AuthenticationToken   string       `json:"authenticationToken" db:"authentication_token"`
	IpAddress             string       `json:"ipAddress" db:"ip"`
	UserID                int          `json:"userId" db:"user_id"`
	UserAgent             string       `json:"userAgent" db:"user_agent"`
	DeviceName            nulls.String `json:"deviceName" db:"device_name"`
	PushNotificationToken nulls.String `json:"-" db:"push_notification_token"`
	ExpiredAt             nulls.Time   `json:"expiredAt" db:"expired_at"`
	CreatedAt             time.Time    `json:"createdAt" db:"created_at"`
	UpdatedAt             time.Time    `json:"updatedAt" db:"updated_at"`
}

func (*Session) Create

func (s *Session) Create() (string, error)

func (*Session) Delete

func (s *Session) Delete() string

func (*Session) ID

func (s *Session) ID() uuid.UUID

func (*Session) PrimaryKeyType

func (s *Session) PrimaryKeyType() string

func (Session) String

func (s Session) String() string

String is not required by pop and may be deleted

func (*Session) UpdatePushNotificationToken

func (s *Session) UpdatePushNotificationToken(token nulls.String)

UpdatePushNotificationToken updates the PN token if it is valid

type Sessions

type Sessions []Session

Sessions is not required by pop and may be deleted

type User

type User struct {
	ID                  int          `json:"-" db:"id"`
	Email               string       `json:"email" db:"email"`
	FirstName           nulls.String `json:"firstName" db:"first_name"`
	LastName            nulls.String `json:"lastName" db:"last_name"`
	Admin               bool         `json:"admin" db:"admin"`
	PasswordResetToken  nulls.String `json:"-" db:"password_reset_token"`
	PasswordResetSentAt nulls.Time   `json:"-" db:"password_reset_sent_at"`
	AvatarFileName      nulls.String `json:"-" db:"avatar_file_name"`
	AvatarContentType   nulls.String `json:"-" db:"avatar_content_type"`
	AvatarFileSize      nulls.Int64  `json:"-" db:"avatar_file_size"`
	AvatarUpdatedAt     nulls.Time   `json:"-" db:"avatar_updated_at"`
	EncryptedPassword   string       `json:"-" db:"encrypted_password"`
	CreatedAt           time.Time    `json:"-" db:"created_at"`
	UpdatedAt           time.Time    `json:"-" db:"updated_at"`
	CurrentSession      *Session     `json:"-" db:"-"`
}

func FindUserForPasswordReset

func FindUserForPasswordReset(token string) (*User, error)

func NewUser

func NewUser(email, password string) User

func (*User) AvatarUrl

func (u *User) AvatarUrl() string

func (*User) EncryptPassword

func (u *User) EncryptPassword(password []byte)

func (*User) MarshalJSON

func (u *User) MarshalJSON() ([]byte, error)

func (*User) NullableFirstName

func (u *User) NullableFirstName() *string

NullableFirstName returns JSON nulls if empty

func (*User) NullableLastName

func (u *User) NullableLastName() *string

NullableLastName returns JSON nulls if empty

func (*User) SaveAvatar

func (u *User) SaveAvatar(file multipart.File) error

func (*User) SendPushNotification

func (u *User) SendPushNotification(title, body string) error

func (User) String

func (u User) String() string

String is not required by pop and may be deleted

func (*User) Validate

func (u *User) Validate(tx *pop.Connection) (*validate.Errors, error)

Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. This method is not required and may be deleted.

func (*User) ValidateCreate

func (u *User) ValidateCreate(tx *pop.Connection) (*validate.Errors, error)

ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. This method is not required and may be deleted.

func (*User) ValidateUpdate

func (u *User) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error)

ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. This method is not required and may be deleted.

func (*User) VerifyPassword

func (u *User) VerifyPassword(password string) bool

type Users

type Users []User

Users is not required by pop and may be deleted

func (Users) String

func (u Users) String() string

String is not required by pop and may be deleted

Jump to

Keyboard shortcuts

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