diff --git a/controller.go b/controller.go
index 4c9b38d..79155e6 100644
--- a/controller.go
+++ b/controller.go
@@ -19,6 +19,7 @@ func (c *controller) LoadRouter(pub fs.FS) {
serveMux.HandleFunc("GET /available_cakes", c.cakeOptions)
serveMux.HandleFunc("GET /edit_cakes", c.cakeOptions)
serveMux.HandleFunc("GET /cake_editor", c.cakeEditor)
+ serveMux.HandleFunc("GET /cake_editor/{ID}", c.cakeEditor)
serveMux.HandleFunc("POST /new_cake", c.newCake)
c.Handler = serveMux
diff --git a/handlers.go b/handlers.go
index 452be2d..0fdb160 100644
--- a/handlers.go
+++ b/handlers.go
@@ -18,14 +18,29 @@ func (c *controller) cakeOptions(w http.ResponseWriter, r *http.Request) {
}
func (c *controller) cakeEditor(w http.ResponseWriter, r *http.Request) {
+ fmt.Println("received get request at ", r.URL.String())
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})
+ url := strings.Split(r.URL.String(), "/")
+
+ if len(url) < 3 {
+ fmt.Println("no arg")
+ c.tmpl["cake_editor"].Execute(w, cake{"", 0, 0})
+ return
+ }
+
+ id, err := strconv.Atoi(url[2])
+ if err != nil {
+ fmt.Println("can't get info")
+ c.tmpl["cake_editor"].Execute(w, cake{"", 0, 0})
+ return
+ }
+
+ c.tmpl["cake_editor"].Execute(w, cake{"Hello", id, 120})
}
func (c *controller) newCake(w http.ResponseWriter, r *http.Request) {
diff --git a/templates/cake_editor.html b/templates/cake_editor.html
index 5aaf568..c0caffa 100644
--- a/templates/cake_editor.html
+++ b/templates/cake_editor.html
@@ -9,4 +9,5 @@
+
\ No newline at end of file