Implement TaskScope fluent builder (core methods)
- TaskScope struct for task-scoped operations - Client.Task(taskID) returns a TaskScope - Methods: Get, Close, Open, MoveToColumn, MoveToProject, Update - MoveToColumn fetches task to get project_id and swimlane_id - All methods delegate to direct Client methods - Comprehensive test coverage
This commit is contained in:
parent
0c5b7fd6e9
commit
371bdb8ba9
3 changed files with 316 additions and 1 deletions
53
task_scope.go
Normal file
53
task_scope.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package kanboard
|
||||
|
||||
import "context"
|
||||
|
||||
// TaskScope provides fluent task-scoped operations.
|
||||
type TaskScope struct {
|
||||
client *Client
|
||||
taskID int
|
||||
}
|
||||
|
||||
// Task returns a TaskScope for fluent task-scoped operations.
|
||||
func (c *Client) Task(taskID int) *TaskScope {
|
||||
return &TaskScope{
|
||||
client: c,
|
||||
taskID: taskID,
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the task.
|
||||
func (t *TaskScope) Get(ctx context.Context) (*Task, error) {
|
||||
return t.client.GetTask(ctx, t.taskID)
|
||||
}
|
||||
|
||||
// Close closes the task (sets it to inactive).
|
||||
func (t *TaskScope) Close(ctx context.Context) error {
|
||||
return t.client.CloseTask(ctx, t.taskID)
|
||||
}
|
||||
|
||||
// Open opens the task (sets it to active).
|
||||
func (t *TaskScope) Open(ctx context.Context) error {
|
||||
return t.client.OpenTask(ctx, t.taskID)
|
||||
}
|
||||
|
||||
// MoveToColumn moves the task to a different column.
|
||||
// The task is placed at the end of the column (position=0).
|
||||
// Requires the project ID to be fetched from the task.
|
||||
func (t *TaskScope) MoveToColumn(ctx context.Context, columnID int) error {
|
||||
task, err := t.Get(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return t.client.MoveTaskPosition(ctx, int(task.ProjectID), t.taskID, columnID, 0, int(task.SwimlaneID))
|
||||
}
|
||||
|
||||
// MoveToProject moves the task to a different project.
|
||||
func (t *TaskScope) MoveToProject(ctx context.Context, projectID int) error {
|
||||
return t.client.MoveTaskToProject(ctx, t.taskID, projectID)
|
||||
}
|
||||
|
||||
// Update updates the task using TaskUpdateParams.
|
||||
func (t *TaskScope) Update(ctx context.Context, params *TaskUpdateParams) error {
|
||||
return t.client.UpdateTaskFromParams(ctx, t.taskID, params)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue