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

Method update

pkg/server/controllers/books.go:186–222  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

184}
185
186func (b *Books) update(r *http.Request) (database.Book, error) {
187 user := context.User(r.Context())
188 if user == nil {
189 return database.Book{}, app.ErrLoginRequired
190 }
191
192 vars := mux.Vars(r)
193 uuid := vars["bookUUID"]
194
195 if !helpers.ValidateUUID(uuid) {
196 return database.Book{}, app.ErrInvalidUUID
197 }
198
199 tx := b.app.DB.Begin()
200
201 var book database.Book
202 if err := tx.Where("user_id = ? AND uuid = ?", user.ID, uuid).First(&book).Error; err != nil {
203 tx.Rollback()
204 return database.Book{}, pkgErrors.Wrap(err, "finding book")
205 }
206
207 var params updateBookPayload
208 if err := parseRequestData(r, &params); err != nil {
209 tx.Rollback()
210 return database.Book{}, pkgErrors.Wrap(err, "decoding payload")
211 }
212
213 book, err := b.app.UpdateBook(tx, *user, book, params.Name)
214 if err != nil {
215 tx.Rollback()
216 return database.Book{}, pkgErrors.Wrap(err, "updating a book")
217 }
218
219 tx.Commit()
220
221 return book, nil
222}
223
224// V3Update updates a book
225func (b *Books) V3Update(w http.ResponseWriter, r *http.Request) {

Callers 1

V3UpdateMethod · 0.95

Calls 7

UserFunction · 0.92
ValidateUUIDFunction · 0.92
parseRequestDataFunction · 0.85
UpdateBookMethod · 0.80
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected