Clean up a bit the add book to list interface

This commit is contained in:
Las Zenow 2018-04-09 19:00:06 +00:00
parent 11195e258b
commit a40b5ac534
2 changed files with 17 additions and 6 deletions

View file

@ -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