CreateBook creates a new book in the server
(ctx context.DnoteCtx, label string)
| 321 | |
| 322 | // CreateBook creates a new book in the server |
| 323 | func CreateBook(ctx context.DnoteCtx, label string) (CreateBookResp, error) { |
| 324 | payload := CreateBookPayload{ |
| 325 | Name: label, |
| 326 | } |
| 327 | b, err := json.Marshal(payload) |
| 328 | if err != nil { |
| 329 | return CreateBookResp{}, errors.Wrap(err, "marshaling payload") |
| 330 | } |
| 331 | |
| 332 | res, err := doAuthorizedReq(ctx, "POST", "/v3/books", string(b), nil) |
| 333 | if err != nil { |
| 334 | return CreateBookResp{}, errors.Wrap(err, "posting a book to the server") |
| 335 | } |
| 336 | |
| 337 | var resp CreateBookResp |
| 338 | if err := json.NewDecoder(res.Body).Decode(&resp); err != nil { |
| 339 | return resp, errors.Wrap(err, "decoding response payload") |
| 340 | } |
| 341 | |
| 342 | return resp, nil |
| 343 | } |
| 344 | |
| 345 | type updateBookPayload struct { |
| 346 | Name *string `json:"name"` |
no test coverage detected