Fix metadata editor

Convert slices to postgres arrays.
This commit is contained in:
Las Zenow 2017-05-30 23:28:42 +00:00
parent 71d975c2f7
commit 2562f4c2c8
2 changed files with 15 additions and 8 deletions

View file

@ -87,6 +87,7 @@ func cleanEmptyStr(s []string) []string {
}
func saveHandler(h handler) {
// XXX: check for errors (ISBN, length(lang), ...)
id := mux.Vars(h.r)["id"]
if !h.sess.IsModerator() {
notFound(h)
@ -97,26 +98,26 @@ func saveHandler(h handler) {
publisher := h.r.FormValue("publisher")
date := h.r.FormValue("date")
description := h.r.FormValue("description")
author := cleanEmptyStr(h.r.Form["author"])
authors := cleanEmptyStr(h.r.Form["author"])
tags := cleanEmptyStr(strings.Split(h.r.FormValue("tags"), ","))
isbn := parser.ISBN(h.r.FormValue("isbn")) // XXX: check for errors
lang := cleanEmptyStr(h.r.Form["lang"])
isbn := parser.ISBN(h.r.FormValue("isbn"))
lang := h.r.FormValue("lang")
book := map[string]interface{}{"title": title,
"publisher": publisher,
"date": date,
"description": description,
"author": author,
"authors": authors,
"tags": tags,
"isbn": isbn,
"lang": lang}
err := h.db.UpdateBook(id, book)
if err != nil {
log.Error("Updating book: ", err)
notFound(h)
return
h.sess.Notify("Can't modify book!", err.Error(), "error")
} else {
h.sess.Notify("Book Modified!", "", "success")
}
h.sess.Notify("Book Modified!", "", "success")
h.sess.Save(h.w, h.r)
if h.db.IsBookActive(id) {
http.Redirect(h.w, h.r, "/book/"+id, http.StatusFound)