Rework lastper100 to return a food instead of float32

This commit is contained in:
2024-08-13 15:31:50 +02:00
parent abb25c1357
commit 6bfd5cc26a
4 changed files with 11 additions and 27 deletions

6
app.go
View File

@@ -44,12 +44,12 @@ func (a *App) UpdateFood(food Food) WailsFood1 {
return WailsFood1{Data: data, Success: true} return WailsFood1{Data: data, Success: true}
} }
func (a *App) GetLastPer100(name string) WailsPer100 { func (a *App) GetLastPer100(name string) WailsFood1 {
data, err := foodService.GetLastPer100(name) data, err := foodService.GetLastPer100(name)
if err != nil { if err != nil {
return WailsPer100{Success: false, Error: err.Error()} return WailsFood1{Success: false, Error: err.Error()}
} }
return WailsPer100{Data: data, Success: true} return WailsFood1{Data: data, Success: true}
} }
func (a *App) GetDailyFood() WailsAggregateFood { func (a *App) GetDailyFood() WailsAggregateFood {

View File

@@ -56,19 +56,19 @@ func (s *FoodService) GetRecent() ([]Food, error) {
return res, nil return res, nil
} }
func (s *FoodService) GetLastPer100(name string) (float32, error) { func (s *FoodService) GetLastPer100(name string) (Food, error) {
res := Food{}
if s.db == nil || !s.db.Ready { if s.db == nil || !s.db.Ready {
return 0, fmt.Errorf("cannot get last per100, db is nil or is not ready") return res, fmt.Errorf("cannot get last per100, db is nil or is not ready")
} }
row := s.db.readConn.QueryRow("SELECT per100 FROM food WHERE food like ? ORDER BY rowid DESC LIMIT 1", name+"%") row := s.db.readConn.QueryRow(fmt.Sprintf("SELECT %s FROM food WHERE food like ? ORDER BY rowid DESC LIMIT 1", foodColumns), name+"%")
var per100 float32 err := row.Scan(&res.Rowid, &res.Date, &res.Food, &res.Descripton, &res.Amount, &res.Per100, &res.Energy)
err := row.Scan(&per100)
if err != nil { if err != nil {
return 0, fmt.Errorf("error scanning row: %v", err) return res, fmt.Errorf("error scanning row: %v", err)
} }
return per100, nil return res, nil
} }
func (s *FoodService) Create(food Food) (Food, error) { func (s *FoodService) Create(food Food) (Food, error) {

View File

@@ -14,7 +14,7 @@ export function GetDailyWeight():Promise<main.WailsAggregateWeight>;
export function GetFood():Promise<main.WailsFood>; export function GetFood():Promise<main.WailsFood>;
export function GetLastPer100(arg1:string):Promise<main.WailsPer100>; export function GetLastPer100(arg1:string):Promise<main.WailsFood1>;
export function GetMonthlyFood():Promise<main.WailsAggregateFood>; export function GetMonthlyFood():Promise<main.WailsAggregateFood>;

View File

@@ -206,22 +206,6 @@ export namespace main {
this.error = source["error"]; this.error = source["error"];
} }
} }
export class WailsPer100 {
data: number;
success: boolean;
error?: string;
static createFrom(source: any = {}) {
return new WailsPer100(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.data = source["data"];
this.success = source["success"];
this.error = source["error"];
}
}
export class Weight { export class Weight {
rowid: number; rowid: number;
date: string; date: string;