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

Method UpdateBook

pkg/server/app/books.go:82–105  ·  view source on GitHub ↗

UpdateBook updaates the book, the usn and the user's max_usn

(tx *gorm.DB, user database.User, book database.Book, label *string)

Source from the content-addressed store, hash-verified

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) {
83 if user.ID != book.UserID {
84 return book, errors.New("Not allowed")
85 }
86
87 nextUSN, err := incrementUserUSN(tx, user.ID)
88 if err != nil {
89 return book, errors.Wrap(err, "incrementing user max_usn")
90 }
91
92 if label != nil {
93 book.Label = *label
94 }
95
96 book.USN = nextUSN
97 book.EditedOn = a.Clock.Now().UnixNano()
98 book.Deleted = false
99
100 if err := tx.Save(&book).Error; err != nil {
101 return book, errors.Wrap(err, "updating the book")
102 }
103
104 return book, nil
105}

Callers 2

updateMethod · 0.80
TestUpdateBookFunction · 0.80

Calls 3

incrementUserUSNFunction · 0.85
NewMethod · 0.80
NowMethod · 0.65

Tested by 1

TestUpdateBookFunction · 0.64