mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
48 lines
902 B
Go
48 lines
902 B
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type Schedule struct {
|
|
ID string
|
|
ConnectorID ConnectorID
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (s Schedule) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(&struct {
|
|
ID string `json:"id"`
|
|
ConnectorID string `json:"connectorID"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
}{
|
|
ID: s.ID,
|
|
ConnectorID: s.ConnectorID.String(),
|
|
CreatedAt: s.CreatedAt,
|
|
})
|
|
}
|
|
|
|
func (s *Schedule) UnmarshalJSON(data []byte) error {
|
|
var aux struct {
|
|
ID string `json:"id"`
|
|
ConnectorID string `json:"connectorID"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &aux); err != nil {
|
|
return err
|
|
}
|
|
|
|
connectorID, err := ConnectorIDFromString(aux.ConnectorID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
s.ID = aux.ID
|
|
s.ConnectorID = connectorID
|
|
s.CreatedAt = aux.CreatedAt
|
|
|
|
return nil
|
|
}
|