diff options
Diffstat (limited to 'controller')
| -rw-r--r-- | controller/recipe.go | 32 | 
1 files changed, 32 insertions, 0 deletions
| diff --git a/controller/recipe.go b/controller/recipe.go new file mode 100644 index 0000000..4d5de53 --- /dev/null +++ b/controller/recipe.go @@ -0,0 +1,32 @@ +package controller + +import ( +	"encoding/json" +	"io" +	"net/http" + +	"xengineering.eu/ceres/model" +) + +func Recipe(w http.ResponseWriter, r *http.Request) { +	buf, err := io.ReadAll(r.Body) +	if err != nil { +		http.Error(w, err.Error(), http.StatusInternalServerError) +		return +	} + +	recipe := model.Recipe{} +	err = json.Unmarshal(buf, &recipe) +	if err != nil { +		http.Error(w, err.Error(), http.StatusBadRequest) +		return +	} + +	err = recipe.Update() +	if err != nil { +		http.Error(w, err.Error(), http.StatusInternalServerError) +		return +	} + +	http.Redirect(w, r, "/recipe/" + recipe.Id, http.StatusSeeOther) +} | 
