Add status field to orders

This commit is contained in:
bronku 2025-03-18 22:30:16 +01:00
parent d4b76f6307
commit e55ca30d20
5 changed files with 17 additions and 12 deletions

View file

@ -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)

View file

@ -14,6 +14,7 @@
<th>Location</th>
<th>Date</th>
<th>Accepted</th>
<th>Status</th>
<th>Paid</th>
<th>Cakes</th>
</tr>
@ -26,13 +27,9 @@
<th>{{.Location}}</th>
<th>{{.Date.Format "2006-01-02"}}</th>
<th>{{.Accepted.Format "2006-01-02"}}</th>
<th>{{.Status}}</th>
<th>{{.Paid}}</th>
<th>
{{range .Cakes}}
{{.Name}}
{{.Amount}}
{{end}}
</th>
<th>{{range .Cakes}} {{.Name}} {{.Amount}} {{end}}</th>
</tr>
{{end}}
</table>

View file

@ -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))

View file

@ -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
}

View file

@ -23,6 +23,11 @@
</select>
<label>date</label>
<input type="date" name="date" value="{{.Date.Format "2006-01-02"}}">
<label>status</label>
<select name="status" id="status">
<option value="accepted">accepted</option>
<option value="done">done</option>
</select>
<label>paid</label>
<input type="number" name="paid" min="0" value="{{.Paid}}">
</div>