From e55ca30d20bcce54f4efd9aa24b28b9f9bbddd15 Mon Sep 17 00:00:00 2001 From: bronku Date: Tue, 18 Mar 2025 22:30:16 +0100 Subject: [PATCH] Add status field to orders --- handler.go | 2 ++ index.html | 11 ++++------- main.go | 6 +++--- model.go | 1 + order.html | 9 +++++++-- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/handler.go b/handler.go index 60660cc..1f31884 100644 --- a/handler.go +++ b/handler.go @@ -73,6 +73,8 @@ func (h *handler) addOrder(w http.ResponseWriter, r *http.Request) { return } + n.Status = strings.TrimSpace(r.FormValue("status")) + n.Paid, err = strconv.Atoi(r.FormValue("paid")) if err != nil { w.WriteHeader(http.StatusBadRequest) diff --git a/index.html b/index.html index d47cabb..4170952 100644 --- a/index.html +++ b/index.html @@ -14,6 +14,7 @@ Location Date Accepted + Status Paid Cakes @@ -26,14 +27,10 @@ {{.Location}} {{.Date.Format "2006-01-02"}} {{.Accepted.Format "2006-01-02"}} + {{.Status}} {{.Paid}} - - {{range .Cakes}} - {{.Name}} - {{.Amount}} - {{end}} - + {{range .Cakes}} {{.Name}} {{.Amount}} {{end}} {{end}} - \ No newline at end of file + diff --git a/main.go b/main.go index 3aebaf2..eb8f37b 100644 --- a/main.go +++ b/main.go @@ -24,9 +24,9 @@ func main() { h.s.saveCake(cake{"Rolada makowa", -1, 80, 0}) h.s.saveCake(cake{"Wieniec bezowy", -1, 120, 0}) - h.s.saveOrder(order{-1, "Albert", "Camus", "123456789", "Kartuzy", time.Now().AddDate(0, 0, 7), time.Now(), 0, nil}) - h.s.saveOrder(order{-1, "George", "Orwell", "", "Kartuzy", time.Now().AddDate(0, 1, 0), time.Now(), 0, nil}) - h.s.saveOrder(order{-1, "Karl", "Marx", "0700", "Somonino", time.Now(), time.Now(), 0, nil}) + h.s.saveOrder(order{-1, "Albert", "Camus", "123456789", "Kartuzy", time.Now().AddDate(0, 0, 7), time.Now(), "accepted", 0, nil}) + h.s.saveOrder(order{-1, "George", "Orwell", "", "Kartuzy", time.Now().AddDate(0, 1, 0), time.Now(), "accepted", 0, nil}) + h.s.saveOrder(order{-1, "Karl", "Marx", "0700", "Somonino", time.Now(), time.Now(), "accepted", 0, nil}) http.HandleFunc("GET /order/", logger(h.form)) http.HandleFunc("GET /", logger(h.index)) diff --git a/model.go b/model.go index 92d911c..b0c038d 100644 --- a/model.go +++ b/model.go @@ -17,6 +17,7 @@ type order struct { Location string Date time.Time Accepted time.Time + Status string Paid int // increments of 0.01 Cakes []cake } diff --git a/order.html b/order.html index f3907f5..b41cacf 100644 --- a/order.html +++ b/order.html @@ -23,6 +23,11 @@ + + @@ -45,7 +50,7 @@ {{end}} - + \ No newline at end of file +