Implement Link API methods
- GetAllTaskLinks: retrieve all links for a task - CreateTaskLink: create link between two tasks - RemoveTaskLink: delete a task link - TaskScope.GetLinks and LinkTo for fluent API - Link types include "blocks", "is blocked by", etc. - Comprehensive test coverage
This commit is contained in:
parent
4907a7caad
commit
39ff0a90c8
4 changed files with 336 additions and 1 deletions
56
links.go
Normal file
56
links.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package kanboard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GetAllTaskLinks returns all links for a task.
|
||||
func (c *Client) GetAllTaskLinks(ctx context.Context, taskID int) ([]TaskLink, error) {
|
||||
params := map[string]int{"task_id": taskID}
|
||||
|
||||
var result []TaskLink
|
||||
if err := c.call(ctx, "getAllTaskLinks", params, &result); err != nil {
|
||||
return nil, fmt.Errorf("getAllTaskLinks: %w", err)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateTaskLink creates a link between two tasks.
|
||||
// The linkID specifies the type of relationship (e.g., "blocks", "is blocked by").
|
||||
// Returns the ID of the created link.
|
||||
func (c *Client) CreateTaskLink(ctx context.Context, taskID, oppositeTaskID, linkID int) (int, error) {
|
||||
params := map[string]int{
|
||||
"task_id": taskID,
|
||||
"opposite_task_id": oppositeTaskID,
|
||||
"link_id": linkID,
|
||||
}
|
||||
|
||||
var result int
|
||||
if err := c.call(ctx, "createTaskLink", params, &result); err != nil {
|
||||
return 0, fmt.Errorf("createTaskLink: %w", err)
|
||||
}
|
||||
|
||||
if result == 0 {
|
||||
return 0, fmt.Errorf("createTaskLink: failed to create link")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RemoveTaskLink deletes a task link.
|
||||
func (c *Client) RemoveTaskLink(ctx context.Context, taskLinkID int) error {
|
||||
params := map[string]int{"task_link_id": taskLinkID}
|
||||
|
||||
var success bool
|
||||
if err := c.call(ctx, "removeTaskLink", params, &success); err != nil {
|
||||
return fmt.Errorf("removeTaskLink: %w", err)
|
||||
}
|
||||
|
||||
if !success {
|
||||
return fmt.Errorf("removeTaskLink: delete failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue