diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-11-09 19:17:38 -0500 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-11-09 19:21:05 -0500 |
commit | 902914a89b2465da42d7f35e0e6bbe390f559a12 (patch) | |
tree | 4a56ad9f8ac4a97f3fd740efaec09cb22c5ad0aa /backend | |
parent | 5521f0b7d49c81791acc6e2a897d36b341e70d8e (diff) |
Add basic access recipe functionality
Note: Only prints recipe to server stdout does not return to client
Diffstat (limited to 'backend')
-rw-r--r-- | backend/main.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/backend/main.go b/backend/main.go index f5a6e52..135d18d 100644 --- a/backend/main.go +++ b/backend/main.go @@ -21,7 +21,18 @@ func SingleRecipe(w http.ResponseWriter, r *http.Request) { return } if r.Method == "GET" { - fmt.Printf("Return recipe \"%d\"...\n", recipe_id) + recipe := RecipeFromId(recipe_id, db) + if recipe == nil { + recipe = MakeRecipe() + } + + output, err := json.MarshalIndent(recipe, "", " ") + if err != nil { + fmt.Println("Error converting to JSON") + } else { + fmt.Println(string(output)) + } + } else if r.Method == "POST" { fmt.Printf("Create recipe \"%d\"...\n", recipe_id) } else if r.Method == "PUT" { |