28 lines
1,008 B
Go
28 lines
1,008 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Category struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
Label string `gorm:"unique;not null" json:"label"`
|
|
Color string `gorm:"not null;default:#9eb1e7" json:"color"`
|
|
MonthThreshold *float64 `json:"month_threshold"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Transactions []Transaction `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"transactions"`
|
|
Rules []CategoryRule `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"rules"`
|
|
IgnoreTransactions *bool `gorm:"not null;default:0" json:"ignore_transactions"`
|
|
}
|
|
|
|
func NewCategory(label, color string, rules []CategoryRule, monthThreshold *float64) *Category {
|
|
category := Category{
|
|
Label: label,
|
|
Color: color,
|
|
Rules: rules,
|
|
MonthThreshold: monthThreshold,
|
|
}
|
|
|
|
return &category
|
|
}
|