new cake form
This commit is contained in:
parent
36484f874f
commit
331f3080f9
8 changed files with 127 additions and 43 deletions
45
handlers.go
45
handlers.go
|
|
@ -3,14 +3,55 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *controller) cakeOptions(w http.ResponseWriter, _ *http.Request) {
|
||||
func (c *controller) cakeOptions(w http.ResponseWriter, r *http.Request) {
|
||||
type cake struct {
|
||||
Name string
|
||||
ID int
|
||||
}
|
||||
c.tmpl["available_cakes"].Execute(w, struct{ Cakes []cake }{Cakes: []cake{{"Hello", 1}, {"World", 2}}})
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
template := strings.Split(r.URL.String(), "/")[1]
|
||||
c.tmpl[template].Execute(w, struct{ Cakes []cake }{Cakes: []cake{{"Hello", 1}, {"World", 2}}})
|
||||
}
|
||||
|
||||
func (c *controller) editCakes(w http.ResponseWriter, r *http.Request) {
|
||||
type cake struct {
|
||||
Name string
|
||||
ID int
|
||||
Price int
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
c.tmpl["cake_editor"].Execute(w, cake{"Hello", 1, 120})
|
||||
}
|
||||
|
||||
func (c *controller) newCake(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
c.tmpl["alert"].Execute(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
type cake struct {
|
||||
Name string
|
||||
ID int
|
||||
Price int
|
||||
}
|
||||
var out cake
|
||||
out.Name = r.FormValue("name")
|
||||
out.Price, err = strconv.Atoi(r.FormValue("price"))
|
||||
if err != nil {
|
||||
c.tmpl["alert"].Execute(w, err)
|
||||
return
|
||||
}
|
||||
out.ID, err = strconv.Atoi(r.FormValue("id"))
|
||||
if err != nil {
|
||||
c.tmpl["alert"].Execute(w, err)
|
||||
return
|
||||
}
|
||||
_ = c.tmpl["cake"].Execute(w, out)
|
||||
}
|
||||
|
||||
func (c *controller) postNewOrder(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue