Use array_agg to get the taxes for the product’s form
This commit is contained in:
parent
4db0a8fb5a
commit
4463c7ee0b
|
@ -40,21 +40,10 @@ func GetProductForm(w http.ResponseWriter, r *http.Request, params httprouter.Pa
|
|||
mustRenderNewProductForm(w, r, form)
|
||||
return
|
||||
}
|
||||
var productId int
|
||||
if notFoundErrorOrPanic(conn.QueryRow(r.Context(), "select product_id, product.name, product.description, to_price(price, decimal_digits) from product join company using (company_id) join currency using (currency_code) where product.slug = $1", slug).Scan(&productId, form.Name, form.Description, form.Price)) {
|
||||
if notFoundErrorOrPanic(conn.QueryRow(r.Context(), "select product.name, product.description, to_price(price, decimal_digits), array_agg(tax_id) from product join product_tax using (product_id) join company using (company_id) join currency using (currency_code) where product.slug = $1 group by product_id, product.name, product.description, price, decimal_digits", slug).Scan(form.Name, form.Description, form.Price, form.Tax)) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
rows, err := conn.Query(r.Context(), "select tax_id from product_tax where product_id = $1", productId)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
if err := rows.Scan(form.Tax); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
mustRenderEditProductForm(w, r, form)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue