summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-10 11:09:16 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-10 11:09:16 -0500
commit7995a8bd93ab6a98c6e4a78951e60e37e475388a (patch)
tree3452102a457b47977f9e6b4113ad1e6e89fc8834
parent902914a89b2465da42d7f35e0e6bbe390f559a12 (diff)
Add basic functionality to get list of recipe ids
Note: Still only prints to stdout, does not respond to client
-rw-r--r--backend/main.go19
1 files changed, 18 insertions, 1 deletions
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))
+ }
}
}