From a40b5ac534f05893a790b8a35f4149da002f059d Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Mon, 9 Apr 2018 19:00:06 +0000 Subject: [PATCH] Clean up a bit the add book to list interface --- lib/database/list.go | 7 ++++--- templates/book.html | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/database/list.go b/lib/database/list.go index 99cb1a3..5ce5630 100644 --- a/lib/database/list.go +++ b/lib/database/list.go @@ -106,25 +106,26 @@ func (db *pgDB) GetListsByBook(bookID string) ([]BookList, error) { var bookListEntries []BookListEntry err := db.sql.Model(&bookListEntries). + Column("BookList"). Where("book_id = ?", bookID). Select() if err != nil || len(bookListEntries) == 0 { return bookLists, err } - whereQuery := "id IN (" + whereQuery := `list_id IN (` listIDs := make([]interface{}, len(bookListEntries)) for i, entry := range bookListEntries { whereQuery += "?" if i < len(bookListEntries)-1 { whereQuery += ", " } - listIDs[i] = entry.ID + listIDs[i] = entry.BookList.ListID } whereQuery += ")" err = db.sql.Model(&bookLists). - Column("Books"). + Column("Books", "User"). Where(whereQuery, listIDs...). Select() return bookLists, err diff --git a/templates/book.html b/templates/book.html index 4bc77ba..b70217c 100644 --- a/templates/book.html +++ b/templates/book.html @@ -78,23 +78,33 @@ function delBook(){ {{if .Lists}}
+
+
+{{else}} +
{{end}} {{if .S.User}} -
-
+
+
Add book to a list:
+ +
+
+