diff --git a/controller/controller.go b/controller/controller.go index 58f862e..9eedb2c 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -1,7 +1,6 @@ package controller import ( - "fmt" "html/template" "io/fs" "net/http" @@ -15,32 +14,16 @@ type Controller struct { // #todo: load all automatically func (c *Controller) LoadTemplates(fs fs.FS) { c.tmpl = make(map[string]*template.Template) - c.tmpl["order/confirmation.html"], _ = template.ParseFS(fs, "templates/order/confirmation.html") - c.tmpl["new_order.html"], _ = template.ParseFS(fs, "templates/new_order.html") + c.tmpl["order/post_new"], _ = template.ParseFS(fs, "templates/order/post_new.html") + c.tmpl["order/get_new"], _ = template.ParseFS(fs, "templates/order/get_new.html") } func (c *Controller) LoadRouter(pub fs.FS) { serveMux := http.NewServeMux() serveMux.Handle("GET /", http.FileServerFS(unwrap(fs.Sub(pub, "public")))) - serveMux.HandleFunc("POST /", c.HandlePost) - serveMux.HandleFunc("GET /new_order.html", c.HandleGet) + serveMux.HandleFunc("POST /order/new", c.postNewOrder) + serveMux.HandleFunc("GET /order/new", c.getNewOrder) c.Handler = serveMux } - -func (c *Controller) HandlePost(w http.ResponseWriter, r *http.Request) { - fmt.Println("received Post request: ", r) - err := r.ParseForm() - if err != nil { - _ = c.tmpl["order/confirmation.html"].Execute(w, struct{ Status any }{Status: err}) - } - w.WriteHeader(http.StatusAccepted) - fmt.Println(r.Form) - _ = c.tmpl["order/confirmation.html"].Execute(w, struct{ Status any }{Status: r.Form}) -} - -func (c *Controller) HandleGet(w http.ResponseWriter, r *http.Request) { - fmt.Println("received Get request: ", r) - _ = c.tmpl["new_order.html"].Execute(w, nil) -} diff --git a/controller/new_order.go b/controller/new_order.go new file mode 100644 index 0000000..06b3bce --- /dev/null +++ b/controller/new_order.go @@ -0,0 +1,22 @@ +package controller + +import ( + "fmt" + "net/http" +) + +func (c *Controller) postNewOrder(w http.ResponseWriter, r *http.Request) { + fmt.Println("received Post request: ", r) + err := r.ParseForm() + if err != nil { + _ = c.tmpl["order/post_new"].Execute(w, struct{ Status any }{Status: err}) + } + w.WriteHeader(http.StatusAccepted) + fmt.Println(r.Form) + _ = c.tmpl["order/post_new"].Execute(w, struct{ Status any }{Status: r.Form}) +} + +func (c *Controller) getNewOrder(w http.ResponseWriter, r *http.Request) { + fmt.Println("received Get request: ", r) + _ = c.tmpl["order/get_new"].Execute(w, nil) +} diff --git a/public/index.html b/public/index.html index 715e825..683e99c 100644 --- a/public/index.html +++ b/public/index.html @@ -1,5 +1,6 @@ +