forked from microsoftgraph/msgraph-sdk-go-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_response_model.go
77 lines (65 loc) · 2.07 KB
/
batch_response_model.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
package msgraphgocore
import (
"github.com/microsoft/kiota-abstractions-go/serialization"
)
type batchResponse struct {
responses []BatchItem
indexResponse map[string]BatchItem
isIndexed bool
}
// GetResponses returns a slice of BatchItem to the user
func (br *batchResponse) GetResponses() []BatchItem {
return br.responses
}
// SetResponses adds a slice of BatchItem to the response
func (br *batchResponse) SetResponses(responses []BatchItem) {
br.responses = responses
}
// GetResponseById returns a response payload as a batch item
func (br *batchResponse) GetResponseById(itemId string) BatchItem {
if !br.isIndexed {
for _, resp := range br.GetResponses() {
br.indexResponse[*(resp.GetId())] = resp
}
br.isIndexed = true
}
return br.indexResponse[itemId]
}
// CreateBatchResponseDiscriminator creates a new instance of the appropriate class based on discriminator value
func CreateBatchResponseDiscriminator(serialization.ParseNode) (serialization.Parsable, error) {
res := batchResponse{
indexResponse: make(map[string]BatchItem),
isIndexed: false,
}
return &res, nil
}
// BatchResponse instance of batch request result payload
type BatchResponse interface {
serialization.Parsable
GetResponses() []BatchItem
SetResponses(responses []BatchItem)
GetResponseById(itemId string) BatchItem
}
// Serialize serializes information the current object
func (br *batchResponse) Serialize(serialization.SerializationWriter) error {
panic("batch responses are not serializable")
}
// GetFieldDeserializers the deserialization information for the current model
func (br *batchResponse) GetFieldDeserializers() map[string]func(serialization.ParseNode) error {
res := make(map[string]func(serialization.ParseNode) error)
res["responses"] = func(n serialization.ParseNode) error {
val, err := n.GetCollectionOfObjectValues(CreateBatchRequestItemDiscriminator)
if err != nil {
return err
}
if val != nil {
res := make([]BatchItem, len(val))
for i, v := range val {
res[i] = v.(BatchItem)
}
br.SetResponses(res)
}
return nil
}
return res
}