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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n.Status = strings.TrimSpace(r.FormValue("status"))
|
||||||
|
|
||||||
n.Paid, err = strconv.Atoi(r.FormValue("paid"))
|
n.Paid, err = strconv.Atoi(r.FormValue("paid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
|
||||||
11
index.html
11
index.html
|
|
@ -14,6 +14,7 @@
|
||||||
<th>Location</th>
|
<th>Location</th>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
<th>Accepted</th>
|
<th>Accepted</th>
|
||||||
|
<th>Status</th>
|
||||||
<th>Paid</th>
|
<th>Paid</th>
|
||||||
<th>Cakes</th>
|
<th>Cakes</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -26,14 +27,10 @@
|
||||||
<th>{{.Location}}</th>
|
<th>{{.Location}}</th>
|
||||||
<th>{{.Date.Format "2006-01-02"}}</th>
|
<th>{{.Date.Format "2006-01-02"}}</th>
|
||||||
<th>{{.Accepted.Format "2006-01-02"}}</th>
|
<th>{{.Accepted.Format "2006-01-02"}}</th>
|
||||||
|
<th>{{.Status}}</th>
|
||||||
<th>{{.Paid}}</th>
|
<th>{{.Paid}}</th>
|
||||||
<th>
|
<th>{{range .Cakes}} {{.Name}} {{.Amount}} {{end}}</th>
|
||||||
{{range .Cakes}}
|
|
||||||
{{.Name}}
|
|
||||||
{{.Amount}}
|
|
||||||
{{end}}
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</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{"Rolada makowa", -1, 80, 0})
|
||||||
h.s.saveCake(cake{"Wieniec bezowy", -1, 120, 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, "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(), 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(), 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 /order/", logger(h.form))
|
||||||
http.HandleFunc("GET /", logger(h.index))
|
http.HandleFunc("GET /", logger(h.index))
|
||||||
|
|
|
||||||
1
model.go
1
model.go
|
|
@ -17,6 +17,7 @@ type order struct {
|
||||||
Location string
|
Location string
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Accepted time.Time
|
Accepted time.Time
|
||||||
|
Status string
|
||||||
Paid int // increments of 0.01
|
Paid int // increments of 0.01
|
||||||
Cakes []cake
|
Cakes []cake
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,11 @@
|
||||||
</select>
|
</select>
|
||||||
<label>date</label>
|
<label>date</label>
|
||||||
<input type="date" name="date" value="{{.Date.Format "2006-01-02"}}">
|
<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>
|
<label>paid</label>
|
||||||
<input type="number" name="paid" min="0" value="{{.Paid}}">
|
<input type="number" name="paid" min="0" value="{{.Paid}}">
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -45,7 +50,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
<button type="submit">submit</button>
|
<button type="submit">submit</button>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
<script>
|
<script>
|
||||||
function addCake(id, name, amount){
|
function addCake(id, name, amount){
|
||||||
|
|
@ -83,4 +88,4 @@
|
||||||
{{range .Order.Cakes}}
|
{{range .Order.Cakes}}
|
||||||
addCake({{.ID}}, '{{.Name}} {{.Price}}', {{.Amount}})
|
addCake({{.ID}}, '{{.Name}} {{.Price}}', {{.Amount}})
|
||||||
{{end}}
|
{{end}}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue