checkvist-api/notes.go
Oliver Jakoubek 5f71f40077 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
2026-01-14 13:40:37 +01:00

75 lines
2.1 KiB
Go

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, &notes); 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, &note); err != nil {
return nil, err
}
return &note, 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, &note); err != nil {
return nil, err
}
return &note, 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)
}