-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscription_note.go
96 lines (89 loc) · 3.23 KB
/
subscription_note.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
package models
import (
"encoding/json"
"log"
"time"
)
// SubscriptionNote represents a SubscriptionNote struct.
type SubscriptionNote struct {
Id *int `json:"id,omitempty"`
Body *string `json:"body,omitempty"`
SubscriptionId *int `json:"subscription_id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Sticky *bool `json:"sticky,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for SubscriptionNote.
// It customizes the JSON marshaling process for SubscriptionNote objects.
func (s SubscriptionNote) MarshalJSON() (
[]byte,
error) {
return json.Marshal(s.toMap())
}
// toMap converts the SubscriptionNote object to a map representation for JSON marshaling.
func (s SubscriptionNote) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, s.AdditionalProperties)
if s.Id != nil {
structMap["id"] = s.Id
}
if s.Body != nil {
structMap["body"] = s.Body
}
if s.SubscriptionId != nil {
structMap["subscription_id"] = s.SubscriptionId
}
if s.CreatedAt != nil {
structMap["created_at"] = s.CreatedAt.Format(time.RFC3339)
}
if s.UpdatedAt != nil {
structMap["updated_at"] = s.UpdatedAt.Format(time.RFC3339)
}
if s.Sticky != nil {
structMap["sticky"] = s.Sticky
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for SubscriptionNote.
// It customizes the JSON unmarshaling process for SubscriptionNote objects.
func (s *SubscriptionNote) UnmarshalJSON(input []byte) error {
var temp subscriptionNote
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "id", "body", "subscription_id", "created_at", "updated_at", "sticky")
if err != nil {
return err
}
s.AdditionalProperties = additionalProperties
s.Id = temp.Id
s.Body = temp.Body
s.SubscriptionId = temp.SubscriptionId
if temp.CreatedAt != nil {
CreatedAtVal, err := time.Parse(time.RFC3339, *temp.CreatedAt)
if err != nil {
log.Fatalf("Cannot Parse created_at as % s format.", time.RFC3339)
}
s.CreatedAt = &CreatedAtVal
}
if temp.UpdatedAt != nil {
UpdatedAtVal, err := time.Parse(time.RFC3339, *temp.UpdatedAt)
if err != nil {
log.Fatalf("Cannot Parse updated_at as % s format.", time.RFC3339)
}
s.UpdatedAt = &UpdatedAtVal
}
s.Sticky = temp.Sticky
return nil
}
// subscriptionNote is a temporary struct used for validating the fields of SubscriptionNote.
type subscriptionNote struct {
Id *int `json:"id,omitempty"`
Body *string `json:"body,omitempty"`
SubscriptionId *int `json:"subscription_id,omitempty"`
CreatedAt *string `json:"created_at,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
Sticky *bool `json:"sticky,omitempty"`
}