Library/models/authors_list.go

20 lines
424 B
Go
Raw Normal View History

package models
2017-11-08 09:55:17 +00:00
// ListAuthors returns a list with all authors, filtered by an optional searchstring
func ListAuthors(searchterm string) (authors []Author, err error) {
if searchterm == "" {
err = x.Find(&authors)
} else {
err = x.
2017-11-07 15:35:10 +00:00
Where("forename LIKE ?", "%"+searchterm+"%").
Or("lastname LIKE ?", "%"+searchterm+"%").
Find(&authors)
}
if err != nil {
return []Author{}, err
}
return authors, nil
2017-11-07 15:35:10 +00:00
}