This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
history.go
272 lines (220 loc) · 6.76 KB
/
history.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
package api
import (
"encoding/json"
)
// HistoryResidence represents the payload for the history residence section.
type HistoryResidence struct {
PayloadList Payload `json:"List" sql:"-"`
// Validator specific fields
List *Collection `json:"-"`
// Persister specific fields
ID int `json:"-"`
ListID int `json:"-" pg:", fk:List"`
}
// Unmarshal bytes in to the entity properties.
func (entity *HistoryResidence) Unmarshal(raw []byte) error {
err := json.Unmarshal(raw, entity)
if err != nil {
return err
}
list, err := entity.PayloadList.Entity()
if err != nil {
return err
}
entity.List = list.(*Collection)
return err
}
// Marshal to payload structure
func (entity *HistoryResidence) Marshal() Payload {
if entity.List != nil {
entity.PayloadList = entity.List.Marshal()
}
return MarshalPayloadEntity("history.residence", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *HistoryResidence) Valid() (bool, error) {
return entity.List.Valid()
}
// ClearNoBranches clears any questions answered nos on a kickback
func (entity *HistoryResidence) ClearNoBranches() error {
entity.List.ClearBranchNo()
return nil
}
// HistoryEmployment represents the payload for the history employment section.
type HistoryEmployment struct {
PayloadList Payload `json:"List" sql:"-"`
PayloadEmploymentRecord Payload `json:"EmploymentRecord" sql:"-"`
// Validator specific fields
List *Collection `json:"-"`
EmploymentRecord *Branch `json:"-"`
// Persister specific fields
ID int `json:"-"`
ListID int `json:"-" pg:", fk:List"`
EmploymentRecordID int `json:"-"`
}
// Unmarshal bytes in to the entity properties.
func (entity *HistoryEmployment) Unmarshal(raw []byte) error {
err := json.Unmarshal(raw, entity)
if err != nil {
return err
}
list, err := entity.PayloadList.Entity()
if err != nil {
return err
}
entity.List = list.(*Collection)
employmentRecord, err := entity.PayloadEmploymentRecord.Entity()
if err != nil {
return err
}
entity.EmploymentRecord = employmentRecord.(*Branch)
return err
}
// Marshal to payload structure
func (entity *HistoryEmployment) Marshal() Payload {
if entity.List != nil {
entity.PayloadList = entity.List.Marshal()
}
if entity.EmploymentRecord != nil {
entity.PayloadEmploymentRecord = entity.EmploymentRecord.Marshal()
}
return MarshalPayloadEntity("history.employment", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *HistoryEmployment) Valid() (bool, error) {
if ok, err := entity.List.Valid(); !ok {
return false, err
}
if ok, err := entity.EmploymentRecord.Valid(); !ok {
return false, err
}
return true, nil
}
// ClearNoBranches clears any questions answered nos on a kickback
func (entity *HistoryEmployment) ClearNoBranches() error {
entity.EmploymentRecord.ClearNo()
nestedErr := entity.List.ClearNestedHasNo("Reprimand")
if nestedErr != nil {
return nestedErr
}
entity.List.ClearBranchNo()
return nil
}
// HistoryEducation represents the payload for the history education section.
type HistoryEducation struct {
PayloadHasAttended Payload `json:"HasAttended" sql:"-"`
PayloadHasDegree10 Payload `json:"HasDegree10" sql:"-"`
PayloadList Payload `json:"List" sql:"-"`
// Validator specific fields
HasAttended *Branch `json:"-" sql:"-"`
HasDegree10 *Branch `json:"-" sql:"-"`
List *Collection `json:"-" sql:"-"`
// Persister specific fields
ID int `json:"-"`
HasAttendedID int `json:"-" pg:", fk:HasAttended"`
HasDegree10ID int `json:"-" pg:", fk:HasDegree10" sql:"has_degree10_id"`
ListID int `json:"-" pg:", fk:List"`
}
// Unmarshal bytes in to the entity properties.
func (entity *HistoryEducation) Unmarshal(raw []byte) error {
err := json.Unmarshal(raw, entity)
if err != nil {
return err
}
hasAttended, err := entity.PayloadHasAttended.Entity()
if err != nil {
return err
}
entity.HasAttended = hasAttended.(*Branch)
hasDegree10, err := entity.PayloadHasDegree10.Entity()
if err != nil {
return err
}
entity.HasDegree10 = hasDegree10.(*Branch)
list, err := entity.PayloadList.Entity()
if err != nil {
return err
}
entity.List = list.(*Collection)
return err
}
// Marshal to payload structure
func (entity *HistoryEducation) Marshal() Payload {
if entity.HasAttended != nil {
entity.PayloadHasAttended = entity.HasAttended.Marshal()
}
if entity.HasDegree10 != nil {
entity.PayloadHasDegree10 = entity.HasDegree10.Marshal()
}
if entity.List != nil {
entity.PayloadList = entity.List.Marshal()
}
return MarshalPayloadEntity("history.education", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *HistoryEducation) Valid() (bool, error) {
if entity.HasAttended.Value == "Yes" || entity.HasDegree10.Value == "Yes" {
return entity.List.Valid()
}
return true, nil
}
// ClearNoBranches clears any questions answered nos on a kickback
func (entity *HistoryEducation) ClearNoBranches() error {
entity.HasAttended.ClearNo()
entity.HasDegree10.ClearNo()
entity.List.ClearBranchNo()
return nil
}
// HistoryFederal represents the payload for the history federal section.
type HistoryFederal struct {
PayloadHasFederalService Payload `json:"HasFederalService" sql:"-"`
PayloadList Payload `json:"List" sql:"-"`
// Validator specific fields
HasFederalService *Branch `json:"-"`
List *Collection `json:"-"`
// Persister specific fields
ID int `json:"-"`
HasFederalServiceID int `json:"-" pg:", fk:HasFederalService"`
ListID int `json:"-" pg:", fk:List"`
}
// Unmarshal bytes in to the entity properties.
func (entity *HistoryFederal) Unmarshal(raw []byte) error {
err := json.Unmarshal(raw, entity)
if err != nil {
return err
}
hasFederalService, err := entity.PayloadHasFederalService.Entity()
if err != nil {
return err
}
entity.HasFederalService = hasFederalService.(*Branch)
list, err := entity.PayloadList.Entity()
if err != nil {
return err
}
entity.List = list.(*Collection)
return err
}
// Marshal to payload structure
func (entity *HistoryFederal) Marshal() Payload {
if entity.HasFederalService != nil {
entity.PayloadHasFederalService = entity.HasFederalService.Marshal()
}
if entity.List != nil {
entity.PayloadList = entity.List.Marshal()
}
return MarshalPayloadEntity("history.federal", entity)
}
// Valid checks the value(s) against an battery of tests.
func (entity *HistoryFederal) Valid() (bool, error) {
if entity.HasFederalService.Value == "No" {
return true, nil
}
return entity.List.Valid()
}
// ClearNoBranches clears any questions answered nos on a kickback
func (entity *HistoryFederal) ClearNoBranches() error {
entity.HasFederalService.ClearNo()
entity.List.ClearBranchNo()
return nil
}