-
Notifications
You must be signed in to change notification settings - Fork 127
/
commodity.go
42 lines (34 loc) · 961 Bytes
/
commodity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package commodity
import (
"github.com/ananthakumaran/paisa/internal/model/price"
"github.com/samber/lo"
"github.com/spf13/viper"
)
type TaxCategoryType string
const (
Debt TaxCategoryType = "debt"
Equity TaxCategoryType = "equity"
)
type Commodity struct {
Name string
Type price.CommodityType
Code string
Harvest int
TaxCategory TaxCategoryType `mapstructure:"tax_category"`
}
func All() []Commodity {
var commodities []Commodity
viper.UnmarshalKey("commodities", &commodities)
return commodities
}
func FindByName(name string) Commodity {
c, _ := lo.Find(All(), func(c Commodity) bool { return c.Name == name })
return c
}
func FindByCode(name string) Commodity {
c, _ := lo.Find(All(), func(c Commodity) bool { return c.Code == name })
return c
}
func FindByType(commodityType price.CommodityType) []Commodity {
return lo.Filter(All(), func(c Commodity, _ int) bool { return c.Type == commodityType })
}