Make "want read" button work
This commit is contained in:
@@ -14,13 +14,14 @@ type BookGet struct {
|
||||
Summary string `json:"summary"`
|
||||
Rating int `json:"rating"`
|
||||
Read bool `json:"read"`
|
||||
WantRead bool `json:"wantread"`
|
||||
CoverPath string `json:"coverPath"`
|
||||
}
|
||||
|
||||
func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (BookGet, error) {
|
||||
var book BookGet
|
||||
query := db.Model(&model.Book{})
|
||||
query = query.Select("books.title, books.author, books.summary, user_books.rating, user_books.read, " + selectStaticFilesPath())
|
||||
query = query.Select("books.title, books.author, books.summary, user_books.rating, user_books.read, user_books.want_read, " + selectStaticFilesPath())
|
||||
query = query.Joins("left join user_books on (user_books.book_id = books.id and user_books.user_id = ?)", userId)
|
||||
query = query.Joins("left join static_files on (static_files.id = books.cover_id)")
|
||||
query = query.Where("books.id = ?", bookId)
|
||||
@@ -51,13 +52,14 @@ type BookUserGet struct {
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
Rating int `json:"rating" binding:"min=0,max=10"`
|
||||
Read bool `json:"read" binding:"boolean"`
|
||||
WantRead bool `json:"wantread" binding:"boolean"`
|
||||
CoverPath string `json:"coverPath"`
|
||||
}
|
||||
|
||||
func FetchBookUserGet(db *gorm.DB, userId uint) ([]BookUserGet, error) {
|
||||
var books []BookUserGet
|
||||
query := db.Model(&model.UserBook{})
|
||||
query = query.Select("books.id, books.title, books.author, user_books.rating, user_books.read," + selectStaticFilesPath())
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user