stub handler for category add
This commit is contained in:
parent
3a18696bdf
commit
a860c3ad70
|
@ -290,6 +290,27 @@ func categoryChangeParentHandler(w http.ResponseWriter, r *http.Request, user *u
|
|||
http.Redirect(w, r, "/categories", http.StatusFound)
|
||||
}
|
||||
|
||||
func categoryAddHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||
session, _ := store.Get(r, "c_user")
|
||||
|
||||
name := categoryFromReqArg(r.FormValue("name"))
|
||||
parent := categoryFromReqArg(r.FormValue("parent"))
|
||||
|
||||
if name == nil {
|
||||
session.AddFlash("Invalid category name", flash_err)
|
||||
} else {
|
||||
err := category.Add(db, name, parent)
|
||||
if err != nil {
|
||||
session.AddFlash("Error commiting to Database", flash_err)
|
||||
} else {
|
||||
session.AddFlash("Added category", flash_info)
|
||||
}
|
||||
}
|
||||
|
||||
session.Save(r, w)
|
||||
http.Redirect(w, r, "/categories", http.StatusFound)
|
||||
}
|
||||
|
||||
func ServeFileHandler(res http.ResponseWriter, req *http.Request) {
|
||||
fname := path.Base(req.URL.Path)
|
||||
http.ServeFile(res, req, "./"+fname)
|
||||
|
@ -313,6 +334,7 @@ func init_route_handlers() {
|
|||
|
||||
r.HandleFunc("/categories", getPostHandler(userHandler(categoriesFormHandler), userHandler(categoriesPostHandler)))
|
||||
r.HandleFunc("/categories/change-parent", userHandler(categoryChangeParentHandler))
|
||||
r.HandleFunc("/categories/add", userHandler(categoryAddHandler))
|
||||
|
||||
http.Handle("/", r)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue