UpdateBook updates a book in the server
(ctx context.DnoteCtx, label, uuid string)
| 353 | |
| 354 | // UpdateBook updates a book in the server |
| 355 | func UpdateBook(ctx context.DnoteCtx, label, uuid string) (UpdateBookResp, error) { |
| 356 | payload := updateBookPayload{ |
| 357 | Name: &label, |
| 358 | } |
| 359 | b, err := json.Marshal(payload) |
| 360 | if err != nil { |
| 361 | return UpdateBookResp{}, errors.Wrap(err, "marshaling payload") |
| 362 | } |
| 363 | |
| 364 | endpoint := fmt.Sprintf("/v3/books/%s", uuid) |
| 365 | res, err := doAuthorizedReq(ctx, "PATCH", endpoint, string(b), nil) |
| 366 | if err != nil { |
| 367 | return UpdateBookResp{}, errors.Wrap(err, "posting a book to the server") |
| 368 | } |
| 369 | |
| 370 | var resp UpdateBookResp |
| 371 | if err := json.NewDecoder(res.Body).Decode(&resp); err != nil { |
| 372 | return resp, errors.Wrap(err, "decoding payload") |
| 373 | } |
| 374 | |
| 375 | return resp, nil |
| 376 | } |
| 377 | |
| 378 | // DeleteBookResp is the response from create book api |
| 379 | type DeleteBookResp struct { |
no test coverage detected