add filter read/want read when browsing books
This commit is contained in:
@@ -56,15 +56,29 @@ type BookUserGet struct {
|
||||
CoverPath string `json:"coverPath"`
|
||||
}
|
||||
|
||||
func FetchBookUserGet(db *gorm.DB, userId uint) ([]BookUserGet, error) {
|
||||
func FetchReadUserBook(db *gorm.DB, userId uint) ([]BookUserGet, error) {
|
||||
query := fetchUserBookGet(db, userId)
|
||||
query = query.Where("user_books.read IS TRUE")
|
||||
var books []BookUserGet
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
}
|
||||
|
||||
func FetchWantReadUserBook(db *gorm.DB, userId uint) ([]BookUserGet, error) {
|
||||
query := fetchUserBookGet(db, userId)
|
||||
query = query.Where("user_books.want_read IS TRUE")
|
||||
var books []BookUserGet
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
}
|
||||
|
||||
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())
|
||||
query = query.Joins("left join books on (books.id = user_books.book_id)")
|
||||
query = query.Joins("left join static_files on (static_files.id = books.cover_id)")
|
||||
query = query.Where("user_id = ?", userId)
|
||||
res := query.Find(&books)
|
||||
return books, res.Error
|
||||
return query
|
||||
}
|
||||
|
||||
func selectStaticFilesPath() string {
|
||||
|
||||
Reference in New Issue
Block a user