Implement Checklist operations
Add checklists.go with ChecklistService for CRUD operations:
- client.Checklists() returns ChecklistService
- List(ctx) - get all checklists (GET /checklists.json)
- ListWithOptions(ctx, opts) - with archived filter support
- Get(ctx, id) - get single checklist (GET /checklists/{id}.json)
- Create(ctx, name) - create new checklist (POST /checklists.json)
- Update(ctx, id, name) - update checklist name (PUT /checklists/{id}.json)
- Delete(ctx, id) - delete checklist (DELETE /checklists/{id}.json)
All methods support context for cancellation and timeouts.
Closes checkvist-api-c2k
This commit is contained in:
parent
3bb006e33d
commit
e5ee947fa4
2 changed files with 91 additions and 1 deletions
|
|
@ -14,7 +14,7 @@
|
|||
{"id":"checkvist-api-93m","title":"Create CHANGELOG","description":"Create CHANGELOG.md following Keep a Changelog format:\n- [Unreleased] section for ongoing work\n- Initial release preparation notes\n- Document all features implemented","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:39.009748936+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:37:00.644317886+01:00","closed_at":"2026-01-14T13:37:00.644317886+01:00","close_reason":"Closed"}
|
||||
{"id":"checkvist-api-bbx","title":"Write unit tests for Notes","description":"Create notes_test.go with tests:\n- TestNotes_List\n- TestNotes_Create\n- TestNotes_Update\n- TestNotes_Delete\nUse table-driven tests. Create testdata/notes/ fixtures.","status":"open","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:37.829382141+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T12:31:37.829382141+01:00","dependencies":[{"issue_id":"checkvist-api-bbx","depends_on_id":"checkvist-api-5ab","type":"blocks","created_at":"2026-01-14T12:33:14.119755191+01:00","created_by":"Oliver Jakoubek"}]}
|
||||
{"id":"checkvist-api-br3","title":"Core API Operations","description":"Phase 2: Implement CRUD operations for Checklists, Tasks, and Notes. All P0 (must-have) features for the library.","status":"open","priority":0,"issue_type":"epic","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:30:53.20627925+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T12:30:53.20627925+01:00"}
|
||||
{"id":"checkvist-api-c2k","title":"Implement Checklist operations","description":"Create checklists.go with ChecklistService:\n- client.Checklists() returns ChecklistService\n- List(ctx) ([]Checklist, error) - GET /checklists.json\n- Get(ctx, id) (*Checklist, error) - GET /checklists/{id}.json\n- Create(ctx, name) (*Checklist, error) - POST /checklists.json\n- Update(ctx, id, name) (*Checklist, error) - PUT /checklists/{id}.json\n- Delete(ctx, id) error - DELETE /checklists/{id}.json\n- Support archived filter in List\nContext support for all methods.","status":"open","priority":0,"issue_type":"feature","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:30:53.566197933+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T12:30:53.566197933+01:00","dependencies":[{"issue_id":"checkvist-api-c2k","depends_on_id":"checkvist-api-8u6","type":"blocks","created_at":"2026-01-14T12:32:54.533462004+01:00","created_by":"Oliver Jakoubek"},{"issue_id":"checkvist-api-c2k","depends_on_id":"checkvist-api-lpn","type":"blocks","created_at":"2026-01-14T12:32:54.859645166+01:00","created_by":"Oliver Jakoubek"}]}
|
||||
{"id":"checkvist-api-c2k","title":"Implement Checklist operations","description":"Create checklists.go with ChecklistService:\n- client.Checklists() returns ChecklistService\n- List(ctx) ([]Checklist, error) - GET /checklists.json\n- Get(ctx, id) (*Checklist, error) - GET /checklists/{id}.json\n- Create(ctx, name) (*Checklist, error) - POST /checklists.json\n- Update(ctx, id, name) (*Checklist, error) - PUT /checklists/{id}.json\n- Delete(ctx, id) error - DELETE /checklists/{id}.json\n- Support archived filter in List\nContext support for all methods.","status":"closed","priority":0,"issue_type":"feature","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:30:53.566197933+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:38:06.162666425+01:00","closed_at":"2026-01-14T13:38:06.162666425+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-c2k","depends_on_id":"checkvist-api-8u6","type":"blocks","created_at":"2026-01-14T12:32:54.533462004+01:00","created_by":"Oliver Jakoubek"},{"issue_id":"checkvist-api-c2k","depends_on_id":"checkvist-api-lpn","type":"blocks","created_at":"2026-01-14T12:32:54.859645166+01:00","created_by":"Oliver Jakoubek"}]}
|
||||
{"id":"checkvist-api-cb8","title":"Extended Features","description":"Phase 3: Implement P1 (should-have) features including client-side filtering and builder patterns for fluent interfaces.","status":"open","priority":1,"issue_type":"epic","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:30:55.624242123+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T12:30:55.624242123+01:00"}
|
||||
{"id":"checkvist-api-e9p","title":"Implement data models","description":"Create models.go with all data structures:\n- Checklist struct (ID, Name, Public, Archived, ReadOnly, TaskCount, TaskCompleted, Tags, TagsAsText, UpdatedAt)\n- Task struct (ID, ChecklistID, ParentID, Content, Status, Position, Priority, Tags, TagsAsText, DueDateRaw, DueDate, AssigneeIDs, CommentsCount, UpdateLine, UpdatedAt, CreatedAt, Children, Notes)\n- TaskStatus enum (StatusOpen=0, StatusClosed=1, StatusInvalidated=2)\n- Note struct (ID, TaskID, Comment, UpdatedAt, CreatedAt)\n- Tags type (map[string]bool)\n- User struct (ID, Username, Email)\n- DueDate struct with constructors (DueAt, DueString, DueInDays) and constants (DueToday, DueTomorrow, DueNextWeek, DueNextMonth)","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:06.900391036+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:22:22.273934664+01:00","closed_at":"2026-01-14T13:22:22.273934664+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-e9p","depends_on_id":"checkvist-api-5wr","type":"blocks","created_at":"2026-01-14T12:32:46.433908937+01:00","created_by":"Oliver Jakoubek"}]}
|
||||
{"id":"checkvist-api-lpn","title":"Implement authentication with auto token renewal","description":"Add to client.go:\n- Authenticate(ctx context.Context) error - explicit login\n- refreshToken(ctx context.Context) error - token renewal\n- ensureAuthenticated(ctx context.Context) error - auto-auth before requests\n- CurrentUser(ctx context.Context) (*User, error) - get logged in user\n- Token management: store token and expiry, auto-refresh before expiry\n- Thread-safe token access using mutex\n- Support for optional 2FA token\nAPI endpoints:\n- POST /auth/login.json?version=2 (login)\n- POST /auth/refresh_token.json?version=2 (refresh)\n- GET /auth/curr_user.json (current user)\nToken sent via X-Client-Token header","status":"closed","priority":0,"issue_type":"task","owner":"mail@oliverjakoubek.de","created_at":"2026-01-14T12:31:08.358878117+01:00","created_by":"Oliver Jakoubek","updated_at":"2026-01-14T13:26:32.668016856+01:00","closed_at":"2026-01-14T13:26:32.668016856+01:00","close_reason":"Closed","dependencies":[{"issue_id":"checkvist-api-lpn","depends_on_id":"checkvist-api-ymg","type":"blocks","created_at":"2026-01-14T12:32:47.656124681+01:00","created_by":"Oliver Jakoubek"}]}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,93 @@
|
|||
package checkvist
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// checklists.go contains the ChecklistService for CRUD operations on checklists.
|
||||
|
||||
// ChecklistService provides operations on Checkvist checklists.
|
||||
type ChecklistService struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// Checklists returns a ChecklistService for performing checklist operations.
|
||||
func (c *Client) Checklists() *ChecklistService {
|
||||
return &ChecklistService{client: c}
|
||||
}
|
||||
|
||||
// ListOptions configures the List operation.
|
||||
type ListOptions struct {
|
||||
// Archived filters to show only archived checklists when true.
|
||||
Archived bool
|
||||
}
|
||||
|
||||
// List returns all checklists accessible to the authenticated user.
|
||||
func (s *ChecklistService) List(ctx context.Context) ([]Checklist, error) {
|
||||
return s.ListWithOptions(ctx, ListOptions{})
|
||||
}
|
||||
|
||||
// ListWithOptions returns checklists with the specified options.
|
||||
func (s *ChecklistService) ListWithOptions(ctx context.Context, opts ListOptions) ([]Checklist, error) {
|
||||
path := "/checklists.json"
|
||||
if opts.Archived {
|
||||
path += "?archived=true"
|
||||
}
|
||||
|
||||
var checklists []Checklist
|
||||
if err := s.client.doGet(ctx, path, &checklists); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return checklists, nil
|
||||
}
|
||||
|
||||
// Get returns a single checklist by ID.
|
||||
func (s *ChecklistService) Get(ctx context.Context, id int) (*Checklist, error) {
|
||||
path := fmt.Sprintf("/checklists/%d.json", id)
|
||||
|
||||
var checklist Checklist
|
||||
if err := s.client.doGet(ctx, path, &checklist); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &checklist, nil
|
||||
}
|
||||
|
||||
// createChecklistRequest is the request body for creating a checklist.
|
||||
type createChecklistRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// Create creates a new checklist with the given name.
|
||||
func (s *ChecklistService) Create(ctx context.Context, name string) (*Checklist, error) {
|
||||
body := createChecklistRequest{Name: name}
|
||||
|
||||
var checklist Checklist
|
||||
if err := s.client.doPost(ctx, "/checklists.json", body, &checklist); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &checklist, nil
|
||||
}
|
||||
|
||||
// updateChecklistRequest is the request body for updating a checklist.
|
||||
type updateChecklistRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// Update updates the name of an existing checklist.
|
||||
func (s *ChecklistService) Update(ctx context.Context, id int, name string) (*Checklist, error) {
|
||||
path := fmt.Sprintf("/checklists/%d.json", id)
|
||||
body := updateChecklistRequest{Name: name}
|
||||
|
||||
var checklist Checklist
|
||||
if err := s.client.doPut(ctx, path, body, &checklist); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &checklist, nil
|
||||
}
|
||||
|
||||
// Delete permanently deletes a checklist by ID.
|
||||
func (s *ChecklistService) Delete(ctx context.Context, id int) error {
|
||||
path := fmt.Sprintf("/checklists/%d.json", id)
|
||||
return s.client.doDelete(ctx, path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue