caltrack/types/types.go
Bastian Gruber 6b6778508f
Some checks are pending
Build and Push / build (push) Waiting to run
fix: store entries for the day I am currently seeing
2026-02-24 12:19:54 +00:00

126 lines
3.8 KiB
Go

package types
import "time"
type EntryType string
const (
EntryFood EntryType = "food"
EntryExercise EntryType = "exercise"
)
type Entry struct {
ID int64 `json:"id"`
Date string `json:"date"`
Time string `json:"time"`
Type EntryType `json:"type"`
Description string `json:"description"`
Kcal int `json:"kcal"`
CreatedAt time.Time `json:"created_at"`
}
type DailySummary struct {
Date string `json:"date"`
TotalConsumed int `json:"total_consumed"`
TotalBurned int `json:"total_burned"`
TargetKcal int `json:"target_kcal"`
NetKcal int `json:"net_kcal"`
}
type WeighIn struct {
ID int64 `json:"id"`
Date string `json:"date"`
WeightKg float64 `json:"weight_kg"`
CreatedAt time.Time `json:"created_at"`
}
type Product struct {
ID int64 `json:"id"`
Name string `json:"name"`
Brand string `json:"brand"`
ServingSize float64 `json:"serving_size"`
ServingUnit string `json:"serving_unit"`
KcalPerServing int `json:"kcal_per_serving"`
Source string `json:"source"`
CreatedAt time.Time `json:"created_at"`
LastUsed time.Time `json:"last_used"`
}
type Config struct {
AnthropicAPIKey string `toml:"anthropic_api_key" json:"-"`
CurrentWeightKg float64 `toml:"current_weight_kg" json:"current_weight_kg"`
TargetWeightKg float64 `toml:"target_weight_kg" json:"target_weight_kg"`
HeightCm int `toml:"height_cm" json:"height_cm"`
Age int `toml:"age" json:"age"`
Sex string `toml:"sex" json:"sex"`
ActivityLevel string `toml:"activity_level" json:"activity_level"`
WeeklyLossKg float64 `toml:"weekly_loss_kg" json:"weekly_loss_kg"`
ListenAddr string `toml:"listen_addr" json:"listen_addr"`
Timezone string `toml:"timezone" json:"timezone"`
HasAPIKey bool `toml:"-" json:"has_api_key"`
}
// Now returns the current time in the configured timezone.
func (c *Config) Now() time.Time {
if c.Timezone != "" {
if loc, err := time.LoadLocation(c.Timezone); err == nil {
return time.Now().In(loc)
}
}
return time.Now()
}
type TodayResponse struct {
Date string `json:"date"`
Entries []Entry `json:"entries"`
Summary DailySummary `json:"summary"`
TargetKcal int `json:"target_kcal"`
Deficit int `json:"deficit"`
Weight float64 `json:"weight"`
Config Config `json:"config"`
}
type AddEntryRequest struct {
Type EntryType `json:"type"`
Description string `json:"description"`
Date string `json:"date,omitempty"`
}
type AddEntryResponse struct {
Entries []Entry `json:"entries"`
}
type WeighInRequest struct {
WeightKg float64 `json:"weight_kg"`
}
type SettingsRequest struct {
CurrentWeightKg *float64 `json:"current_weight_kg,omitempty"`
TargetWeightKg *float64 `json:"target_weight_kg,omitempty"`
HeightCm *int `json:"height_cm,omitempty"`
Age *int `json:"age,omitempty"`
Sex *string `json:"sex,omitempty"`
ActivityLevel *string `json:"activity_level,omitempty"`
WeeklyLossKg *float64 `json:"weekly_loss_kg,omitempty"`
AnthropicAPIKey *string `json:"anthropic_api_key,omitempty"`
}
type AutocompleteResult struct {
Name string `json:"name"`
Brand string `json:"brand"`
KcalPerServing int `json:"kcal_per_serving"`
ServingSize float64 `json:"serving_size"`
ServingUnit string `json:"serving_unit"`
}
type AIEstimation struct {
Items []AIEstimationItem `json:"items"`
}
type AIEstimationItem struct {
Name string `json:"name"`
Brand string `json:"brand"`
Kcal int `json:"kcal"`
ServingSize float64 `json:"serving_size"`
ServingUnit string `json:"serving_unit"`
}