2026-01-14 12:42:00 +01:00
|
|
|
package checkvist
|
|
|
|
|
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-14 12:42:00 +01:00
|
|
|
// tasks.go contains the TaskService for CRUD operations on tasks within a checklist.
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
|
|
|
|
|
// TaskService provides operations on tasks within a specific checklist.
|
|
|
|
|
type TaskService struct {
|
|
|
|
|
client *Client
|
|
|
|
|
checklistID int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tasks returns a TaskService for performing task operations on the specified checklist.
|
|
|
|
|
func (c *Client) Tasks(checklistID int) *TaskService {
|
|
|
|
|
return &TaskService{
|
|
|
|
|
client: c,
|
|
|
|
|
checklistID: checklistID,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List returns all tasks in the checklist.
|
|
|
|
|
func (s *TaskService) List(ctx context.Context) ([]Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks.json", s.checklistID)
|
|
|
|
|
|
|
|
|
|
var tasks []Task
|
|
|
|
|
if err := s.client.doGet(ctx, path, &tasks); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse due dates
|
|
|
|
|
for i := range tasks {
|
|
|
|
|
parseDueDate(&tasks[i])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tasks, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get returns a single task by ID, including its parent hierarchy.
|
|
|
|
|
func (s *TaskService) Get(ctx context.Context, taskID int) (*Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks/%d.json", s.checklistID, taskID)
|
|
|
|
|
|
|
|
|
|
var task Task
|
|
|
|
|
if err := s.client.doGet(ctx, path, &task); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseDueDate(&task)
|
|
|
|
|
return &task, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateTaskRequest represents the request body for creating a task.
|
|
|
|
|
type CreateTaskRequest struct {
|
2026-01-14 21:24:46 +01:00
|
|
|
Content string `json:"content"`
|
|
|
|
|
ParentID int `json:"parent_id,omitempty"`
|
|
|
|
|
Position int `json:"position,omitempty"`
|
|
|
|
|
Due string `json:"due_date,omitempty"`
|
|
|
|
|
Priority int `json:"priority,omitempty"`
|
|
|
|
|
Tags string `json:"tags,omitempty"`
|
|
|
|
|
Repeat string `json:"repeat,omitempty"`
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-14 19:02:34 +01:00
|
|
|
// createTaskWrapper wraps the task fields for the nested JSON format
|
|
|
|
|
// expected by the Checkvist API: {"task": {"content": "...", ...}}
|
|
|
|
|
type createTaskWrapper struct {
|
|
|
|
|
Task CreateTaskRequest `json:"task"`
|
|
|
|
|
}
|
|
|
|
|
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
// TaskBuilder provides a fluent interface for building task creation requests.
|
|
|
|
|
type TaskBuilder struct {
|
|
|
|
|
content string
|
|
|
|
|
parentID int
|
|
|
|
|
position int
|
|
|
|
|
due string
|
|
|
|
|
priority int
|
|
|
|
|
tags []string
|
2026-01-14 14:39:27 +01:00
|
|
|
repeat string
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewTask creates a new TaskBuilder with the given content.
|
|
|
|
|
func NewTask(content string) *TaskBuilder {
|
|
|
|
|
return &TaskBuilder{content: content}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithParent sets the parent task ID for creating a subtask.
|
|
|
|
|
func (b *TaskBuilder) WithParent(parentID int) *TaskBuilder {
|
|
|
|
|
b.parentID = parentID
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithPosition sets the position of the task within its siblings.
|
|
|
|
|
func (b *TaskBuilder) WithPosition(position int) *TaskBuilder {
|
|
|
|
|
b.position = position
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithDueDate sets the due date using a DueDate value.
|
|
|
|
|
func (b *TaskBuilder) WithDueDate(due DueDate) *TaskBuilder {
|
|
|
|
|
b.due = due.String()
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithPriority sets the priority level (1 = highest, 2 = high, 0 = normal).
|
|
|
|
|
func (b *TaskBuilder) WithPriority(priority int) *TaskBuilder {
|
|
|
|
|
b.priority = priority
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithTags sets the tags for the task.
|
|
|
|
|
func (b *TaskBuilder) WithTags(tags ...string) *TaskBuilder {
|
|
|
|
|
b.tags = tags
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 14:39:27 +01:00
|
|
|
// WithRepeat sets the repeat pattern for the task using Checkvist's smart syntax.
|
|
|
|
|
// Common patterns include:
|
|
|
|
|
// - "daily" - repeats every day
|
|
|
|
|
// - "weekly" - repeats every week
|
|
|
|
|
// - "monthly" - repeats every month
|
|
|
|
|
// - "yearly" - repeats every year
|
|
|
|
|
// - "every 2 days" - repeats every 2 days
|
|
|
|
|
// - "every week on monday" - repeats weekly on Monday
|
|
|
|
|
// - "every month on 15" - repeats monthly on the 15th
|
|
|
|
|
// - "every 2 weeks on friday" - repeats every 2 weeks on Friday
|
|
|
|
|
func (b *TaskBuilder) WithRepeat(pattern string) *TaskBuilder {
|
|
|
|
|
b.repeat = pattern
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
// build converts the TaskBuilder to a CreateTaskRequest.
|
|
|
|
|
func (b *TaskBuilder) build() CreateTaskRequest {
|
|
|
|
|
req := CreateTaskRequest{
|
|
|
|
|
Content: b.content,
|
|
|
|
|
ParentID: b.parentID,
|
|
|
|
|
Position: b.position,
|
|
|
|
|
Due: b.due,
|
|
|
|
|
Priority: b.priority,
|
2026-01-14 14:39:27 +01:00
|
|
|
Repeat: b.repeat,
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
if len(b.tags) > 0 {
|
|
|
|
|
for i, tag := range b.tags {
|
|
|
|
|
if i > 0 {
|
|
|
|
|
req.Tags += ", "
|
|
|
|
|
}
|
|
|
|
|
req.Tags += tag
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return req
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create creates a new task using a TaskBuilder.
|
|
|
|
|
func (s *TaskService) Create(ctx context.Context, builder *TaskBuilder) (*Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks.json", s.checklistID)
|
2026-01-14 19:02:34 +01:00
|
|
|
body := createTaskWrapper{Task: builder.build()}
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
|
|
|
|
|
var task Task
|
|
|
|
|
if err := s.client.doPost(ctx, path, body, &task); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseDueDate(&task)
|
|
|
|
|
return &task, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateTaskRequest represents the request body for updating a task.
|
|
|
|
|
type UpdateTaskRequest struct {
|
|
|
|
|
Content *string `json:"content,omitempty"`
|
|
|
|
|
ParentID *int `json:"parent_id,omitempty"`
|
|
|
|
|
Position *int `json:"position,omitempty"`
|
2026-01-14 19:02:34 +01:00
|
|
|
Due *string `json:"due_date,omitempty"`
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
Priority *int `json:"priority,omitempty"`
|
|
|
|
|
Tags *string `json:"tags,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 19:02:34 +01:00
|
|
|
// updateTaskWrapper wraps the task fields for PUT requests
|
|
|
|
|
type updateTaskWrapper struct {
|
|
|
|
|
Task UpdateTaskRequest `json:"task"`
|
|
|
|
|
}
|
|
|
|
|
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
// Update updates an existing task.
|
|
|
|
|
func (s *TaskService) Update(ctx context.Context, taskID int, req UpdateTaskRequest) (*Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks/%d.json", s.checklistID, taskID)
|
2026-01-14 19:02:34 +01:00
|
|
|
body := updateTaskWrapper{Task: req}
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
|
|
|
|
|
var task Task
|
2026-01-14 19:02:34 +01:00
|
|
|
if err := s.client.doPut(ctx, path, body, &task); err != nil {
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseDueDate(&task)
|
|
|
|
|
return &task, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete permanently deletes a task.
|
|
|
|
|
func (s *TaskService) Delete(ctx context.Context, taskID int) error {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks/%d.json", s.checklistID, taskID)
|
|
|
|
|
return s.client.doDelete(ctx, path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close marks a task as completed.
|
2026-01-15 10:48:38 +01:00
|
|
|
// The API returns an array containing the modified task and potentially its subtasks.
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
func (s *TaskService) Close(ctx context.Context, taskID int) (*Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks/%d/close.json", s.checklistID, taskID)
|
|
|
|
|
|
2026-01-15 10:48:38 +01:00
|
|
|
var tasks []Task
|
|
|
|
|
if err := s.client.doPost(ctx, path, nil, &tasks); err != nil {
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 10:48:38 +01:00
|
|
|
if len(tasks) == 0 {
|
|
|
|
|
return nil, fmt.Errorf("close task: unexpected empty response")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseDueDate(&tasks[0])
|
|
|
|
|
return &tasks[0], nil
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reopen reopens a closed or invalidated task.
|
2026-01-15 10:48:38 +01:00
|
|
|
// The API returns an array containing the modified task and potentially its subtasks.
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
func (s *TaskService) Reopen(ctx context.Context, taskID int) (*Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks/%d/reopen.json", s.checklistID, taskID)
|
|
|
|
|
|
2026-01-15 10:48:38 +01:00
|
|
|
var tasks []Task
|
|
|
|
|
if err := s.client.doPost(ctx, path, nil, &tasks); err != nil {
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 10:48:38 +01:00
|
|
|
if len(tasks) == 0 {
|
|
|
|
|
return nil, fmt.Errorf("reopen task: unexpected empty response")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseDueDate(&tasks[0])
|
|
|
|
|
return &tasks[0], nil
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Invalidate marks a task as invalidated (strikethrough).
|
2026-01-15 10:48:38 +01:00
|
|
|
// The API returns an array containing the modified task and potentially its subtasks.
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
func (s *TaskService) Invalidate(ctx context.Context, taskID int) (*Task, error) {
|
|
|
|
|
path := fmt.Sprintf("/checklists/%d/tasks/%d/invalidate.json", s.checklistID, taskID)
|
|
|
|
|
|
2026-01-15 10:48:38 +01:00
|
|
|
var tasks []Task
|
|
|
|
|
if err := s.client.doPost(ctx, path, nil, &tasks); err != nil {
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 10:48:38 +01:00
|
|
|
if len(tasks) == 0 {
|
|
|
|
|
return nil, fmt.Errorf("invalidate task: unexpected empty response")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parseDueDate(&tasks[0])
|
|
|
|
|
return &tasks[0], nil
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parseDueDate attempts to parse the DueDateRaw string into a time.Time.
|
2026-01-15 09:29:20 +01:00
|
|
|
// It supports the Checkvist API format (YYYY/MM/DD) and ISO 8601 format (YYYY-MM-DD).
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
func parseDueDate(task *Task) {
|
|
|
|
|
if task.DueDateRaw == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-15 09:29:20 +01:00
|
|
|
// Try multiple date formats (API uses slashes, ISO uses dashes)
|
|
|
|
|
formats := []string{
|
|
|
|
|
"2006/01/02", // Checkvist API format
|
|
|
|
|
"2006-01-02", // ISO 8601 format
|
|
|
|
|
}
|
|
|
|
|
for _, format := range formats {
|
|
|
|
|
if t, err := time.Parse(format, task.DueDateRaw); err == nil {
|
|
|
|
|
task.DueDate = &t
|
|
|
|
|
return
|
|
|
|
|
}
|
Implement Task operations
Add tasks.go with TaskService for full task CRUD:
- client.Tasks(checklistID) returns TaskService
- List(ctx) - get all tasks in checklist
- Get(ctx, taskID) - get single task with parent hierarchy
- Create(ctx, builder) - create task using TaskBuilder
- Update(ctx, taskID, req) - update task properties
- Delete(ctx, taskID) - permanently delete task
- Close(ctx, taskID) - mark task as completed
- Reopen(ctx, taskID) - reopen closed/invalidated task
- Invalidate(ctx, taskID) - mark task as invalidated (strikethrough)
TaskBuilder fluent interface for task creation:
- NewTask(content) - create builder
- WithParent(id) - set parent for subtask
- WithPosition(pos) - set position in list
- WithDueDate(due) - set due date using DueDate type
- WithPriority(level) - set priority (0=normal, 1=highest, 2=high)
- WithTags(tags...) - set tags
Automatic DueDate parsing from DueDateRaw (ISO 8601 format).
Closes checkvist-api-rl9
2026-01-14 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
}
|