diff --git a/app.go b/app.go
index b392579..de048a1 100644
--- a/app.go
+++ b/app.go
@@ -20,6 +20,10 @@ func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
-func (a *App) GetFood() ([]Food, error) {
- return foodService.GetRecent()
+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}
}
\ No newline at end of file
diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte
index b7e722b..8f2caea 100644
--- a/frontend/src/App.svelte
+++ b/frontend/src/App.svelte
@@ -1,9 +1,6 @@
diff --git a/frontend/src/lib/components/Energy/Energy.svelte b/frontend/src/lib/components/Energy/Energy.svelte
index e69de29..fac7599 100644
--- a/frontend/src/lib/components/Energy/Energy.svelte
+++ b/frontend/src/lib/components/Energy/Energy.svelte
@@ -0,0 +1,20 @@
+
+
+
+ {#each food as f}
+ {f.food}
+ {/each}
+
\ No newline at end of file
diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts
index ac77339..987b6bb 100644
--- a/frontend/wailsjs/go/main/App.d.ts
+++ b/frontend/wailsjs/go/main/App.d.ts
@@ -2,4 +2,4 @@
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
-export function GetFood():Promise>;
+export function GetFood():Promise;
diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts
index d9113e0..6c9d68c 100644
--- a/frontend/wailsjs/go/models.ts
+++ b/frontend/wailsjs/go/models.ts
@@ -1,7 +1,13 @@
export namespace main {
export class Food {
-
+ rowid: number;
+ date: string;
+ food: string;
+ description: string;
+ amount: number;
+ per100: number;
+ energy: number;
static createFrom(source: any = {}) {
return new Food(source);
@@ -9,9 +15,49 @@ export namespace main {
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
-
+ this.rowid = source["rowid"];
+ this.date = source["date"];
+ this.food = source["food"];
+ this.description = source["description"];
+ this.amount = source["amount"];
+ this.per100 = source["per100"];
+ this.energy = source["energy"];
}
}
+ export class WailsFood {
+ data: Food[];
+ success: boolean;
+ error?: string;
+
+ static createFrom(source: any = {}) {
+ return new WailsFood(source);
+ }
+
+ constructor(source: any = {}) {
+ if ('string' === typeof source) source = JSON.parse(source);
+ this.data = this.convertValues(source["data"], Food);
+ this.success = source["success"];
+ this.error = source["error"];
+ }
+
+ convertValues(a: any, classs: any, asMap: boolean = false): any {
+ if (!a) {
+ return a;
+ }
+ if (a.slice && a.map) {
+ return (a as any[]).map(elem => this.convertValues(elem, classs));
+ } else if ("object" === typeof a) {
+ if (asMap) {
+ for (const key of Object.keys(a)) {
+ a[key] = new classs(a[key]);
+ }
+ return a;
+ }
+ return new classs(a);
+ }
+ return a;
+ }
+ }
}
diff --git a/types.go b/types.go
deleted file mode 100644
index 59608a5..0000000
--- a/types.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package main
-
-import "time"
-
-type (
-
- Weight struct {
- rowid int
- date time.Time
- weight float32
- }
- AggregatedWeight struct {
- period string
- amount float32
- }
-)
diff --git a/wailstypes.go b/wailstypes.go
new file mode 100644
index 0000000..596aed7
--- /dev/null
+++ b/wailstypes.go
@@ -0,0 +1,33 @@
+package main
+
+import "time"
+
+type (
+ // Wails doesn't rlike generics... Fuck...
+ // WailsReturn[T interface{}] struct {
+ // Data T `json:'data'`
+ // Success bool `json:'success'`
+ // Error string `json:'error'`
+ // }
+
+ WailsFood struct {
+ Data []Food `json:"data"`
+ Success bool `json:"success"`
+ Error string `json:"error,omitempty"`
+ }
+ WailsAggregateFood struct {
+ Data []AggregatedFood `json:"data"`
+ Success bool `json:"success"`
+ Error string `json:"error,omitempty"`
+ }
+
+ Weight struct {
+ rowid int
+ date time.Time
+ weight float32
+ }
+ AggregatedWeight struct {
+ period string
+ amount float32
+ }
+)