Implement Note operations
Add notes.go with NoteService for task comment CRUD:
- client.Notes(checklistID, taskID) returns NoteService
- List(ctx) - get all notes on a task (GET /comments.json)
- Create(ctx, comment) - add new note (POST /comments.json)
- Update(ctx, noteID, comment) - update note text (PUT /comments/{id}.json)
- Delete(ctx, noteID) - remove note (DELETE /comments/{id}.json)
All methods support context for cancellation and timeouts.
Closes checkvist-api-5ab
This commit is contained in:
parent
3aa2a284de
commit
5f71f40077
2 changed files with 73 additions and 1 deletions
72
notes.go
72
notes.go
|
|
@ -1,3 +1,75 @@
|
|||
package checkvist
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// notes.go contains the NoteService for CRUD operations on notes (comments) attached to tasks.
|
||||
|
||||
// NoteService provides operations on notes (comments) attached to a specific task.
|
||||
type NoteService struct {
|
||||
client *Client
|
||||
checklistID int
|
||||
taskID int
|
||||
}
|
||||
|
||||
// Notes returns a NoteService for performing note operations on the specified task.
|
||||
func (c *Client) Notes(checklistID, taskID int) *NoteService {
|
||||
return &NoteService{
|
||||
client: c,
|
||||
checklistID: checklistID,
|
||||
taskID: taskID,
|
||||
}
|
||||
}
|
||||
|
||||
// List returns all notes (comments) attached to the task.
|
||||
func (s *NoteService) List(ctx context.Context) ([]Note, error) {
|
||||
path := fmt.Sprintf("/checklists/%d/tasks/%d/comments.json", s.checklistID, s.taskID)
|
||||
|
||||
var notes []Note
|
||||
if err := s.client.doGet(ctx, path, ¬es); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return notes, nil
|
||||
}
|
||||
|
||||
// createNoteRequest is the request body for creating a note.
|
||||
type createNoteRequest struct {
|
||||
Comment string `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}
|
||||
|
||||
var note Note
|
||||
if err := s.client.doPost(ctx, path, body, ¬e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ¬e, nil
|
||||
}
|
||||
|
||||
// updateNoteRequest is the request body for updating a note.
|
||||
type updateNoteRequest struct {
|
||||
Comment string `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}
|
||||
|
||||
var note Note
|
||||
if err := s.client.doPut(ctx, path, body, ¬e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ¬e, nil
|
||||
}
|
||||
|
||||
// Delete permanently deletes a note.
|
||||
func (s *NoteService) Delete(ctx context.Context, noteID int) error {
|
||||
path := fmt.Sprintf("/checklists/%d/tasks/%d/comments/%d.json", s.checklistID, s.taskID, noteID)
|
||||
return s.client.doDelete(ctx, path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue