MCPcopy Index your code
hub / github.com/dnote/dnote / DeleteBook

Method DeleteBook

pkg/server/app/books.go:59–79  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

57
58// DeleteBook marks a book deleted with the next usn and updates the user's max_usn
59func (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
82func (a *App) UpdateBook(tx *gorm.DB, user database.User, book database.Book, label *string) (database.Book, error) {

Callers 2

delMethod · 0.80
TestDeleteBookFunction · 0.80

Calls 2

incrementUserUSNFunction · 0.85
NewMethod · 0.80

Tested by 1

TestDeleteBookFunction · 0.64