model

package
v0.0.0-...-eddb447 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequiredEntry

func RequiredEntry(entryId int) func(db *gorm.DB) *gorm.DB

RequiredEntry can be used as a scope to return a custom error if the entry id associated with the expense doesn't exist.

func ValidateModel

func ValidateModel(model ModelValidator) func(db *gorm.DB) *gorm.DB

ValidateModel can be used as a scope to validate any of the existing GORM models, that implement the ModelValidator interface.

Types

type BaseModel

type BaseModel struct {
	Id        int `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

type Debt

type Debt struct {
	BaseModel
	Value

	Person  string
	Details string
}

Debt models a debt owed to or held by someone. Fields are automatically mapped by gorm to their database equivalents.

func (*Debt) AfterDelete

func (d *Debt) AfterDelete(tx *gorm.DB) (err error)

AfterDelete is a gorm hook that adds an error if the debt was not found during an delete operation. This implicitly assumes that the delete query executes with a "returning" clause that writes to an empty debt.

func (*Debt) AfterUpdate

func (d *Debt) AfterUpdate(tx *gorm.DB) (err error)

AfterUpdate is a gorm hook that adds an error if the debt was not found during an update operation. This implicitly assumes that the update query executes with a "returning" clause that writes to an empty debt.

func (Debt) Validate

func (d Debt) Validate() error

type Entry

type Entry struct {
	BaseModel
	Value

	Month       int
	Year        int
	Category    string
	Subcategory string
	Recurring   bool

	Expenses []Expense
}

Entry models an entry of a planning. Fields are automatically mapped by gorm to their database equivalents.

func (*Entry) AfterDelete

func (e *Entry) AfterDelete(tx *gorm.DB) (err error)

AfterDelete is a gorm hook that adds an error if the entry was not found during an delete operation. This implicitly assumes that the delete query executes with a "returning" clause that writes to an empty entry.

func (*Entry) AfterUpdate

func (e *Entry) AfterUpdate(tx *gorm.DB) (err error)

AfterUpdate is a gorm hook that adds an error if the entry was not found during an update operation. This implicitly assumes that the update query executes with a "returning" clause that writes to an empty entry.

func (Entry) Validate

func (e Entry) Validate() error

type ErrExpenseInvalidEntryKey

type ErrExpenseInvalidEntryKey struct {
	// contains filtered or unexported fields
}

func (ErrExpenseInvalidEntryKey) Error

type ErrInvalidModel

type ErrInvalidModel struct {
	// contains filtered or unexported fields
}

ErrInvalidModel stores the data of a model validation error. The reasons are included to provide all issues that occured during validation.

func NewBaseModelError

func NewBaseModelError(prefix string, reasons []string) ErrInvalidModel

func (ErrInvalidModel) Error

func (b ErrInvalidModel) Error() string

type Expense

type Expense struct {
	BaseModel
	Value

	EntryId       int
	Name          string
	Description   string
	PaymentMethod string
}

Expense models an expense that can be associated with an entry. Fields are automatically mapped by gorm to their database equivalents.

func (*Expense) AfterDelete

func (e *Expense) AfterDelete(tx *gorm.DB) (err error)

AfterDelete is a gorm hook that adds an error if the expense was not found during an delete operation. This implicitly assumes that the delete query executes with a "returning" clause that writes to an empty expense.

func (*Expense) AfterUpdate

func (e *Expense) AfterUpdate(tx *gorm.DB) (err error)

AfterUpdate is a gorm hook that adds an error if the expense was not found during an update operation. This implicitly assumes that the update query executes with a "returning" clause that writes to an empty expense.

func (Expense) Validate

func (e Expense) Validate() error

type InvalidModelErrBuilder

type InvalidModelErrBuilder struct {
	// contains filtered or unexported fields
}

InvalidModelErrBuilder can be used to create detailed model validation errors, by adding each individual error after instantiating a builder.

func NewBaseModelErrorBuilder

func NewBaseModelErrorBuilder(modelName string) *InvalidModelErrBuilder

func (*InvalidModelErrBuilder) AddError

func (b *InvalidModelErrBuilder) AddError(err string)

func (*InvalidModelErrBuilder) Error

func (b *InvalidModelErrBuilder) Error() error

type ModelValidator

type ModelValidator interface {
	Validate() error
}

ModelValidator is the interface all models implement to throws

type Value

type Value struct {
	Currency string
	Amount   int
	Exponent int
}

func FromCurrencyValue

func FromCurrencyValue(v currency.Value) Value

FromCurrencyValue converts the public currency Value type to the model representation of value.

Jump to

Keyboard shortcuts

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