add "reading" filter for books currently being read

This commit is contained in:
2025-11-24 13:58:31 +01:00
parent 8c0a9fe431
commit 46492967a3
9 changed files with 154 additions and 2 deletions

View File

@@ -97,11 +97,32 @@ func FetchReadUserBookCount(db *gorm.DB, userId uint) (int64, error) {
return count, res.Error
}
func FetchReadingUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
var books []BookUserGet
query := fetchReadingUserBookQuery(db, userId)
query = query.Limit(limit)
query = query.Offset(offset)
res := query.Find(&books)
return books, res.Error
}
func FetchReadingUserBookCount(db *gorm.DB, userId uint) (int64, error) {
query := fetchReadingUserBookQuery(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.read IS TRUE")
return query
}
func fetchReadingUserBookQuery(db *gorm.DB, userId uint) *gorm.DB {
query := fetchUserBookGet(db, userId)
query = query.Where("user_books.start_read_date IS NOT NULL")
return query
}
func FetchWantReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
var books []BookUserGet