db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package db contains common entities (errors, models and etc). All DB implementations have to use them

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrYearNotExist           = errors.New("there're no records for passed year")
	ErrMonthNotExist          = errors.New("such Month doesn't exist")
	ErrDayNotExist            = errors.New("such Day doesn't exist")
	ErrIncomeNotExist         = errors.New("such Income doesn't exist")
	ErrMonthlyPaymentNotExist = errors.New("such Monthly Payment doesn't exist")
	ErrSpendNotExist          = errors.New("such Spend doesn't exist")
	ErrSpendTypeNotExist      = errors.New("such Spend Type doesn't exist")
)

Common errors

Functions

This section is empty.

Types

type AddIncomeArgs

type AddIncomeArgs struct {
	MonthID uint
	Title   string
	Notes   string
	Income  money.Money
}

type AddMonthlyPaymentArgs

type AddMonthlyPaymentArgs struct {
	MonthID uint
	Title   string
	TypeID  uint
	Notes   string
	Cost    money.Money
}

type AddSpendArgs

type AddSpendArgs struct {
	DayID  uint
	Title  string
	TypeID uint   // optional
	Notes  string // optional
	Cost   money.Money
}

type Day

type Day struct {
	ID uint `json:"id"`

	Year  int        `json:"year"`
	Month time.Month `json:"month" swaggertype:"integer"`

	Day int `json:"day"`
	// Saldo is DailyBudget - Cost of all Spends. It can be negative
	Saldo  money.Money `json:"saldo" swaggertype:"number"`
	Spends []*Spend    `json:"spends"`
}

type EditIncomeArgs

type EditIncomeArgs struct {
	ID     uint
	Title  *string
	Notes  *string
	Income *money.Money
}

type EditMonthlyPaymentArgs

type EditMonthlyPaymentArgs struct {
	ID uint

	Title  *string
	TypeID *uint
	Notes  *string
	Cost   *money.Money
}

type EditSpendArgs

type EditSpendArgs struct {
	ID     uint
	Title  *string
	TypeID *uint
	Notes  *string
	Cost   *money.Money
}

type Income

type Income struct {
	ID uint `json:"id"`

	Year  int        `json:"year"`
	Month time.Month `json:"month" swaggertype:"integer"`

	Title  string      `json:"title"`
	Notes  string      `json:"notes,omitempty"`
	Income money.Money `json:"income" swaggertype:"number"`
}

Income contains information about incomes (salary, gifts and etc.)

type Month

type Month struct {
	ID uint `json:"id"`

	Year  int        `json:"year"`
	Month time.Month `json:"month" swaggertype:"integer"`

	Incomes         []*Income         `json:"incomes"`
	MonthlyPayments []*MonthlyPayment `json:"monthly_payments"`

	// DailyBudget is a (TotalIncome - Cost of Monthly Payments) / Number of Days
	DailyBudget money.Money `json:"daily_budget" swaggertype:"number"`
	Days        []*Day      `json:"days"`

	TotalIncome money.Money `json:"total_income" swaggertype:"number"`
	// TotalSpend is a cost of all Monthly Payments and Spends
	TotalSpend money.Money `json:"total_spend" swaggertype:"number"`
	// Result is TotalIncome - TotalSpend
	Result money.Money `json:"result" swaggertype:"number"`
}

type MonthlyPayment

type MonthlyPayment struct {
	ID uint `json:"id"`

	Year  int        `json:"year"`
	Month time.Month `json:"month" swaggertype:"integer"`

	Title string      `json:"title"`
	Type  *SpendType  `json:"type,omitempty"`
	Notes string      `json:"notes,omitempty"`
	Cost  money.Money `json:"cost" swaggertype:"number"`
}

MonthlyPayment contains information about monthly payments (rent, Patreon and etc.)

type SearchOrder added in v0.2.0

type SearchOrder int

SearchOrder is used to specify order of search results. 'Asc' by default

const (
	OrderByAsc SearchOrder = iota
	OrderByDesc
)

type SearchSpendsArgs added in v0.2.0

type SearchSpendsArgs struct {
	Title string // Must be in lovercase
	Notes string // Must be in lovercase

	// TitleExactly defines should we search exactly for the given title
	TitleExactly bool
	// NotesExactly defines should we search exactly for the given notes
	NotesExactly bool

	After  time.Time
	Before time.Time

	MinCost money.Money
	MaxCost money.Money

	// WithoutType is used to search for Spends without Spend Type. TypeIDs must be ignored when it is true
	WithoutType bool
	TypeIDs     []uint

	Sort  SearchSpendsColumn
	Order SearchOrder
}

SearchSpendsArgs is used to search for spends. All fields are optional

nolint:maligned

type SearchSpendsColumn added in v0.2.0

type SearchSpendsColumn int

SearchSpendsColumn is used to specify column to sort by. 'Date' by default

const (
	SortSpendsByDate SearchSpendsColumn = iota
	SortSpendsByTitle
	SortSpendsByCost
)

type Spend

type Spend struct {
	ID uint `json:"id"`

	Year  int        `json:"year"`
	Month time.Month `json:"month" swaggertype:"integer"`
	Day   int        `json:"day"`

	Title string      `json:"title"`
	Type  *SpendType  `json:"type,omitempty"`
	Notes string      `json:"notes,omitempty"`
	Cost  money.Money `json:"cost" swaggertype:"number"`
}

Spend contains information about spends

type SpendType

type SpendType struct {
	ID   uint   `json:"id"`
	Name string `json:"name"`
}

SpendType contains information about spend type

Directories

Path Synopsis
pg
Package pg provides a PostgreSQL implementation for DB
Package pg provides a PostgreSQL implementation for DB

Jump to

Keyboard shortcuts

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