Add consts.go to db package and move all Metric values to consts.go

This commit is contained in:
qowevisa 2024-12-01 12:37:29 +02:00
parent eeaec565bd
commit e83cf56126
2 changed files with 12 additions and 4 deletions

8
db/consts.go Normal file
View File

@ -0,0 +1,8 @@
package db
const (
METRIC_VALUE_NONE = 0 + iota
METRIC_VALUE_GRAM
METRIC_VALUE_KILOGRAM
METRIC_VALUE_LITER
)

View File

@ -107,10 +107,10 @@ func checkSeededValues[T Identifiable](whatToCheck []*T, errorIfNotFound error,
func initMetrics(tx *gorm.DB) error {
metricsThatNeeded := []*Metric{
&Metric{Name: "None", Short: "pcs", Value: 0},
&Metric{Name: "Gram", Short: "g", Value: 1},
&Metric{Name: "Kilogram", Short: "kg", Value: 2},
&Metric{Name: "Liter", Short: "l", Value: 3},
&Metric{Name: "None", Short: "pcs", Value: METRIC_VALUE_NONE},
&Metric{Name: "Gram", Short: "g", Value: METRIC_VALUE_GRAM},
&Metric{Name: "Kilogram", Short: "kg", Value: METRIC_VALUE_KILOGRAM},
&Metric{Name: "Liter", Short: "l", Value: METRIC_VALUE_LITER},
}
return checkSeededValues(metricsThatNeeded, CANT_FIND_METRIC, tx)
}