diff --git a/db/db.go b/db/db.go index 12036bd..67ea415 100644 --- a/db/db.go +++ b/db/db.go @@ -31,3 +31,8 @@ func DbSelect(table, columns string) *sql.Rows { rows, _ := Database.Query("SELECT "+ columns +" FROM "+ table) return rows } + +func DbUpdate(table, column, columnValue, conditionValue string) { + statement, _ := Database.Prepare("UPDATE "+ table + " SET " + column + " = "+ columnValue + " WHERE id = " + conditionValue) + statement.Exec() +} diff --git a/views/views.go b/views/views.go index 6274a6a..28ca65a 100644 --- a/views/views.go +++ b/views/views.go @@ -101,9 +101,11 @@ func PaymentDoneView(p Page, w http.ResponseWriter, r *http.Request) { DbInsert("Purchasement", "priceTotal, firstName, lastName, paymentMethod, deliveryDate", "'" +strconv.Itoa(purchasement.PriceTotal) +"','"+ purchasement.FirstName + "','" + purchasement.LastName + "','" + strconv.Itoa(purchasement.PaymentMethod) + "','" + purchasement.DeliveryDate +"'") for i:= range purchasement.Products { DbInsert("PurchasementProduct", "purchasementId, productId, quantity, priceTotal", "'" +strconv.Itoa(LastPurchasementId) + "','" + strconv.Itoa(purchasement.Products[i].Product.Id) + "','" + strconv.Itoa(purchasement.Products[i].Quantity) + "','" + strconv.Itoa(purchasement.Products[i].PriceTotal) + "'") + DbUpdate("Product", "quantity", strconv.Itoa(purchasement.Products[i].Product.Quantity), strconv.Itoa(purchasement.Products[i].Product.Id)) } ShoppingCart.Products = nil ShoppingCart.Calculate() + } http.Redirect(w, r, "/purchasements", http.StatusSeeOther) }