-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.go
178 lines (152 loc) · 3.65 KB
/
user.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package s7_api_sdk
const (
PassengerTypeCodeAdult = "ADT"
PassengerTypeCodeChild = "CHD"
PassengerTypeCodeInfant = "INF"
)
type User struct {
ID string `xml:"ObjectKey,attr,omitempty"`
PTC *PTC
Age *Age `xml:",omitempty"`
Name *Name `xml:",omitempty"`
Contacts *Contacts `xml:",omitempty"`
FQTVs *FQTVs `xml:",omitempty"`
Gender string `xml:",omitempty"`
PassengerIDInfo *PassengerIDInfo `xml:",omitempty"`
Document *Document `xml:",omitempty"`
}
type PTC struct {
Quantity int `xml:",attr,omitempty"`
Value string `xml:",chardata"`
}
func MakePTC(qty int, passengerType string, qtyAdultChild, qtyInfant, qtyAdult *int) (ptc *PTC) {
if qty < 1 {
return
}
switch {
case passengerType != PassengerTypeCodeAdult &&
passengerType != PassengerTypeCodeChild &&
passengerType != PassengerTypeCodeInfant:
return
case qty > 9:
return
case passengerType == PassengerTypeCodeAdult:
*qtyAdultChild += qty
*qtyAdult += qty
case passengerType == PassengerTypeCodeChild:
*qtyAdultChild += qty
case passengerType == PassengerTypeCodeInfant:
*qtyInfant += qty
}
// switch {
// case *qtyAdultChild > 9:
// log.Println(1)
// return
// case *qtyInfant > *qtyAdult:
// log.Println(2)
// return
// }
ptc = &PTC{
Quantity: qty,
Value: passengerType,
}
return
}
type Age struct {
BirthDate string
}
func MakeAge(date string) *Age {
return &Age{
BirthDate: date,
}
}
type Name struct {
Surname string
Given string
Title string `xml:",omitempty"`
Middle string `xml:",omitempty"`
}
func MakeName(title, given, surname, middle string) *Name {
return &Name{
Title: title,
Given: given,
Surname: surname,
Middle: middle,
}
}
type Contacts struct {
Contact []*Contact
}
type Contact struct {
EmailContact *EmailContact `xml:",omitempty"`
PhoneContact *PhoneContact `xml:",omitempty"`
}
func MakeContact(email, countryCode, areaCode, phoneNumber string) *Contact {
var emailContact *EmailContact
if email != "" {
emailContact = &EmailContact{
Address: email,
}
}
var phoneContact *PhoneContact
if countryCode != "" && areaCode != "" && phoneNumber != "" {
phoneContact = &PhoneContact{
Number: PhoneNumber{
CountryCode: countryCode,
AreaCode: areaCode,
Number: phoneNumber,
},
}
}
return &Contact{
EmailContact: emailContact,
PhoneContact: phoneContact,
}
}
type EmailContact struct {
Address string
}
type PhoneContact struct {
Number PhoneNumber
}
type PhoneNumber struct {
CountryCode string `xml:",attr"`
AreaCode string `xml:",attr"`
Number string `xml:",chardata"`
}
type FQTVs struct {
TravelerFQTVInformation *TravelerFQTVInformation `xml:"TravelerFQTV_Information"`
}
type TravelerFQTVInformation struct {
AirlineID string `xml:",omitempty"`
Account *Account `xml:",omitempty"`
ProgramID string `xml:",omitempty"`
}
func MakeTravelerFQTVInformation(airlineID, account, programID string) *TravelerFQTVInformation {
return &TravelerFQTVInformation{
AirlineID: airlineID,
Account: &Account{
Number: account,
},
ProgramID: programID,
}
}
type Account struct {
Number string
}
type PassengerIDInfo struct {
PassengerDocument *PassengerDocument
}
type PassengerDocument struct {
Type string
ID string
BirthCountry string
DateOfIssue string
DateOfExpiration string
CountryOfResidence string
}
type Passengers struct {
Passenger []*User `xml:",omitempty"`
PassengerReference string `xml:",omitempty"`
PassengerReferences string `xml:",omitempty"`
}