Add cakes management page and routes
This commit is contained in:
parent
72ed1ae61b
commit
f552e87a9d
4 changed files with 36 additions and 2 deletions
|
|
@ -13,7 +13,12 @@ func (h *Server) index(r *http.Request) (any, int, error) {
|
||||||
return data, http.StatusOK, err
|
return data, http.StatusOK, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Server) getOrder(r *http.Request) (any, int, error) {
|
func (h *Server) cakes(r *http.Request) (any, int, error) {
|
||||||
|
data, err := h.s.GetCakes()
|
||||||
|
return data, http.StatusOK, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Server) order(r *http.Request) (any, int, error) {
|
||||||
type formData struct {
|
type formData struct {
|
||||||
Order store.Order
|
Order store.Order
|
||||||
Catalogue []store.Cake
|
Catalogue []store.Cake
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,10 @@ func (h *Server) Close() {
|
||||||
func (h *Server) loadHandler() {
|
func (h *Server) loadHandler() {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
mux.HandleFunc("GET /order/", h.render(h.getOrder, "order.html"))
|
mux.HandleFunc("GET /order/", h.render(h.order, "order.html"))
|
||||||
mux.HandleFunc("GET /", h.render(h.index, "index.html"))
|
mux.HandleFunc("GET /", h.render(h.index, "index.html"))
|
||||||
mux.HandleFunc("POST /order/", h.render(h.postOrder, "confirmation.html"))
|
mux.HandleFunc("POST /order/", h.render(h.postOrder, "confirmation.html"))
|
||||||
|
mux.HandleFunc("GET /cakes", h.render(h.cakes, "cakes.html"))
|
||||||
|
|
||||||
h.Handler = mux
|
h.Handler = mux
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
internal/server/templates/cakes.html
Normal file
27
internal/server/templates/cakes.html
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
<header>
|
||||||
|
<h1>Kill me please</h1>
|
||||||
|
</header>
|
||||||
|
<nav>
|
||||||
|
<a href="order">New</a>
|
||||||
|
<a href="cakes">Manage Cakes</a>
|
||||||
|
</nav>
|
||||||
|
<main>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Price</th>
|
||||||
|
<th>Category</th>
|
||||||
|
<th>Availability</th>
|
||||||
|
</tr>
|
||||||
|
{{range .}}
|
||||||
|
<tr>
|
||||||
|
<th><a href="/cake/{{.ID}}">edit</a></th>
|
||||||
|
<th>{{.Name}}</th>
|
||||||
|
<th>{{.Price}}</th>
|
||||||
|
<th>{{.Category}}</th>
|
||||||
|
<th>{{.Availability}}</th>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</table>
|
||||||
|
</main>
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
</header>
|
</header>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="order">New</a>
|
<a href="order">New</a>
|
||||||
|
<a href="cakes">Manage Cakes</a>
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
<table>
|
<table>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue