User book API: use a single query with result and count
This commit is contained in:
@@ -24,8 +24,8 @@ func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (dto.BookGet, error)
|
||||
return book, res.Error
|
||||
}
|
||||
|
||||
func FetchReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGet, error) {
|
||||
var books []dto.BookUserGet
|
||||
func FetchReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGetBook, error) {
|
||||
var books []dto.BookUserGetBook
|
||||
query := fetchReadUserBookQuery(db, userId)
|
||||
query = query.Limit(limit)
|
||||
query = query.Offset(offset)
|
||||
@@ -40,8 +40,8 @@ func FetchReadUserBookCount(db *gorm.DB, userId uint) (int64, error) {
|
||||
return count, res.Error
|
||||
}
|
||||
|
||||
func FetchReadingUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGet, error) {
|
||||
var books []dto.BookUserGet
|
||||
func FetchReadingUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGetBook, error) {
|
||||
var books []dto.BookUserGetBook
|
||||
query := fetchReadingUserBookQuery(db, userId)
|
||||
query = query.Limit(limit)
|
||||
query = query.Offset(offset)
|
||||
@@ -67,8 +67,8 @@ func fetchReadingUserBookQuery(db *gorm.DB, userId uint) *gorm.DB {
|
||||
return query
|
||||
}
|
||||
|
||||
func FetchWantReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGet, error) {
|
||||
var books []dto.BookUserGet
|
||||
func FetchWantReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGetBook, error) {
|
||||
var books []dto.BookUserGetBook
|
||||
|
||||
query := fetchWantReadUserBookQuery(db, userId)
|
||||
query = query.Limit(limit)
|
||||
|
||||
Reference in New Issue
Block a user