143 lines
3.8 KiB
Go
143 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
)
|
|
|
|
// App struct
|
|
type App struct {
|
|
ctx context.Context
|
|
}
|
|
|
|
// NewApp creates a new App application struct
|
|
func NewApp() *App {
|
|
return &App{}
|
|
}
|
|
|
|
// startup is called when the app starts. The context is saved
|
|
// so we can call the runtime methods
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
}
|
|
|
|
// region food
|
|
func (a *App) GetFood() WailsFood {
|
|
data, err := foodService.GetRecent()
|
|
if err != nil {
|
|
return WailsFood{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsFood{Data: data, Success: true}
|
|
}
|
|
func (a *App) CreateFood(food Food) WailsFood1 {
|
|
data, err := foodService.Create(food)
|
|
if err != nil {
|
|
return WailsFood1{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsFood1{Data: data, Success: true}
|
|
}
|
|
func (a *App) UpdateFood(food Food) WailsFood1 {
|
|
data, err := foodService.Update(food)
|
|
if err != nil {
|
|
return WailsFood1{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsFood1{Data: data, Success: true}
|
|
}
|
|
|
|
func (a *App) GetLastPer100(name string) WailsFood1 {
|
|
data, err := foodService.GetLastPer100(name)
|
|
if err != nil {
|
|
return WailsFood1{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsFood1{Data: data, Success: true}
|
|
}
|
|
|
|
func (a *App) GetDailyFood() WailsAggregateFood {
|
|
data, err := foodService.GetDaily()
|
|
if err != nil {
|
|
return WailsAggregateFood{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateFood{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetWeeklyFood() WailsAggregateFood {
|
|
data, err := foodService.GetWeekly()
|
|
if err != nil {
|
|
return WailsAggregateFood{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateFood{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetMonthlyFood() WailsAggregateFood {
|
|
data, err := foodService.GetMonthly()
|
|
if err != nil {
|
|
return WailsAggregateFood{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateFood{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetYearlyFood() WailsAggregateFood {
|
|
data, err := foodService.GetYearly()
|
|
if err != nil {
|
|
return WailsAggregateFood{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateFood{Data: data, Success: true}
|
|
}
|
|
|
|
// region weight
|
|
func (a *App) GetWeight() WailsWeight {
|
|
data, err := weightService.GetRecent()
|
|
if err != nil {
|
|
return WailsWeight{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsWeight{Data: data, Success: true}
|
|
}
|
|
func (a *App) CreateWeight(weight Weight) WailsWeight1 {
|
|
data, err := weightService.Create(weight)
|
|
if err != nil {
|
|
return WailsWeight1{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsWeight1{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetDailyWeight() WailsAggregateWeight {
|
|
data, err := weightService.GetDaily()
|
|
if err != nil {
|
|
return WailsAggregateWeight{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateWeight{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetWeeklyWeight() WailsAggregateWeight {
|
|
data, err := weightService.GetWeekly()
|
|
if err != nil {
|
|
return WailsAggregateWeight{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateWeight{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetMonthlyWeight() WailsAggregateWeight {
|
|
data, err := weightService.GetMonthly()
|
|
if err != nil {
|
|
return WailsAggregateWeight{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateWeight{Data: data, Success: true}
|
|
}
|
|
func (a *App) GetYearlyWeight() WailsAggregateWeight {
|
|
data, err := weightService.GetYearly()
|
|
if err != nil {
|
|
return WailsAggregateWeight{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsAggregateWeight{Data: data, Success: true}
|
|
}
|
|
|
|
// region settings
|
|
func (a *App) GetSettings() settings {
|
|
return Settings
|
|
}
|
|
func (a *App) SetSetting(key string, value int64) WailsGenericAck {
|
|
_, err := settingsService.Set(key, value)
|
|
if err != nil {
|
|
return WailsGenericAck{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsGenericAck{Success: true}
|
|
}
|
|
|
|
//region other
|
|
func (a *App) Close() {
|
|
os.Exit(0)
|
|
} |