models

package
v0.0.0-...-c770a38 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteTransaction

func DeleteTransaction(database *mongo.Database, id primitive.ObjectID) error

Delete a Transaction by _id

func SetAccountValue

func SetAccountValue(
	database *mongo.Database,
	account *Account,
	value float64,
	vTime primitive.DateTime,
) error

Set Account value and current value

func UpdateTransaction

func UpdateTransaction(
	database *mongo.Database,
	transaction *Transaction,
	name string,
	date primitive.DateTime,
	amount float64,
	category TransactionCategory,
) error

Update transaction (replace)

func UpdateTransactionCategoryActive

func UpdateTransactionCategoryActive(database *mongo.Database, id primitive.ObjectID, active bool) error

Update the active status of a TransactionCategory

Types

type Account

type Account struct {
	Name           string              `bson:"name" json:"name"`
	Type           AccountType         `bson:"type" json:"type"`
	ID             primitive.ObjectID  `bson:"_id,omitempty" json:"_id"`
	Active         bool                `bson:"active" json:"active"`
	IncludeNetWork bool                `bson:"include_net_worth" json:"include_net_worth"`
	StartDate      primitive.DateTime  `bson:"start_date" json:"start_date"`
	EndDate        *primitive.DateTime `bson:"end_date" json:"end_date"`
	CurrentValue   *AccountValue       `bson:"current_value,omitempty" json:"current_value"`
	Values         []*AccountValue     `bson:"values" json:"values"`
}

func CreateAccount

func CreateAccount(
	database *mongo.Database,
	name string,
	acctType AccountType,
	includeNetWorth bool,
	startDate primitive.DateTime,
) (Account, error)

This function will create a new Account

func GetAccount

func GetAccount(database *mongo.Database, id primitive.ObjectID) (Account, error)

Get a single account

func GetAccountList

func GetAccountList(database *mongo.Database, activeDate *time.Time) ([]Account, error)

Listing

type AccountType

type AccountType string

These are the valid Account types

const (
	TYPE_ACCOUNT_DEBIT      AccountType = "debit"
	TYPE_ACCOUNT_CREDIT     AccountType = "credit"
	TYPE_ACCOUNT_INVESTMENT AccountType = "investment"
)

type AccountValue

type AccountValue struct {
	Value float64            `bson:"value" json:"value"`
	Date  primitive.DateTime `bson:"date" json:"date"`
}

The following structs represent an Account and the nested Account Value

type CategoryType

type CategoryType string

These are the valid Category types

const (
	TYPE_DEBIT    CategoryType = "debit"
	TYPE_CREDIT   CategoryType = "credit"
	TYPE_TRANSFER CategoryType = "transfer"
)

type Transaction

type Transaction struct {
	Name     string              `bson:"name" json:"name"`
	Category TransactionCategory `bson:"category" json:"category"`
	Date     primitive.DateTime  `bson:"date" json:"date"`
	ID       primitive.ObjectID  `bson:"_id,omitempty" json:"_id"`
	Amount   float64             `bson:"amount" json:"amount"`
}

This is the transaction struct which represents the transaction type in the database

func CreateTransaction

func CreateTransaction(
	database *mongo.Database,
	name string,
	date primitive.DateTime,
	amount float64,
	category TransactionCategory,
) (Transaction, error)

Create a Transaction

func GetTransaction

func GetTransaction(database *mongo.Database, id primitive.ObjectID) (Transaction, error)

Retrieve a single Transaction by _id

func GetTransactionList

func GetTransactionList(database *mongo.Database, filter *TransactionFilter) []Transaction

type TransactionCategory

type TransactionCategory struct {
	Name   string             `bson:"name" json:"name"`
	Type   CategoryType       `bson:"type" json:"type"`
	ID     primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
	Active bool               `bson:"active" json:"active"`
}

This is the struct which represents a category

func CreateTransactionCategory

func CreateTransactionCategory(database *mongo.Database, name string, catType CategoryType) (TransactionCategory, error)

Function to create a TransactionCategory from a string name and type

func GetActiveTransactionCategories

func GetActiveTransactionCategories(database *mongo.Database) []TransactionCategory

func GetAllTransactionCategories

func GetAllTransactionCategories(database *mongo.Database) []TransactionCategory

func GetInactiveTransactionCategories

func GetInactiveTransactionCategories(database *mongo.Database) []TransactionCategory

func GetTransactionCategory

func GetTransactionCategory(database *mongo.Database, id primitive.ObjectID) (TransactionCategory, error)

Function to retrieve a single TransactionCategory by ObjectID

func GetTransactionCategoryList

func GetTransactionCategoryList(database *mongo.Database, filter bson.M) []TransactionCategory

Functions to retrieve lists of TransactionCategory objects from the database

type TransactionFilter

type TransactionFilter struct {
	StartDate time.Time
	EndDate   time.Time
}

Jump to

Keyboard shortcuts

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