From 7995a8bd93ab6a98c6e4a78951e60e37e475388a Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 10 Nov 2019 11:09:16 -0500 Subject: Add basic functionality to get list of recipe ids Note: Still only prints to stdout, does not respond to client --- backend/main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/main.go b/backend/main.go index 135d18d..4679e73 100644 --- a/backend/main.go +++ b/backend/main.go @@ -10,7 +10,24 @@ import "encoding/json" func RecipeList(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { - fmt.Printf("Return all recipe names...\n") + var ids []int + var id int + + rows, err := db.Query("SELECT id FROM recipes") + if err != nil { + } else { + for rows.Next() { + rows.Scan(&id) + ids = append(ids, id) + } + } + + output, err := json.MarshalIndent(ids, "", " ") + if err != nil { + fmt.Println("Error converting to JSON") + } else { + fmt.Println(string(output)) + } } } -- cgit v1.1