This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
supervisor.go
89 lines (77 loc) · 2.33 KB
/
supervisor.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
package api
import "encoding/json"
// Supervisor is a basic input.
type Supervisor struct {
PayloadSupervisorName Payload `json:"SupervisorName" sql:"-"`
PayloadTitle Payload `json:"Title" sql:"-"`
PayloadEmail Payload `json:"Email" sql:"-"`
PayloadEmailNotApplicable Payload `json:"EmailNotApplicable" sql:"-"`
PayloadAddress Payload `json:"Address" sql:"-"`
PayloadTelephone Payload `json:"Telephone" sql:"-"`
SupervisorName *Text `json:"-"`
Title *Text `json:"-"`
Email *Email `json:"-"`
EmailNotApplicable *NotApplicable `json:"-"`
Address *Location `json:"-"`
Telephone *Telephone `json:"-"`
}
// Unmarshal bytes in to the entity properties.
func (entity *Supervisor) Unmarshal(raw []byte) error {
err := json.Unmarshal(raw, entity)
if err != nil {
return err
}
supervisorName, err := entity.PayloadSupervisorName.Entity()
if err != nil {
return err
}
entity.SupervisorName = supervisorName.(*Text)
title, err := entity.PayloadTitle.Entity()
if err != nil {
return err
}
entity.Title = title.(*Text)
email, err := entity.PayloadEmail.Entity()
if err != nil {
return err
}
entity.Email = email.(*Email)
emailNotApplicable, err := entity.PayloadEmailNotApplicable.Entity()
if err != nil {
return err
}
entity.EmailNotApplicable = emailNotApplicable.(*NotApplicable)
address, err := entity.PayloadAddress.Entity()
if err != nil {
return err
}
entity.Address = address.(*Location)
telephone, err := entity.PayloadTelephone.Entity()
if err != nil {
return err
}
entity.Telephone = telephone.(*Telephone)
return err
}
// Marshal to payload structure
func (entity *Supervisor) Marshal() Payload {
if entity.SupervisorName != nil {
entity.PayloadSupervisorName = entity.SupervisorName.Marshal()
}
if entity.Title != nil {
entity.PayloadTitle = entity.Title.Marshal()
}
if entity.Email != nil {
entity.PayloadEmail = entity.Email.Marshal()
}
if entity.EmailNotApplicable != nil {
entity.PayloadEmailNotApplicable = entity.EmailNotApplicable.Marshal()
}
if entity.Address != nil {
entity.PayloadAddress = entity.Address.Marshal()
}
if entity.Telephone != nil {
entity.PayloadTelephone = entity.Telephone.Marshal()
}
return MarshalPayloadEntity("supervisor", entity)
}