-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
413 lines (369 loc) · 13.1 KB
/
types.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
package tenkft
// Projects a collection of project - emulates /projects
type Projects struct {
Data []*Project `json:"data"`
Paging *Paging `json:"paging"`
}
// GetByID get a project from collection by id
func (ps *Projects) GetByID(id int) (targetProject *Project) {
for _, p := range ps.Data {
if p.ID == id {
targetProject = p
return
}
}
return
}
// Find finds a person based on a callback that returns a boolean
func (ps *Projects) Find(cb func(*Project) bool) (p *Project) {
for _, project := range ps.Data {
if cb(project) {
p = project
return
}
}
return
}
type baseProject struct {
Archived bool `json:"archived,omitempty"`
Name string `json:"name,omitempty"`
EndsAt string `json:"ends_at,omitempty"`
StartsAt string `json:"starts_at,omitempty"`
Description string `json:"description,omitempty"`
Client string `json:"client,omitempty"`
ProjectState string `json:"project_state,omitempty"`
PhaseName string `json:"phase_name,omitempty,omitempty"`
ProjectCode string `json:"project_code,omitempty,omitempty"`
}
// Project abstraction to the /project schema
type Project struct {
*baseProject
ID int `json:"id"`
ArchivedAt string `json:"archived_at"`
GUID string `json:"guid"`
ParentID int `json:"parent_id"`
SecureURL string `json:"secureurl"`
SecureURLExpiration string `json:"secureurl_expiration"`
Settings interface{} `json:"settings"`
TimeentryLockout interface{} `json:"timeentry_lockout"`
DeletedAt string `json:"deleted_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
UseParentBillRates bool `json:"use_parent_bill_rates"`
Thumbnail string `json:"thumbnail"`
Type string `json:"type"`
HasPendingUpdates bool `json:"has_pending_updates"`
Tags Tags `json:"tags"`
Assignments Assignments `json:"assignments"`
BoundingStartdate string `json:"bounding_startdate"`
BoundingEnddate string `json:"bounding_enddate"`
ConfirmedHours float64 `json:"confirmed_hours"`
ConfirmedDollars float64 `json:"confirmed_dollars"`
ApprovedHours float64 `json:"approved_hours"`
ApprovedDollars float64 `json:"approved_dollars"`
UnconfirmedHours float64 `json:"unconfirmed_hours"`
UnconfirmedDollars float64 `json:"unconfirmed_dollars"`
ScheduledHours float64 `json:"scheduled_hours"`
ScheduledDollars float64 `json:"scheduled_dollars"`
FutureHours float64 `json:"future_hours"`
FutureDollars float64 `json:"future_dollars"`
}
type baseUser struct {
Archived bool `json:"archived,omitempty"`
Discipline string `json:"discipline"`
Email string `json:"email"`
FirstName string `json:"first_name"`
HireDate string `json:"hire_date"`
LastName string `json:"last_name"`
Location string `json:"location"`
MobilePhone string `json:"mobile_phone"`
Role string `json:"role"`
BillabilityTarget float64 `json:"billability_target"`
}
// User abstraction to the /user schema
type User struct {
*baseUser
AccountOwner bool `json:"account_owner"`
ArchivedAt string `json:"archived_at"`
Billable bool `json:"billable"`
Billrate float64 `json:"billrate"`
CreatedAt string `json:"created_at"`
Deleted bool `json:"deleted"`
DeletedAt string `json:"deleted_at"`
DisplayName string `json:"display_name"`
EmployeeNumber interface{} `json:"employee_number"`
GUID string `json:"guid"`
HasLogin bool `json:"has_login"`
ID int `json:"id"`
InvitationPending bool `json:"invitation_pending"`
LoginType string `json:"login_type"`
OfficePhone string `json:"office_phone"`
TerminationDate string `json:"termination_date"`
Thumbnail string `json:"thumbnail"`
Type string `json:"type"`
UserSettings float64 `json:"user_settings"`
UserTypeID int `json:"user_type_id"`
Tags Tags `json:"tags"`
Assignments Assignments `json:"assignments"`
Availabilities Availabilities `json:"availabilities"`
}
// Tags holds a collection of tags - only reachable from a user or project.
type Tags struct {
Data []*Tag `json:"data"`
Paging *Paging `json:"paging"`
}
type baseTag struct {
Value string `json:"value"`
}
// Tag holds a tag - only reachable from a user or a project.
type Tag struct {
*baseTag
ID int `json:"id"`
}
// Tags holds a collection of tags - only reachable from a user or project.
type Availabilities struct {
Data []*Availability `json:"data"`
Paging *Paging `json:"paging"`
}
// Tag holds a tag - only reachable from a user or a project.
type Availability struct {
ID int `json:"id"`
UserID int `json:"user_id"`
StartsAt string `json:"starts_at"`
EndsAt string `json:"ends_at"`
Day0 float64 `json:"day0"`
Day1 float64 `json:"day1"`
Day2 float64 `json:"day2"`
Day3 float64 `json:"day3"`
Day4 float64 `json:"day4"`
Day5 float64 `json:"day5"`
Day6 float64 `json:"day6"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// Users holds a collection of users and also indicates whether paginating is available.
type Users struct {
Data []*User `json:"data"`
Paging *Paging `json:"paging"`
}
// GetNonOwnerCount returns the number of users who are not account owners
func (users *Users) GetNonOwnerCount() int {
var count int
for _, u := range users.Data {
if u.AccountOwner == false {
count++
}
}
return count
}
// Paging abstracts paging parameters
type Paging struct {
PerPage int `json:"per_page"`
Page int `json:"page"`
Previous string `json:"previous"`
Self string `json:"self"`
Next string `json:"next"`
}
// HasNext confirms whether there is a next pagination page.
func (p *Paging) HasNext() bool {
return p.Next != "null" && p.Next != ""
}
// GetNextPage returns next page in pagination
func (p *Paging) GetNextPage() int {
return p.Page + 1
}
// Assignments abstraction to /assignments schema
type Assignments struct {
Data []*Assignment `json:"data"`
Paging *Paging `json:"paging"`
}
type baseAssignment struct {
AllocationMode string `json:"allocation_mode"`
AssignableID int `json:"assignable_id"`
EndsAt string `json:"ends_at"`
FixedHours float64 `json:"fixed_hours,omitempty"`
HoursPerDay float64 `json:"hours_per_day,omitempty"`
Percent float64 `json:"percent,omitempty"`
StartsAt string `json:"starts_at"`
}
// Assignment an abstraction to an assignment schema
type Assignment struct {
*baseAssignment
AllDayAssignment bool `json:"all_day_assignment"`
BillRate float64 `json:"bill_rate"`
BillRateID int `json:"bill_rate_id"`
CreatedAt string `json:"created_at"`
ID int `json:"id"`
RepetitionID int `json:"repetition_id"`
ResourceRequestID int `json:"resource_request_id"`
Status string `json:"status"`
UpdatedAt string `json:"updated_at"`
UserID int `json:"user_id"`
}
// Phases abstraction to project phases schema
type Phases struct {
Data []*Phase `json:"data"`
Paging *Paging `json:"paging"`
}
type basePhase struct {
Archived bool `json:"archived,omitempty"`
PhaseName string `json:"phase_name"`
EndsAt string `json:"ends_at"`
StartsAt string `json:"starts_at"`
}
// Phase abstraction to a project phase object
type Phase struct {
*basePhase
ID int `json:"id"`
ArchivedAt string `json:"archived_at"`
Description string `json:"description"`
GUID string `json:"guid"`
Name string `json:"name"`
ParentID int `json:"parent_id"`
ProjectCode string `json:"project_code"`
SecureURL string `json:"secureurl"`
SecureURLExpiration string `json:"secureurl_expiration"`
Settings interface{} `json:"settings"`
TimeentryLockout interface{} `json:"timeentry_lockout"`
DeletedAt string `json:"deleted_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
UseParentBillRates bool `json:"use_parent_bill_rates"`
Thumbnail string `json:"thumbnail"`
Type string `json:"type"`
HasPendingUpdates bool `json:"has_pending_updates"`
Client string `json:"client"`
ProjectState string `json:"project_state"`
}
// PlaceholderResources abstraction to /placeholder_resources
type PlaceholderResources struct {
Data []*PlaceholderResource `json:"data"`
Paging *Paging `json:"paging"`
}
// PlaceholderResource abstraction to a PlaceholderResource object.
type PlaceholderResource struct {
ID int `json:"id"`
Title string `json:"title"`
UserTypeID int `json:"user_type_id"`
GUID string `json:"guid"`
Role string `json:"role"`
Discipline string `json:"discipline"`
Location string `json:"location"`
CreatedAt string `json:"created_at"`
Billrate float64 `json:"billrate"`
DisplayName string `json:"displayName"`
Type string `json:"type"`
Thumbnail string `json:"thumbnail"`
Abbreviation string `json:"abbreviation"`
Color string `json:"color"`
}
// LeaveTypes abstraction to /leave_types response collection
type LeaveTypes struct {
Data []*LeaveType `json:"data"`
Paging *Paging `json:"paging"`
}
// FindByName finds a *LeaveType by its name
func (lts *LeaveTypes) FindByName(name string) (lt *LeaveType) {
for _, lt = range lts.Data {
if lt.Name == name {
return
}
}
return
}
// LeaveType abstraction to LeaveType object
type LeaveType struct {
ID int `json:"id"`
Description string `json:"description"`
GUID string `json:"guid"`
Name string `json:"name"`
DeletedAt string `json:"deleted_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Type string `json:"type"`
}
// Roles abstraction to /roles schema
type Roles struct {
Data []*Role `json:"data"`
Paging *Paging `json:"paging"`
}
// Role abstraction to a role object
type Role struct {
ID int `json:"id"`
Value string `json:"value"`
}
// BillRates abstraction to /roles schema
type BillRates struct {
Data []*BillRate `json:"data"`
Paging *Paging `json:"paging"`
}
// BillRate abstraction to a role object
type BillRate struct {
ID int `json:"id"`
Rate float64 `json:"rate"`
AssignableID int `json:"assignable_id"`
DisciplineID int `json:"discipline_id"`
RoleID int `json:"role_id"`
UserID int `json:"user_id"`
StartsAt string `json:"starts_at"`
EndsAt string `json:"ends_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Startdate string `json:"startdate"`
Enddate string `json:"enddate"`
}
type TimeEntries struct {
Data []*TimeEntry `json:"data"`
Paging *Paging `json:"paging"`
}
type TimeEntry struct {
Task string `json:"task"`
ScheduledHours float64 `json:"scheduled_hours"`
Hours float64 `json:"hours"`
BillRateID int `json:"bill_rate_id"`
AssignableID int `json:"assignable_id"`
UpdatedAt string `json:"updated_at"`
ID int `json:"id": 591986688`
BillRate float64 `json:"bill_rate"`
Notes string `json:"notes"`
UserID int `json:"user_id"`
IsSuggestion bool `json:"is_suggestion"`
Date string `json:"date"`
CreatedAt string `json:"created_at"`
AssignableType string `json:"assignable_type"`
}
type Holidays struct {
Data []*Holiday `json:"data"`
Paging *Paging `json:"paging"`
}
type Holiday struct {
UpdatedAt string `json:"updated_at"`
Date string `json:"date"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
ID int `json:"id"`
}
type Approvals struct {
Data []*Approval `json:"data"`
Paging *Paging `json:"paging"`
}
type Approval struct {
ApprovedAt string `json:"approved_at"`
ApprovedBy int `json:"approved_by"`
Status string `json:"status"`
ApprovableType string `json:"approvable_type"`
ApprovableId int `json:"approvable_id"`
ID int `json:"id"`
UpdatedAt string `json:"updated_at"`
SubmittedAt string `json:"submitted_at"`
CreatedAt string `json:"created_at"`
SubmittedBy int `json:"submitted_by"`
}
type Disciplines struct {
Data []*Discipline `json:"data"`
Paging *Paging `json:"paging"`
}
type Discipline struct {
Value string `json:"value"`
ID int `json:"id"`
}