Export types to json

This commit is contained in:
2024-08-09 18:02:58 +02:00
parent b177416204
commit 01e6515de5
2 changed files with 27 additions and 27 deletions

View File

@@ -11,19 +11,19 @@ type (
db *DB
}
Food struct {
rowid int64
date string
food string
descripton string
amount float32
per100 float32
energy float32
rowid int64 `json:"rowid"`
date string `json:"date"`
food string `json:"food"`
descripton string `json:"description"`
amount float32 `json:"amount"`
per100 float32 `json:"per100"`
energy float32 `json:"energy"`
}
AggregatedFood struct {
period string
amount float32
avgPer100 float32
energy float32
period string `json:"period"`
amount float32 `json:"amount"`
avgPer100 float32 `json:"avgPer100"`
energy float32 `json:"energy"`
}
)
@@ -32,7 +32,7 @@ const foodAggregatedColumns = "period, amount, avgPer100, energy"
func (s *FoodService) GetRecent() ([]Food, error) {
var res []Food
if s.db == nil || !s.db.Ready {
if s.db == nil || !s.db.Ready {
return res, fmt.Errorf("cannot get recent food, db is nil or is not ready")
}
@@ -66,7 +66,7 @@ func (s *FoodService) Create(food Food) (Food, error) {
if food.amount <= 0 {
return food, fmt.Errorf("cannot create food, amount is less than or equal to 0")
}
var res sql.Result
var err error
if food.per100 > 0 {
@@ -237,4 +237,4 @@ func (s *FoodService) GetYearly() ([]AggregatedFood, error) {
}
return res, nil
}
}

View File

@@ -13,21 +13,21 @@ type (
)
type settings struct {
FoodDaysLookback int
FoodAggregatedDaysLookback int
FoodDailyLookback int
FoodWeeklyLookback int
FoodMonthlyLookback int
FoodYearlyLookback int
FoodDaysLookback int `default:"30" json:"foodDaysLookback"`
FoodAggregatedDaysLookback int `default:"30" json:"foodAggregatedDaysLookback"`
FoodDailyLookback int `default:"30" json:"foodDailyLookback"`
FoodWeeklyLookback int `default:"4" json:"foodWeeklyLookback"`
FoodMonthlyLookback int `default:"4" json:"foodMonthlyLookback"`
FoodYearlyLookback int `default:"2" json:"foodYearlyLookback"`
WeightDaysLookback int
WeightAggregatedDaysLookback int
WeightDailyLookback int
WeightWeeklyLookback int
WeightMonthlyLookback int
WeightYearlyLookback int
WeightDaysLookback int `default:"30" json:"weightDaysLookback"`
WeightAggregatedDaysLookback int `default:"30" json:"weightAggregatedDaysLookback"`
WeightDailyLookback int `default:"30" json:"weightDailyLookback"`
WeightWeeklyLookback int `default:"4" json:"weightWeeklyLookback"`
WeightMonthlyLookback int `default:"4" json:"weightMonthlyLookback"`
WeightYearlyLookback int `default:"2" json:"weightYearlyLookback"`
Target int
Target int `default:"2000" json:"target"`
}
var Settings settings