From 902914a89b2465da42d7f35e0e6bbe390f559a12 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 9 Nov 2019 19:17:38 -0500 Subject: Add basic access recipe functionality Note: Only prints recipe to server stdout does not return to client --- backend/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'backend') 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" { -- cgit v1.1