Fix Notes API parameter format for Create and Update
The Checkvist API expects nested JSON parameters in the format
{"comment": {"comment": "text"}} but the code was sending flat
{"comment": "text"}, causing 400 Bad Request errors.
Changes:
- Add noteCommentWrapper struct for nested JSON format
- Update createNoteRequest and updateNoteRequest to use wrapper
- Update Create and Update methods to use nested structure
- Update tests to verify nested format
Fixes: checkvist-api-awg
This commit is contained in:
parent
9145157ba7
commit
c95825dc88
3 changed files with 17 additions and 11 deletions
14
notes.go
14
notes.go
|
|
@ -34,15 +34,21 @@ func (s *NoteService) List(ctx context.Context) ([]Note, error) {
|
|||
return notes, nil
|
||||
}
|
||||
|
||||
// noteCommentWrapper wraps the comment field for the nested JSON format
|
||||
// expected by the Checkvist API: {"comment": {"comment": "text"}}
|
||||
type noteCommentWrapper struct {
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
// createNoteRequest is the request body for creating a note.
|
||||
type createNoteRequest struct {
|
||||
Comment string `json:"comment"`
|
||||
Comment noteCommentWrapper `json:"comment"`
|
||||
}
|
||||
|
||||
// Create creates a new note (comment) on the task.
|
||||
func (s *NoteService) Create(ctx context.Context, comment string) (*Note, error) {
|
||||
path := fmt.Sprintf("/checklists/%d/tasks/%d/comments.json", s.checklistID, s.taskID)
|
||||
body := createNoteRequest{Comment: comment}
|
||||
body := createNoteRequest{Comment: noteCommentWrapper{Comment: comment}}
|
||||
|
||||
var note Note
|
||||
if err := s.client.doPost(ctx, path, body, ¬e); err != nil {
|
||||
|
|
@ -53,13 +59,13 @@ func (s *NoteService) Create(ctx context.Context, comment string) (*Note, error)
|
|||
|
||||
// updateNoteRequest is the request body for updating a note.
|
||||
type updateNoteRequest struct {
|
||||
Comment string `json:"comment"`
|
||||
Comment noteCommentWrapper `json:"comment"`
|
||||
}
|
||||
|
||||
// Update updates an existing note's comment text.
|
||||
func (s *NoteService) Update(ctx context.Context, noteID int, comment string) (*Note, error) {
|
||||
path := fmt.Sprintf("/checklists/%d/tasks/%d/comments/%d.json", s.checklistID, s.taskID, noteID)
|
||||
body := updateNoteRequest{Comment: comment}
|
||||
body := updateNoteRequest{Comment: noteCommentWrapper{Comment: comment}}
|
||||
|
||||
var note Note
|
||||
if err := s.client.doPut(ctx, path, body, ¬e); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue