forked from labd/commercetools-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_review.go
430 lines (387 loc) · 12.5 KB
/
types_review.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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
// Automatically generated, do not edit
package commercetools
import (
"encoding/json"
"errors"
"time"
)
// ReviewUpdateAction uses action as discriminator attribute
type ReviewUpdateAction interface{}
func mapDiscriminatorReviewUpdateAction(input interface{}) (ReviewUpdateAction, error) {
var discriminator string
if data, ok := input.(map[string]interface{}); ok {
discriminator, ok = data["action"].(string)
if !ok {
return nil, errors.New("Error processing discriminator field 'action'")
}
} else {
return nil, errors.New("Invalid data")
}
switch discriminator {
case "setAuthorName":
new := ReviewSetAuthorNameAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setCustomField":
new := ReviewSetCustomFieldAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setCustomType":
new := ReviewSetCustomTypeAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setCustomer":
new := ReviewSetCustomerAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setKey":
new := ReviewSetKeyAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setLocale":
new := ReviewSetLocaleAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setRating":
new := ReviewSetRatingAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setTarget":
new := ReviewSetTargetAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
if new.Target != nil {
new.Target, err = mapDiscriminatorResourceIdentifier(new.Target)
if err != nil {
return nil, err
}
}
return new, nil
case "setText":
new := ReviewSetTextAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "setTitle":
new := ReviewSetTitleAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
case "transitionState":
new := ReviewTransitionStateAction{}
err := decodeStruct(input, &new)
if err != nil {
return nil, err
}
return new, nil
}
return nil, nil
}
// Review is of type BaseResource
type Review struct {
Version int `json:"version"`
UniquenessValue string `json:"uniquenessValue,omitempty"`
Title string `json:"title,omitempty"`
Text string `json:"text,omitempty"`
Target Reference `json:"target,omitempty"`
State *StateReference `json:"state,omitempty"`
Rating float64 `json:"rating,omitempty"`
Locale string `json:"locale,omitempty"`
LastModifiedBy *LastModifiedBy `json:"lastModifiedBy,omitempty"`
LastModifiedAt time.Time `json:"lastModifiedAt"`
Key string `json:"key,omitempty"`
IncludedInStatistics bool `json:"includedInStatistics"`
ID string `json:"id"`
Customer *CustomerReference `json:"customer,omitempty"`
Custom *CustomFields `json:"custom,omitempty"`
CreatedBy *CreatedBy `json:"createdBy,omitempty"`
CreatedAt time.Time `json:"createdAt"`
AuthorName string `json:"authorName,omitempty"`
}
// UnmarshalJSON override to deserialize correct attribute types based
// on the discriminator value
func (obj *Review) UnmarshalJSON(data []byte) error {
type Alias Review
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil {
return err
}
if obj.Target != nil {
var err error
obj.Target, err = mapDiscriminatorReference(obj.Target)
if err != nil {
return err
}
}
return nil
}
// ReviewDraft is a standalone struct
type ReviewDraft struct {
UniquenessValue string `json:"uniquenessValue,omitempty"`
Title string `json:"title,omitempty"`
Text string `json:"text,omitempty"`
Target ResourceIdentifier `json:"target,omitempty"`
State *StateResourceIdentifier `json:"state,omitempty"`
Rating float64 `json:"rating,omitempty"`
Locale string `json:"locale,omitempty"`
Key string `json:"key,omitempty"`
Customer *CustomerResourceIdentifier `json:"customer,omitempty"`
Custom *CustomFieldsDraft `json:"custom,omitempty"`
AuthorName string `json:"authorName,omitempty"`
}
// UnmarshalJSON override to deserialize correct attribute types based
// on the discriminator value
func (obj *ReviewDraft) UnmarshalJSON(data []byte) error {
type Alias ReviewDraft
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil {
return err
}
if obj.Target != nil {
var err error
obj.Target, err = mapDiscriminatorResourceIdentifier(obj.Target)
if err != nil {
return err
}
}
return nil
}
// ReviewPagedQueryResponse is a standalone struct
type ReviewPagedQueryResponse struct {
Total int `json:"total,omitempty"`
Results []Review `json:"results"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Count int `json:"count"`
}
// ReviewRatingStatistics is a standalone struct
type ReviewRatingStatistics struct {
RatingsDistribution interface{} `json:"ratingsDistribution"`
LowestRating float64 `json:"lowestRating"`
HighestRating float64 `json:"highestRating"`
Count int `json:"count"`
AverageRating float64 `json:"averageRating"`
}
// ReviewReference implements the interface Reference
type ReviewReference struct {
ID string `json:"id"`
Obj *Review `json:"obj,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewReference) MarshalJSON() ([]byte, error) {
type Alias ReviewReference
return json.Marshal(struct {
TypeID string `json:"typeId"`
*Alias
}{TypeID: "review", Alias: (*Alias)(&obj)})
}
// ReviewResourceIdentifier implements the interface ResourceIdentifier
type ReviewResourceIdentifier struct {
Key string `json:"key,omitempty"`
ID string `json:"id,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewResourceIdentifier) MarshalJSON() ([]byte, error) {
type Alias ReviewResourceIdentifier
return json.Marshal(struct {
TypeID string `json:"typeId"`
*Alias
}{TypeID: "review", Alias: (*Alias)(&obj)})
}
// ReviewSetAuthorNameAction implements the interface ReviewUpdateAction
type ReviewSetAuthorNameAction struct {
AuthorName string `json:"authorName,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetAuthorNameAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetAuthorNameAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setAuthorName", Alias: (*Alias)(&obj)})
}
// ReviewSetCustomFieldAction implements the interface ReviewUpdateAction
type ReviewSetCustomFieldAction struct {
Value interface{} `json:"value,omitempty"`
Name string `json:"name"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetCustomFieldAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetCustomFieldAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setCustomField", Alias: (*Alias)(&obj)})
}
// ReviewSetCustomTypeAction implements the interface ReviewUpdateAction
type ReviewSetCustomTypeAction struct {
Type *TypeResourceIdentifier `json:"type,omitempty"`
Fields *FieldContainer `json:"fields,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetCustomTypeAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetCustomTypeAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setCustomType", Alias: (*Alias)(&obj)})
}
// ReviewSetCustomerAction implements the interface ReviewUpdateAction
type ReviewSetCustomerAction struct {
Customer *CustomerResourceIdentifier `json:"customer,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetCustomerAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetCustomerAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setCustomer", Alias: (*Alias)(&obj)})
}
// ReviewSetKeyAction implements the interface ReviewUpdateAction
type ReviewSetKeyAction struct {
Key string `json:"key,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetKeyAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetKeyAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setKey", Alias: (*Alias)(&obj)})
}
// ReviewSetLocaleAction implements the interface ReviewUpdateAction
type ReviewSetLocaleAction struct {
Locale string `json:"locale,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetLocaleAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetLocaleAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setLocale", Alias: (*Alias)(&obj)})
}
// ReviewSetRatingAction implements the interface ReviewUpdateAction
type ReviewSetRatingAction struct {
Rating float64 `json:"rating,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetRatingAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetRatingAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setRating", Alias: (*Alias)(&obj)})
}
// ReviewSetTargetAction implements the interface ReviewUpdateAction
type ReviewSetTargetAction struct {
Target ResourceIdentifier `json:"target"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetTargetAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetTargetAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setTarget", Alias: (*Alias)(&obj)})
}
// UnmarshalJSON override to deserialize correct attribute types based
// on the discriminator value
func (obj *ReviewSetTargetAction) UnmarshalJSON(data []byte) error {
type Alias ReviewSetTargetAction
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil {
return err
}
if obj.Target != nil {
var err error
obj.Target, err = mapDiscriminatorResourceIdentifier(obj.Target)
if err != nil {
return err
}
}
return nil
}
// ReviewSetTextAction implements the interface ReviewUpdateAction
type ReviewSetTextAction struct {
Text string `json:"text,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetTextAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetTextAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setText", Alias: (*Alias)(&obj)})
}
// ReviewSetTitleAction implements the interface ReviewUpdateAction
type ReviewSetTitleAction struct {
Title string `json:"title,omitempty"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewSetTitleAction) MarshalJSON() ([]byte, error) {
type Alias ReviewSetTitleAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "setTitle", Alias: (*Alias)(&obj)})
}
// ReviewTransitionStateAction implements the interface ReviewUpdateAction
type ReviewTransitionStateAction struct {
State *StateResourceIdentifier `json:"state"`
Force bool `json:"force"`
}
// MarshalJSON override to set the discriminator value
func (obj ReviewTransitionStateAction) MarshalJSON() ([]byte, error) {
type Alias ReviewTransitionStateAction
return json.Marshal(struct {
Action string `json:"action"`
*Alias
}{Action: "transitionState", Alias: (*Alias)(&obj)})
}
// ReviewUpdate is a standalone struct
type ReviewUpdate struct {
Version int `json:"version"`
Actions []ReviewUpdateAction `json:"actions"`
}
// UnmarshalJSON override to deserialize correct attribute types based
// on the discriminator value
func (obj *ReviewUpdate) UnmarshalJSON(data []byte) error {
type Alias ReviewUpdate
if err := json.Unmarshal(data, (*Alias)(obj)); err != nil {
return err
}
for i := range obj.Actions {
var err error
obj.Actions[i], err = mapDiscriminatorReviewUpdateAction(obj.Actions[i])
if err != nil {
return err
}
}
return nil
}