summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-10 11:29:20 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-10 11:29:20 -0500
commit2efe3ce53cebd373bf56ba7580bb63df16871bac (patch)
treea6b4f5e19585297beff6a92653912b475cae6cd5 /backend
parent4f408d2b9521a2e0ff22495f6a6a6646e5a3135d (diff)
Add correct errors for an nonexistent recipe id
Diffstat (limited to 'backend')
-rw-r--r--backend/main.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/backend/main.go b/backend/main.go
index 1ed188a..7376bd0 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -66,16 +66,27 @@ func SingleRecipe(w http.ResponseWriter, r *http.Request) {
return
}
if r.Method == "GET" {
+ var status int
+ var msg string
+
recipe := RecipeFromId(recipe_id, db)
if recipe == nil {
- recipe = MakeRecipe()
+ status = http.StatusNotFound
+ msg = "Recipe not Found"
+ } else {
+ status = http.StatusOK
+ msg = "Successful"
}
+ fmt.Println(status, msg, recipe)
resp := APIResponseItem{
- Status: APIError{Code: 200, Msg: "Successful Request"},
+ Status: APIError{Code: status, Msg: msg},
Data: make([]APIDataRecipe, 0),
}
- resp.Data = append(resp.Data, APIDataRecipe{recipe})
+
+ if status == http.StatusOK {
+ resp.Data = append(resp.Data, APIDataRecipe{recipe})
+ }
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)