DeleteBook marks a book deleted with the next usn and updates the user's max_usn
(tx *gorm.DB, user database.User, book database.Book)
| 57 | |
| 58 | // DeleteBook marks a book deleted with the next usn and updates the user's max_usn |
| 59 | func (a *App) DeleteBook(tx *gorm.DB, user database.User, book database.Book) (database.Book, error) { |
| 60 | if user.ID != book.UserID { |
| 61 | return book, errors.New("Not allowed") |
| 62 | } |
| 63 | |
| 64 | nextUSN, err := incrementUserUSN(tx, user.ID) |
| 65 | if err != nil { |
| 66 | return book, errors.Wrap(err, "incrementing user max_usn") |
| 67 | } |
| 68 | |
| 69 | if err := tx.Model(&book). |
| 70 | Updates(map[string]interface{}{ |
| 71 | "usn": nextUSN, |
| 72 | "deleted": true, |
| 73 | "label": "", |
| 74 | }).Error; err != nil { |
| 75 | return book, errors.Wrap(err, "deleting book") |
| 76 | } |
| 77 | |
| 78 | return book, nil |
| 79 | } |
| 80 | |
| 81 | // UpdateBook updaates the book, the usn and the user's max_usn |
| 82 | func (a *App) UpdateBook(tx *gorm.DB, user database.User, book database.Book, label *string) (database.Book, error) { |