Clean up a bit the add book to list interface
This commit is contained in:
parent
11195e258b
commit
a40b5ac534
2 changed files with 17 additions and 6 deletions
|
@ -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
|
||||
|
|
Reference in a new issue