Add pagination for booksearch
This commit is contained in:
@@ -36,14 +36,28 @@ type BookSearchGet struct {
|
||||
CoverPath string `json:"coverPath"`
|
||||
}
|
||||
|
||||
func FetchBookSearchGet(db *gorm.DB, searchterm string) ([]BookSearchGet, error) {
|
||||
func FetchBookSearchGet(db *gorm.DB, searchterm string, limit int, offset int) ([]BookSearchGet, error) {
|
||||
var books []BookSearchGet
|
||||
query := fetchBookSearchQuery(db, searchterm)
|
||||
query = query.Limit(limit)
|
||||
query = query.Offset(offset)
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
}
|
||||
|
||||
func FetchBookSearchGetCount(db *gorm.DB, searchterm string) (int64, error) {
|
||||
query := fetchBookSearchQuery(db, searchterm)
|
||||
var count int64
|
||||
res := query.Count(&count)
|
||||
return count, res.Error
|
||||
}
|
||||
|
||||
func fetchBookSearchQuery(db *gorm.DB, searchterm string) *gorm.DB {
|
||||
query := db.Model(&model.Book{})
|
||||
query = query.Select("books.title, books.author, books.id," + selectStaticFilesPath())
|
||||
query = query.Joins("left join static_files on (static_files.id = books.cover_id)")
|
||||
query = query.Where("LOWER(title) LIKE ?", "%"+strings.ToLower(searchterm)+"%")
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
return query
|
||||
}
|
||||
|
||||
type BookUserGet struct {
|
||||
|
||||
Reference in New Issue
Block a user