Implement settingsservice

This commit is contained in:
2024-08-09 15:16:02 +02:00
parent d6e00316bc
commit 56e0ef49a0
8 changed files with 61 additions and 7 deletions

View File

@@ -0,0 +1,37 @@
package main
import (
"fmt"
"log"
)
type (
SettingsService struct {
db *DB
}
)
var Settings map[string]string = map[string]string{
"FoodDaysLookback": "7",
"FoodAggregatedDaysLookback": "7",
"WeightDaysLookback": "7",
"WeightAggregatedDaysLookback": "7",
}
func (s *SettingsService) LoadSettings() (map[string]string, error) {
if s.db == nil || !s.db.Ready {
return Settings, fmt.Errorf("cannot load Settings, db is nil or is not ready")
}
for key := range Settings {
var value string
err := s.db.readConn.QueryRow("SELECT value FROM settings WHERE key = ?", key).Scan(&value)
if err != nil {
Error.Printf("error getting setting for key %s: %++v", key, err)
continue
}
log.Println(key, value)
}
return Settings, nil
}