-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
164 lines (145 loc) · 5.49 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
package gosimplicate
import (
"strings"
"time"
)
type CustomField struct {
ID string `json:"id"`
Name string `json:"name"`
Label string `json:"label"`
RenderType string `json:"render_type"`
Position int `json:"position"`
IsFilterable bool `json:"filterable"`
IsSearchable bool `json:"searchable"`
IsMandatory bool `json:"mandatory"`
ValueType string `json:"value_type"`
// Couldn't find an example of Options yet, so don't know what
// the implementation should be like.
//Options [] `json:"options"`
}
type Correction struct {
Amount int `json:"amount"`
Value int `json:"value"`
LastCorrectionDate string `json:"last_correction_date"`
}
type WrappedBool struct {
Value bool `json:"value"`
}
type Employee struct {
Id string `json:"id"`
Name string `json:"name"`
}
type Organization struct {
Id string `json:"id"`
Name string `json:"name"`
RelationNumber string `json:"relation_number"`
}
// Person represents a person in the Simplicate system.
//
// The actual API response also contains the 'timezone', 'country' and 'rights'
// fields, but these are not implemented in this struct yet.
type Person struct {
Username string `json:"username"`
Email string `json:"email"`
Gender string `json:"gender"`
BirthDate SimplicateDate `json:"birth_date"`
Initials string `json:"initials"`
FirstName string `json:"first_name"`
FamilyNamePrefix string `json:"family_name_prefix"`
FamilyName string `json:"family_name"`
IsAuthyEnabled bool `json:"is_authy_enabled"`
IsEmployee bool `json:"is_employee"`
IsLightUser bool `json:"is_light_user"`
EmployeeID string `json:"employee_id"`
PersonID string `json:"person_id"`
IsBlocked bool `json:"is_blocked"`
IsLockNav bool `json:"is_lock_nav"`
KeyIdentifier string `json:"key_identifier"`
HoursViewMode string `json:"hours_view_mode"`
IsAccountOwner bool `json:"is_account_owner"`
HasExternalAgendaIntegration bool `json:"has_external_agenda_integration"`
}
type Project struct {
Id string `json:"id"`
Name string `json:"project_name"`
ProjectNumber string `json:"project_number"`
Organization Organization `json:"organization"`
HasRegisterMileageEnabled bool `json:"has_register_mileage_enabled"`
}
type ProjectService struct {
Id string `json:"id"`
Name string `json:"name"`
StartDate SimplicateDate `json:"start_date"`
DefaultServiceId string `json:"default_service_id"`
RevenueGroupId string `json:"revenue_group_id"`
}
type ServiceType struct {
Id string `json:"id"`
Label string `json:"label"`
Tariff string `json:"tariff"`
Color string `json:"color"`
Type string `json:"type"`
}
// Hours represents a single registration of work.
type Hours struct {
Id string `json:"id"`
Note string `json:"note"`
Source string `json:"source"`
StartDate SimplicateTime `json:"start_date"`
EndDate SimplicateTime `json:"end_date"`
Hours float32 `json:"hours"`
DurationInMinutes int `json:"duration_in_minutes"`
IsRecurring bool `json:"is_recurring"`
IsTimeDefined bool `json:"is_time_defined"`
IsBillable bool `json:"billable"`
IsLocked bool `json:"locked"`
IsEditable WrappedBool `json:"is_editable"`
IsDeletable WrappedBool `json:"is_deletable"`
IsProductive bool `json:"is_productive"`
ShouldSyncToCronofy bool `json:"should_sync_to_cronofy"`
Employee Employee `json:"employee"`
Project Project `json:"project"`
ProjectService ProjectService `json:"projectservice"`
Type ServiceType `json:"type"`
CustomFields []CustomField `json:"custom_fields"`
Corrections Correction `json:"corrections,omitempty"`
}
type HoursType struct {
Id string `json:"id"`
Label string `json:"label"`
Color string `json:"color"`
}
// ProjectsResponse contains response data from the /projects resource.
//
// The response also contains `errors` and `debug` keys, but I've
// never seen them containing anything but `null`, so I don't know
// what data type they hold.
type ProjectsResponse struct {
Data []Project `json:"data"`
}
type SimplicateTime struct {
time.Time
}
const SimplicateTimeLayout = "2006-01-02 15:04:05"
func (st *SimplicateTime) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), "\"")
if s == "null" {
st.Time = time.Time{}
return
}
st.Time, err = time.Parse(SimplicateTimeLayout, s)
return
}
type SimplicateDate struct {
time.Time
}
const SimplicateDateLayout = "2006-01-02"
func (st *SimplicateDate) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), "\"")
if s == "null" {
st.Time = time.Time{}
return
}
st.Time, err = time.Parse(SimplicateDateLayout, s)
return
}