-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinternalTaskLink.go
110 lines (97 loc) · 2.92 KB
/
internalTaskLink.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package ganboard
import "encoding/json"
// CreateTaskLink https://docs.kanboard.org/en/latest/api/internal_task_link_procedures.html#createtasklink
func (c *Client) CreateTaskLink(taskID int, oppositeTaskID int, linkID int) (int, error) {
query := request{
Client: c,
Method: "createTaskLink",
Params: map[string]int{
"task_id": taskID,
"opposite_task_id": oppositeTaskID,
"link_id": linkID,
},
}
response, err := query.decodeInt()
return response, err
}
// UpdateTaskLink https://docs.kanboard.org/en/latest/api/internal_task_link_procedures.html#updatetasklink
func (c *Client) UpdateTaskLink(taskLinkID int, taskID int, oppositeTaskID int, linkID int) (int, error) {
query := request{
Client: c,
Method: "updateTaskLink",
Params: map[string]int{
"task_link_id": taskLinkID,
"task_id": taskID,
"opposite_task_id": oppositeTaskID,
"link_id": linkID,
},
}
response, err := query.decodeInt()
return response, err
}
// GetTaskLinkByID https://docs.kanboard.org/en/latest/api/internal_task_link_procedures.html#gettasklinkbyid
func (c *Client) GetTaskLinkByID(taskLinkID int) (InternalLink, error) {
query := request{
Client: c,
Method: "getTaskLinkById",
Params: map[string]int{
"task_link_id": taskLinkID,
},
}
response, err := query.decodeInternalLink()
return response, err
}
// GetAllTaskLinks https://docs.kanboard.org/en/latest/api/internal_task_link_procedures.html#getalltasklinks
func (c *Client) GetAllTaskLinks() ([]InternalLink, error) {
query := request{
Client: c,
Method: "getAllTaskLinks",
}
response, err := query.decodeInternalLinks()
return response, err
}
// RemoveTaskLink https://docs.kanboard.org/en/latest/api/internal_task_link_procedures.html#removetasklink
func (c *Client) RemoveTaskLink(taskLinkID int) (bool, error) {
query := request{
Client: c,
Method: "removeTaskLink",
Params: map[string]int{
"task_link_id": taskLinkID,
},
}
response, err := query.decodeBoolean()
return response, err
}
// InternalLink type
type InternalLink struct {
ID int `json:"id,string"`
LinkID int `json:"link_id,string"`
TaskID int `json:"task_id,string"`
OppositeTaskID int `json:"opposite_task_id"`
}
func (r *request) decodeInternalLink() (InternalLink, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return InternalLink{}, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result InternalLink `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}
func (r *request) decodeInternalLinks() ([]InternalLink, error) {
rsp, err := r.Client.Request(*r)
if err != nil {
return nil, err
}
body := struct {
JSONRPC string `json:"jsonrpc"`
ID FlexInt `json:"id"`
Result []InternalLink `json:"result"`
}{}
err = json.NewDecoder(rsp.Body).Decode(&body)
return body.Result, err
}