From 683c443b7f5007bd77cd24b851caae0531bf58ed Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 9 Aug 2024 17:18:16 +0200 Subject: [PATCH] Fix up and export food service --- app.go | 10 ++-------- foodservice.go | 25 +++++-------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/app.go b/app.go index 993e720..b392579 100644 --- a/app.go +++ b/app.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" ) // App struct @@ -21,11 +20,6 @@ func (a *App) startup(ctx context.Context) { a.ctx = ctx } -// Greet returns a greeting for the given name -func (a *App) Greet(name string) string { - return fmt.Sprintf("Hello %s, It's show time!", name) -} - -func (a *App) Foo() string { - return "bar" +func (a *App) GetFood() ([]Food, error) { + return foodService.GetRecent() } \ No newline at end of file diff --git a/foodservice.go b/foodservice.go index 98caeb3..dde25da 100644 --- a/foodservice.go +++ b/foodservice.go @@ -42,7 +42,6 @@ func (s *FoodService) GetRecent() ([]Food, error) { return res, err } - var rows []Food for row.Next() { var food Food err := row.Scan(&food.rowid, &food.date, &food.food, &food.descripton, &food.amount, &food.per100, &food.energy) @@ -51,11 +50,9 @@ func (s *FoodService) GetRecent() ([]Food, error) { continue } - rows = append(rows, food) + res = append(res, food) } - log.Printf("%++v", rows) - return res, nil } @@ -150,7 +147,6 @@ func (s *FoodService) GetDaily() ([]AggregatedFood, error) { return res, err } - var rows []AggregatedFood for row.Next() { var food AggregatedFood err := row.Scan(&food.period, &food.amount, &food.avgPer100, &food.energy) @@ -159,11 +155,9 @@ func (s *FoodService) GetDaily() ([]AggregatedFood, error) { continue } - rows = append(rows, food) + res = append(res, food) } - log.Printf("%++v", rows) - return res, nil } @@ -179,7 +173,6 @@ func (s *FoodService) GetWeekly() ([]AggregatedFood, error) { return res, err } - var rows []AggregatedFood for row.Next() { var food AggregatedFood err := row.Scan(&food.period, &food.amount, &food.avgPer100, &food.energy) @@ -188,11 +181,9 @@ func (s *FoodService) GetWeekly() ([]AggregatedFood, error) { continue } - rows = append(rows, food) + res = append(res, food) } - log.Printf("%++v", rows) - return res, nil } @@ -208,7 +199,6 @@ func (s *FoodService) GetMonthly() ([]AggregatedFood, error) { return res, err } - var rows []AggregatedFood for row.Next() { var food AggregatedFood err := row.Scan(&food.period, &food.amount, &food.avgPer100, &food.energy) @@ -217,11 +207,9 @@ func (s *FoodService) GetMonthly() ([]AggregatedFood, error) { continue } - rows = append(rows, food) + res = append(res, food) } - log.Printf("%++v", rows) - return res, nil } @@ -237,7 +225,6 @@ func (s *FoodService) GetYearly() ([]AggregatedFood, error) { return res, err } - var rows []AggregatedFood for row.Next() { var food AggregatedFood err := row.Scan(&food.period, &food.amount, &food.avgPer100, &food.energy) @@ -246,10 +233,8 @@ func (s *FoodService) GetYearly() ([]AggregatedFood, error) { continue } - rows = append(rows, food) + res = append(res, food) } - log.Printf("%++v", rows) - return res, nil } \ No newline at end of file