diff --git a/README.md b/README.md index 4cae5db..b8bbb56 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,10 @@ - [x] option to add additional cakes - [x] saving orders on server - [ ] displaying orders -- [ ] move id to cake struct +- [x] move id to cake struct - [ ] refresh the list on submission - [ ] peristent storage +- [ ] rudimentary css ## ux design ### adding an order: 1. user selects the _add order_ button diff --git a/controller.go b/controller.go index e5094a8..fb124e9 100644 --- a/controller.go +++ b/controller.go @@ -9,6 +9,7 @@ import ( type Cake struct { Name string Price int + ID int } type controller struct { diff --git a/handlers.go b/handlers.go index 3e063cd..ae4febd 100644 --- a/handlers.go +++ b/handlers.go @@ -14,31 +14,25 @@ func (c *controller) cakeOptions(w http.ResponseWriter, r *http.Request) { } func (c *controller) cakeEditor(w http.ResponseWriter, r *http.Request) { - type contents struct { - ID int - Cake Cake - } - url := strings.Split(r.URL.String(), "/") if len(url) < 3 { - c.tmpl["cake_editor"].Execute(w, contents{-1, Cake{"", 0}}) + c.tmpl["cake_editor"].Execute(w, Cake{"", 0, -1}) return } id, err := strconv.Atoi(url[2]) if err != nil { - c.tmpl["cake_editor"].Execute(w, contents{0, Cake{"", 0}}) + c.tmpl["cake_editor"].Execute(w, Cake{"", 0, -1}) return } cake, exists := c.cakes[id] if !exists { - c.tmpl["cake_editor"].Execute(w, contents{0, Cake{"", 0}}) + c.tmpl["cake_editor"].Execute(w, Cake{"", 0, -1}) return } - out := contents{id, cake} - c.tmpl["cake_editor"].Execute(w, out) + c.tmpl["cake_editor"].Execute(w, cake) } func (c *controller) newCake(w http.ResponseWriter, r *http.Request) { @@ -48,14 +42,9 @@ func (c *controller) newCake(w http.ResponseWriter, r *http.Request) { return } - type contents struct { - ID int - Cake Cake - } - - var in contents - in.Cake.Name = r.FormValue("name") - in.Cake.Price, err = strconv.Atoi(r.FormValue("price")) + var in Cake + in.Name = r.FormValue("name") + in.Price, err = strconv.Atoi(r.FormValue("price")) if err != nil { c.tmpl["alert"].Execute(w, err) return @@ -70,7 +59,7 @@ func (c *controller) newCake(w http.ResponseWriter, r *http.Request) { in.ID = len(c.cakes) } - c.cakes[in.ID] = in.Cake + c.cakes[in.ID] = in _ = c.tmpl["cake"].Execute(w, in) } diff --git a/main.go b/main.go index 0205ac3..c8737ac 100644 --- a/main.go +++ b/main.go @@ -20,9 +20,9 @@ func main() { c.tmpl = LoadTemplates(templates) c.LoadRouter(public) c.cakes = make(map[int]Cake) - c.cakes[0] = Cake{"Sernik", 120} - c.cakes[1] = Cake{"Malinowa chmórka", 120} - c.cakes[2] = Cake{"Beza Pavlova", 8} + c.cakes[0] = Cake{"Sernik", 120, 0} + c.cakes[1] = Cake{"Malinowa chmórka", 120, 1} + c.cakes[2] = Cake{"Beza Pavlova", 8, 2} err := http.ListenAndServe(":8080", c) if err != nil { diff --git a/templates/available_cakes.html b/templates/available_cakes.html index f554067..cf4ea06 100644 --- a/templates/available_cakes.html +++ b/templates/available_cakes.html @@ -3,7 +3,7 @@
{{range $key, $value := .}} - {{end}}
diff --git a/templates/cake.html b/templates/cake.html index b9ca526..5ae36be 100644 --- a/templates/cake.html +++ b/templates/cake.html @@ -1,8 +1,8 @@
\ No newline at end of file diff --git a/templates/cake_editor.html b/templates/cake_editor.html index 8860192..c0caffa 100644 --- a/templates/cake_editor.html +++ b/templates/cake_editor.html @@ -1,11 +1,11 @@
- +
- +
diff --git a/templates/edit_cakes.html b/templates/edit_cakes.html index 8ace6a7..39a69b4 100644 --- a/templates/edit_cakes.html +++ b/templates/edit_cakes.html @@ -4,7 +4,7 @@
{{range $key, $value := .}} - {{end}}