diff options
author | xengineering <me@xengineering.eu> | 2023-04-01 16:03:49 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-04-01 18:21:27 +0200 |
commit | 88107366bce6b7f7c788171a18c40ad102904ff4 (patch) | |
tree | 1477a16e0d4e4b2151c23c0194ed9860fe5a6eb3 /handler.go | |
parent | eec9ddfd687a871880628b4a5e9b3c0541b534e2 (diff) | |
download | ceres-88107366bce6b7f7c788171a18c40ad102904ff4.tar ceres-88107366bce6b7f7c788171a18c40ad102904ff4.tar.zst ceres-88107366bce6b7f7c788171a18c40ad102904ff4.zip |
Implement recipe deletion
Diffstat (limited to 'handler.go')
-rw-r--r-- | handler.go | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -188,6 +188,44 @@ func recipeEditPost(w http.ResponseWriter, r *http.Request) { updateRecipe(body, idStr) } +func recipeConfirmDeletionGet(w http.ResponseWriter, r *http.Request) { + + ids := r.URL.Query()["id"] + if len(ids) != 1 { + http.Error(w, "Exactly 1 'id' URL parameter expected.", 400) + return + } + idStr := ids[0] + + type Element struct { + Id string + } + var element Element + element.Id = idStr + + ServeTemplate(w, "recipe_confirm_deletion.html", element) +} + +func recipeConfirmDeletionPost(w http.ResponseWriter, r *http.Request) { + + ids := r.URL.Query()["id"] + if len(ids) != 1 { + http.Error(w, "Exactly 1 'id' URL parameter expected.", 400) + return + } + idStr := ids[0] + + cmd := fmt.Sprintf("DELETE FROM recipes where (id='%s');", idStr) + _, err := db.Query(cmd) + if err != nil { + fmt.Print(err) + http.Error(w, "Could not delete recipe.", 500) + return; + } + + http.Redirect(w, r, "/index.html", 303) +} + func updateRecipe(body string, idStr string) { _, _ = db.Exec(` |