Add status field to orders
This commit is contained in:
parent
d4b76f6307
commit
e55ca30d20
5 changed files with 17 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
11
index.html
11
index.html
|
|
@ -14,6 +14,7 @@
|
|||
<th>Location</th>
|
||||
<th>Date</th>
|
||||
<th>Accepted</th>
|
||||
<th>Status</th>
|
||||
<th>Paid</th>
|
||||
<th>Cakes</th>
|
||||
</tr>
|
||||
|
|
@ -26,14 +27,10 @@
|
|||
<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>
|
||||
</main>
|
||||
</main>
|
||||
|
|
|
|||
6
main.go
6
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))
|
||||
|
|
|
|||
1
model.go
1
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -45,7 +50,7 @@
|
|||
</div>
|
||||
{{end}}
|
||||
<button type="submit">submit</button>
|
||||
</form>
|
||||
</form>
|
||||
</main>
|
||||
<script>
|
||||
function addCake(id, name, amount){
|
||||
|
|
@ -83,4 +88,4 @@
|
|||
{{range .Order.Cakes}}
|
||||
addCake({{.ID}}, '{{.Name}} {{.Price}}', {{.Amount}})
|
||||
{{end}}
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue