forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateOrderItemRequest.go
47 lines (41 loc) · 1.05 KB
/
updateOrderItemRequest.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
package models
import (
"encoding/json"
)
// Update Order item Request
type UpdateOrderItemRequest struct {
Amount int `json:"amount"`
Description string `json:"description"`
Quantity int `json:"quantity"`
Category string `json:"category"`
}
func (u *UpdateOrderItemRequest) MarshalJSON() (
[]byte,
error) {
return json.Marshal(u.toMap())
}
func (u *UpdateOrderItemRequest) toMap() map[string]any {
structMap := make(map[string]any)
structMap["amount"] = u.Amount
structMap["description"] = u.Description
structMap["quantity"] = u.Quantity
structMap["category"] = u.Category
return structMap
}
func (u *UpdateOrderItemRequest) UnmarshalJSON(input []byte) error {
temp := &struct {
Amount int `json:"amount"`
Description string `json:"description"`
Quantity int `json:"quantity"`
Category string `json:"category"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
u.Amount = temp.Amount
u.Description = temp.Description
u.Quantity = temp.Quantity
u.Category = temp.Category
return nil
}