Add works
This commit is contained in:
parent
35406174a2
commit
2fa54d6954
|
@ -51,9 +51,9 @@ func LoadCategories(db *sql.DB) {
|
||||||
func Add(db *sql.DB, name string, parent int) error {
|
func Add(db *sql.DB, name string, parent int) error {
|
||||||
var err error
|
var err error
|
||||||
if parent < 0 {
|
if parent < 0 {
|
||||||
err := db.Exec("INSERT INTO categories (name) VALUE ($1)", name)
|
_, err = db.Exec("INSERT INTO categories (name) VALUES ($1)", name)
|
||||||
} else {
|
} else {
|
||||||
err := db.Exec("INSERT INTO categories (name, parent_id) VALUE ($1, $2)", name, parent)
|
_, err = db.Exec("INSERT INTO categories (name, parent_id) VALUES ($1, $2)", name, parent)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Categories DB Error Add(): " , err)
|
fmt.Println("Categories DB Error Add(): " , err)
|
||||||
|
|
|
@ -293,13 +293,16 @@ func categoryChangeParentHandler(w http.ResponseWriter, r *http.Request, user *u
|
||||||
func categoryAddHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func categoryAddHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
session, _ := store.Get(r, "c_user")
|
session, _ := store.Get(r, "c_user")
|
||||||
|
|
||||||
name := categoryFromReqArg(r.FormValue("name"))
|
name := r.FormValue("name")
|
||||||
parent := categoryFromReqArg(r.FormValue("parent"))
|
parent, perr := strconv.Atoi(r.FormValue("parent"))
|
||||||
|
|
||||||
if name == nil {
|
if perr != nil {
|
||||||
|
parent = -1
|
||||||
|
}
|
||||||
|
if name == "" {
|
||||||
session.AddFlash("Invalid category name", flash_err)
|
session.AddFlash("Invalid category name", flash_err)
|
||||||
} else {
|
} else {
|
||||||
err := category.Add(db, name, parent)
|
err := categories.Add(db, name, parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
session.AddFlash("Error commiting to Database", flash_err)
|
session.AddFlash("Error commiting to Database", flash_err)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue