45 lines
962 B
Go
45 lines
962 B
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
|
|
}
|
|
|
|
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}
|
|
} |