-
Notifications
You must be signed in to change notification settings - Fork 19
/
svc_task.go
232 lines (192 loc) · 9.29 KB
/
svc_task.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package lokalise
import (
"fmt"
"github.com/go-resty/resty/v2"
"github.com/google/go-querystring/query"
)
// TaskService support List, Create, Retrieve, Update, Delete operations
type TaskService struct {
BaseService
listOpts TaskListOptions
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service entity objects
// _____________________________________________________________________________________________________________________
// noinspection GoUnusedConst
const (
pathTasks = "tasks"
StatusCompleted TaskStatus = "completed"
StatusInProgress TaskStatus = "in_progress"
StatusCreated TaskStatus = "created"
StatusQueued TaskStatus = "queued"
TaskTypeTranslation TaskType = "translation"
TaskTypeReview TaskType = "review"
LanguageStatusCompleted LanguageStatus = "completed"
LanguageStatusInProgress LanguageStatus = "in progress"
LanguageStatusCreated LanguageStatus = "created"
)
type (
TaskStatus string
TaskType string
LanguageStatus string
)
type Task struct {
WithCreationTime
WithCreationUser
TaskID int64 `json:"task_id"`
Title string `json:"title"`
Description string `json:"description"`
Status TaskStatus `json:"status"`
Progress int `json:"progress"`
DueDate string `json:"due_date"`
DueDateTimestamp int64 `json:"due_date_timestamp"`
KeysCount int64 `json:"keys_count"`
WordsCount int64 `json:"words_count"`
CanBeParent bool `json:"can_be_parent"`
TaskType TaskType `json:"task_type"`
ParentTaskID int64 `json:"parent_task_id"`
ClosingTags []string `json:"closing_tags"`
LockTranslations bool `json:"do_lock_translations"`
Languages []TaskLanguage `json:"languages"`
SourceLanguageISO string `json:"source_language_iso"`
AutoCloseLanguages bool `json:"auto_close_languages"`
AutoCloseTask bool `json:"auto_close_task"`
AutoCloseItems bool `json:"auto_close_items"`
CompletedAt string `json:"completed_at"`
CompletedAtTs int64 `json:"completed_at_timestamp"`
CompletedBy int64 `json:"completed_by"`
CompletedByEmail string `json:"completed_by_email"`
CustomTranslationStatusIDs []int64 `json:"custom_translation_status_ids,omitempty"`
}
type TaskLanguage struct {
LanguageISO string `json:"language_iso"`
Users []TaskUser `json:"users"`
Groups []TaskGroup `json:"groups"`
Keys []int64 `json:"keys"`
Status LanguageStatus `json:"status"`
Progress int `json:"progress"`
InitialTMLeverage map[string]int64 `json:"initial_tm_leverage"`
KeysCount int64 `json:"keys_count"`
WordsCount int64 `json:"words_count"`
CompletedAt string `json:"completed_at"`
CompletedAtTs int64 `json:"completed_at_timestamp"`
CompletedBy int64 `json:"completed_by"`
CompletedByEmail string `json:"completed_by_email"`
}
type TaskUser struct {
WithUserID
Email string `json:"email"`
Fullname string `json:"fullname"`
}
type TaskGroup struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service request/response objects
// _____________________________________________________________________________________________________________________
type CreateTask struct {
Title string `json:"title"`
Languages []CreateTaskLang `json:"languages"`
Description string `json:"description,omitempty"`
DueDate string `json:"due_date,omitempty"`
Keys []int64 `json:"keys,omitempty"`
SourceLanguageISO string `json:"source_language_iso,omitempty"`
AutoCloseLanguages *bool `json:"auto_close_languages,omitempty"`
AutoCloseTask *bool `json:"auto_close_task,omitempty"`
AutoCloseItems *bool `json:"auto_close_items,omitempty"`
TaskType TaskType `json:"task_type,omitempty"`
ParentTaskID int64 `json:"parent_task_id,omitempty"`
ClosingTags []string `json:"closing_tags,omitempty"`
LockTranslations bool `json:"do_lock_translations,omitempty"`
CustomTranslationStatusIDs []int64 `json:"custom_translation_status_ids,omitempty"`
}
type CreateTaskLang struct {
LanguageISO string `json:"language_iso,omitempty"`
Users []int64 `json:"users,omitempty"`
Groups []int64 `json:"groups,omitempty"`
CloseLanguage bool `json:"close_language,omitempty"` // only for updating
}
type UpdateTask struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
DueDate string `json:"due_date,omitempty"`
Languages []CreateTaskLang `json:"languages,omitempty"`
AutoCloseLanguages *bool `json:"auto_close_languages,omitempty"`
AutoCloseTask *bool `json:"auto_close_task,omitempty"`
AutoCloseItems *bool `json:"auto_close_items,omitempty"`
CloseTask bool `json:"close_task,omitempty"`
ClosingTags []string `json:"closing_tags,omitempty"`
LockTranslations bool `json:"do_lock_translations,omitempty"`
}
type TasksResponse struct {
Paged
WithProjectID
Tasks []Task `json:"tasks"`
}
type TaskResponse struct {
WithProjectID
Task Task `json:"task"`
}
type DeleteTaskResponse struct {
WithProjectID
Deleted bool `json:"task_deleted"`
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Service methods
// _____________________________________________________________________________________________________________________
func (c *TaskService) List(projectID string) (r TasksResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathTasks), &r, c.ListOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *TaskService) Create(projectID string, task CreateTask) (r TaskResponse, err error) {
resp, err := c.post(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathTasks), &r, task)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *TaskService) Retrieve(projectID string, taskID int64) (r TaskResponse, err error) {
resp, err := c.get(c.Ctx(), fmt.Sprintf("%s/%s/%s/%d", pathProjects, projectID, pathTasks, taskID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *TaskService) Update(projectID string, taskID int64, task UpdateTask) (r TaskResponse, err error) {
resp, err := c.put(c.Ctx(), fmt.Sprintf("%s/%s/%s/%d", pathProjects, projectID, pathTasks, taskID), &r, task)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *TaskService) Delete(projectID string, taskID int64) (r DeleteTaskResponse, err error) {
resp, err := c.delete(c.Ctx(), fmt.Sprintf("%s/%s/%s/%d", pathProjects, projectID, pathTasks, taskID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
// ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Additional methods
// _____________________________________________________________________________________________________________________
type TaskListOptions struct {
Limit uint `url:"limit,omitempty"`
Page uint `url:"page,omitempty"`
FilterTitle string `url:"filter_title,omitempty"`
FilterStatuses []TaskStatus `url:"filter_statuses,omitempty"`
}
func (options TaskListOptions) Apply(req *resty.Request) {
v, _ := query.Values(options)
req.SetQueryString(v.Encode())
}
func (c *TaskService) ListOpts() TaskListOptions { return c.listOpts }
func (c *TaskService) SetListOptions(o TaskListOptions) { c.listOpts = o }
func (c *TaskService) WithListOptions(o TaskListOptions) *TaskService {
c.listOpts = o
return c
}