65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// 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) WailsPer100 {
|
|
data, err := foodService.GetLastPer100(name)
|
|
if err != nil {
|
|
return WailsPer100{Success: false, Error: err.Error()}
|
|
}
|
|
return WailsPer100{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}
|
|
}
|