Skip to content

Commit

Permalink
Don't reuse the bytes.Buffer instance in ProductEditAPI. This makes
Browse files Browse the repository at this point in the history
floats actually work.
  • Loading branch information
caoimhechaos committed Jan 3, 2014
1 parent 5a05ee3 commit 770ee81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 5 additions & 6 deletions productedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (self *ProductViewAPI) ServeHTTP(w http.ResponseWriter, req *http.Request)
}

func (self *ProductEditAPI) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var buf *bytes.Buffer = bytes.NewBuffer([]byte{})
var buf *bytes.Buffer = new(bytes.Buffer)
var specid string = req.PostFormValue("id")
var uuid UUID
var codes *Barcodes = new(Barcodes)
Expand Down Expand Up @@ -252,8 +252,7 @@ func (self *ProductEditAPI) ServeHTTP(w http.ResponseWriter, req *http.Request)
return
}

prod.Stock, err = strconv.ParseUint(req.PostFormValue("stock"),
10, 64)
prod.Stock, err = strconv.ParseUint(req.PostFormValue("stock"), 10, 64)
if err != nil {
log.Print("Parsing stock: ", err)
http.Error(w, "stock: "+err.Error(), http.StatusNotAcceptable)
Expand Down Expand Up @@ -292,7 +291,7 @@ func (self *ProductEditAPI) ServeHTTP(w http.ResponseWriter, req *http.Request)
mutation.ColumnOrSupercolumn.Column = col
mutations = append(mutations, mutation)

err = binary.Write(buf, binary.BigEndian, &prod.Price)
err = binary.Write(buf, binary.BigEndian, prod.Price)
col = cassandra.NewColumn()
col.Name = []byte("price")
col.Value = buf.Bytes()
Expand All @@ -301,9 +300,9 @@ func (self *ProductEditAPI) ServeHTTP(w http.ResponseWriter, req *http.Request)
mutation.ColumnOrSupercolumn = cassandra.NewColumnOrSuperColumn()
mutation.ColumnOrSupercolumn.Column = col
mutations = append(mutations, mutation)
buf.Reset()

err = binary.Write(buf, binary.BigEndian, &prod.Stock)
buf = new(bytes.Buffer)
err = binary.Write(buf, binary.BigEndian, prod.Stock)
col = cassandra.NewColumn()
col.Name = []byte("stock")
col.Value = buf.Bytes()
Expand Down
8 changes: 5 additions & 3 deletions templates/search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,18 @@
label.removeChild(label.firstChild);

label.appendChild(document.createTextNode(
"Edit product " + name));
"Edit product " + response.responseJSON["Name"]));

$('#edit-id')[0].value = id;
$('#edit-prodname')[0].value = response.responseJSON["Name"];
$('#edit-count')[0].value = response.responseJSON["Stock"];
$('#edit-price')[0].value = response.responseJSON["Price"];

// TODO(caoimhe): Do something with the barcodes.
barcodes = response.responseJSON["Barcodes"].join("\r\n");
$('#edit-barcode')[0].value = barcodes;
if (response.responseJSON["Barcodes"] != null) {
barcodes = response.responseJSON["Barcodes"].join("\r\n");
$('#edit-barcode')[0].value = barcodes;
}
$('#editItem').modal('show');
}
});
Expand Down

0 comments on commit 770ee81

Please sign in to comment.