Add pagination for "my books" display
This commit is contained in:
@@ -56,22 +56,51 @@ type BookUserGet struct {
|
||||
CoverPath string `json:"coverPath"`
|
||||
}
|
||||
|
||||
func FetchReadUserBook(db *gorm.DB, userId uint) ([]BookUserGet, error) {
|
||||
query := fetchUserBookGet(db, userId)
|
||||
query = query.Where("user_books.read IS TRUE")
|
||||
func FetchReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
|
||||
var books []BookUserGet
|
||||
query := fetchReadUserBookQuery(db, userId)
|
||||
query = query.Limit(limit)
|
||||
query = query.Offset(offset)
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
}
|
||||
|
||||
func FetchWantReadUserBook(db *gorm.DB, userId uint) ([]BookUserGet, error) {
|
||||
func FetchReadUserBookCount(db *gorm.DB, userId uint) (int64, error) {
|
||||
query := fetchReadUserBookQuery(db, userId)
|
||||
var count int64
|
||||
res := query.Count(&count)
|
||||
return count, res.Error
|
||||
}
|
||||
|
||||
func fetchReadUserBookQuery(db *gorm.DB, userId uint) *gorm.DB {
|
||||
query := fetchUserBookGet(db, userId)
|
||||
query = query.Where("user_books.want_read IS TRUE")
|
||||
query = query.Where("user_books.read IS TRUE")
|
||||
return query
|
||||
}
|
||||
|
||||
func FetchWantReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
|
||||
var books []BookUserGet
|
||||
|
||||
query := fetchWantReadUserBookQuery(db, userId)
|
||||
query = query.Limit(limit)
|
||||
query = query.Offset(offset)
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
}
|
||||
|
||||
func FetchWantReadUserBookCount(db *gorm.DB, userId uint) (int64, error) {
|
||||
query := fetchWantReadUserBookQuery(db, userId)
|
||||
var count int64
|
||||
res := query.Count(&count)
|
||||
return count, res.Error
|
||||
}
|
||||
|
||||
func fetchWantReadUserBookQuery(db *gorm.DB, userId uint) *gorm.DB {
|
||||
query := fetchUserBookGet(db, userId)
|
||||
query = query.Where("user_books.want_read IS TRUE")
|
||||
return query
|
||||
}
|
||||
|
||||
func fetchUserBookGet(db *gorm.DB, userId uint) *gorm.DB {
|
||||
query := db.Model(&model.UserBook{})
|
||||
query = query.Select("books.id, books.title, books.author, user_books.rating, user_books.read, user_books.want_read, " + selectStaticFilesPath())
|
||||
|
||||
Reference in New Issue
Block a user