diff options
Diffstat (limited to 'view')
-rw-r--r-- | view/common.go | 18 | ||||
-rw-r--r-- | view/html/recipe-edit.html | 40 |
2 files changed, 58 insertions, 0 deletions
diff --git a/view/common.go b/view/common.go index c371fa0..b4df532 100644 --- a/view/common.go +++ b/view/common.go @@ -62,3 +62,21 @@ func HandlerHTML(prototype model.ReadableData) http.HandlerFunc { } } } + +func RecipeEditHandler(w http.ResponseWriter, r *http.Request) { + var recipe model.Recipe + var err error + + vars := mux.Vars(r) + recipe.Id = vars[`id`] + + err = recipe.FromDB() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + + err = html.ExecuteTemplate(w, `recipe-edit`, recipe) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } +} diff --git a/view/html/recipe-edit.html b/view/html/recipe-edit.html new file mode 100644 index 0000000..b4d6da5 --- /dev/null +++ b/view/html/recipe-edit.html @@ -0,0 +1,40 @@ +{{define "recipe-edit"}} +<html> + {{ template "head" }} + <header> + <nav> + <a href="/">HOME</a> + </nav> + <h1>Recipe editor</h1> + </header> + <body> + <main> + <form action="/recipes/{{.Id}}" method="POST"> + <p> + <label>Title</label> + <input type="text" name="title" value="{{.Title}}"> + </p> + + <p> + <label>Portions</label> + <input type="number" name="portions" value="{{.Portions}}"> + </p> + + <p> + <label>URL</label> + <input type="text" name="url" value="{{.URL}}"> + </p> + + <p> + <label>Notes</label> + <input type="text" name="notes" value="{{.Notes}}"> + </p> + + <input type="submit" value="save"> + <a href="/recipes/{{.Id}}"><button type="button">cancel</button></a> + </form> + </main> + {{ template "footer" }} + </body> +</html> +{{end}} |