Fix metadata editor
Convert slices to postgres arrays.
This commit is contained in:
parent
71d975c2f7
commit
2562f4c2c8
2 changed files with 15 additions and 8 deletions
15
lib/admin.go
15
lib/admin.go
|
@ -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)
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-pg/pg"
|
||||
|
||||
log "github.com/cihub/seelog"
|
||||
)
|
||||
|
||||
|
@ -132,7 +134,11 @@ func (db *pgDB) UpdateBook(id string, data map[string]interface{}) error {
|
|||
setCondition += ", "
|
||||
}
|
||||
setCondition += col + " = ?"
|
||||
params = append(params, val)
|
||||
if col == "authors" || col == "tags" {
|
||||
params = append(params, pg.Array(val))
|
||||
} else {
|
||||
params = append(params, val)
|
||||
}
|
||||
}
|
||||
_, err := db.sql.Model(&Book{}).
|
||||
Set(setCondition, params...).
|
||||
|
|
Reference in a new issue