Skip to content

Commit 3a8d88e

Browse files
committed
search complete
1 parent c9b4a60 commit 3a8d88e

30 files changed

+3416
-204
lines changed

configuration/config.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package configuration
2+
3+
import (
4+
"encoding/base64"
5+
"log"
6+
"os"
7+
8+
"github.com/microparts/configuration-golang"
9+
"github.com/microparts/errors-go"
10+
"github.com/microparts/logs-go"
11+
"gopkg.in/yaml.v2"
12+
)
13+
14+
type connectionConfig struct {
15+
URL string `yaml:"url"`
16+
WSAP string `yaml:"wsap"`
17+
Originator string `yaml:"originator"`
18+
Password string `yaml:"password"`
19+
PasswordRaw string
20+
PinCode string `yaml:"pin_code"`
21+
VatURL string `yaml:"vat_url"`
22+
VatSOAPURL string `yaml:"vat_soap_url"`
23+
VatOfficeID string `yaml:"vat_office_id"`
24+
VatSign string `yaml:"vat_sign"`
25+
}
26+
27+
type amadeusConfig struct {
28+
Connection connectionConfig `yaml:"connection"`
29+
MaxRecommendations int `yaml:"max_recommendations"`
30+
}
31+
32+
type httpConfig struct {
33+
Host string `yaml:"host"`
34+
Port string `yaml:"port"`
35+
}
36+
37+
type formatsConfig struct {
38+
Time string `yaml:"time"`
39+
Date string `yaml:"date"`
40+
XMLDate string `yaml:"xml_date"`
41+
}
42+
43+
// CfgType service config structure
44+
type CfgType struct {
45+
Amadeus amadeusConfig `yaml:"amadeus"`
46+
HTTP httpConfig `yaml:"http"`
47+
Formats formatsConfig `yaml:"formats"`
48+
Queue queueConfig `yaml:"queue"`
49+
Log *logs.Config `yaml:"log"`
50+
Settings SettingsConfig `yaml:"settings"`
51+
Notifications NotificationsConfig `yaml:"notifications"`
52+
}
53+
54+
type queueConfig struct {
55+
PubSub PubSubConfig `yaml:"pubsub"`
56+
}
57+
58+
// PubSubConfig PubSub Config
59+
type PubSubConfig struct {
60+
Host string `yaml:"host"`
61+
ProjectID string `yaml:"project_id"`
62+
Topic string `yaml:"topic"`
63+
Subscription string `yaml:"subscription"`
64+
Key string `yaml:"key"`
65+
}
66+
67+
// SettingsConfig Settings Config
68+
type SettingsConfig struct {
69+
FoidRequreAirlines []string `yaml:"foid_require_airlines"`
70+
RemoveDuplicateAirlines bool `yaml:"remove_duplicate_airlines"`
71+
MaxAttemptsCancelVoid int `yaml:"max_attempts_cancel_void"`
72+
MaxAttemptsDocIssuance int `yaml:"max_attempts_doc_issuance"`
73+
MaxAttemptsPNRRET int `yaml:"max_attempts_pnr_ret"`
74+
MaxAttemptsPNRADD int `yaml:"max_attempts_pnr_add"`
75+
IssueExpire int `yaml:"issue_expire"`
76+
BookingRequestsDelay int `yaml:"booking_requests_delay"`
77+
IssueRequestsDelay int `yaml:"issue_requests_delay"`
78+
FareRulesParagraphsToShow []string `yaml:"fare_rules_paragraphs_to_show"`
79+
FareQualifierList []string `yaml:"fare_qualifier_list"`
80+
}
81+
82+
type NotificationsConfig struct {
83+
ErrorMessageEmail string `yaml:"error_message_email"`
84+
MailFrom string `yaml:"mail_from"`
85+
Queue PubSubConfig `yaml:"pubsub"`
86+
}
87+
88+
var (
89+
// Provider is current service
90+
Provider = "amadeus"
91+
)
92+
93+
var Config *CfgType
94+
95+
// InitConfig initialize config data
96+
func InitConfig() error {
97+
configPath := config.GetEnv("CONFIG_PATH", "")
98+
configBytes, err := config.ReadConfigs(configPath)
99+
if errors.HasErrors(err) {
100+
log.Printf("[config] read error: %+v", err)
101+
return err
102+
}
103+
104+
err = yaml.Unmarshal(configBytes, &Config)
105+
if errors.HasErrors(err) {
106+
log.Printf("[config] unmarshal error for bytes: %+v", configBytes)
107+
return err
108+
}
109+
//
110+
// structs.TimeFormat = func() string {
111+
// return Config.Formats.Time
112+
// }
113+
//
114+
// structs.DateFormat = func() string {
115+
// return Config.Formats.Date
116+
// }
117+
118+
if pwdBytes, err := base64.StdEncoding.DecodeString(Config.Amadeus.Connection.Password); err == nil {
119+
Config.Amadeus.Connection.PasswordRaw = string(pwdBytes)
120+
} else {
121+
log.Println("Error decoding password. Is it not encrypted in bass64?")
122+
os.Exit(-1)
123+
}
124+
125+
return nil
126+
}

configuration/defaults/formats.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
formats:
3+
time: "2006-01-02T15:04:05"
4+
date: "2006-01-02"

configuration/defaults/http.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults:
2+
http:
3+
host: "localhost"
4+
port: "8080"

configuration/defaults/log.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defaults:
2+
log:
3+
level: "error"
4+
format: "json"
5+
sentry:
6+
enable: true
7+
dsn: "https://924c371cd88d44759b1c7d282d1b1105:[email protected]/1364865"
8+
stackTrace:
9+
enable: true
10+
context: 0
11+
skip: 0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defaults:
2+
notifications:
3+
error_message_email: "[email protected]"
4+
mail_from: "[email protected]"
5+
pubsub:
6+
host: "localhost:8085" # for local pub/sup "localhost:8085"
7+
project_id: "tmconsulting24"
8+
topic: "notification-dev"
9+
subscription: "notification-receiver-dev"
10+
key: ""

configuration/defaults/queue.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defaults:
2+
queue:
3+
kind: "pubsub" # pubsub, redis, ...
4+
pubsub:
5+
host: "localhost:8085" # for local pub/sup "localhost:8085"
6+
project_id: "tmconsulting24"
7+
topic: "provider-logs-dev"
8+
subscription: "provider-logs-receiver-dev"
9+
key: ""
10+
redis:
11+
host: ""

configuration/defaults/settings.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defaults:
2+
settings:
3+
foid_require_airlines: ["2B","5N","7J","7R","8Q","BT","EY","FZ","HR","HY","J2","KC","KK","KR","LY","NN","PC","PS","QN","R2","R3","S7","SZ","U6","UT","VV","Y7","YC","YK","YQ","ZG"]
4+
remove_duplicate_airlines: false
5+
max_attempts_cancel_void: 5 # количество раз, которые система пробует отменить бронирование. каждая попытка предваряется sleep(attempt*seconds)
6+
max_attempts_doc_issuance: 5 # количество раз, которые система пробует выписать билет. каждая попытка предваряется sleep(attempt*seconds)
7+
max_attempts_pnr_ret: 5 # количество раз, которые система пробует сделать PNRRET. каждая попытка предваряется sleep(attempt*seconds)
8+
max_attempts_pnr_add: 5 # количество раз, которые система пробует сделать PNRADD. каждая попытка предваряется sleep(attempt*seconds)
9+
issue_expire: 30 # time in minutes, set TK XL time in minutes before departure
10+
booking_requests_delay: 2 # время задержки между запросами букинг
11+
issue_requests_delay: 0 # время задержки между запросами выписки
12+
fare_rules_paragraphs_to_show: ["PE", "CD"] # PE (16)-penalties, CD (19)-Children discounts
13+
fare_qualifier_list: ["P", "U"] # список fareQualifier, с которыми попытаются забронироваться

service/10_search.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
//"github.com/tmconsulting/amadeus-golang-sdk/structs/fare/masterPricerTravelBoardSearch/v14.3/response"
1212
)
1313

14-
func (s *service) FareMasterPricerTravelBoardSearch(query *search.Request) (*search.Response, *client.ResponseSOAPHeader, error) {
14+
func (s *service) FareMasterPricerTravelBoardSearch(query *search.SearchRequest) (*search.SearchResponse, *client.ResponseSOAPHeader, error) {
1515
switch s.mm[FareMasterPricerTravelBoardSearch] {
1616
case FareMasterPricerTravelBoardSearchV143:
17-
query := Fare_MasterPricerTravelBoardSearchRequest_v14_3.MakeRequest(query)
18-
response, header, err := s.sdk.FareMasterPricerTravelBoardSearchV143(query)
17+
request := Fare_MasterPricerTravelBoardSearchRequest_v14_3.MakeRequest(query)
18+
response, header, err := s.sdk.FareMasterPricerTravelBoardSearchV143(request)
1919
if response == nil {
2020
return nil, header, err
2121
}
@@ -25,7 +25,8 @@ func (s *service) FareMasterPricerTravelBoardSearch(query *search.Request) (*sea
2525
return nil, header, errResponse
2626
}
2727

28-
return response.ToCommon(), header, err
28+
reply, err := response.ToCommon(query)
29+
return reply, header, err
2930
}
3031
return nil, nil, nil
3132
}

service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type Service interface {
135135
CloseSession() (reply *SecuritySignOut_v04_1.Response, err error)
136136

137137
// Search
138-
FareMasterPricerTravelBoardSearch(query *search.Request) (*search.Response, *client.ResponseSOAPHeader, error)
138+
FareMasterPricerTravelBoardSearch(query *search.SearchRequest) (*search.SearchResponse, *client.ResponseSOAPHeader, error)
139139
FareInformativeBestPricingWithout(query *Fare_InformativeBestPricingWithoutPNRRequest_v12_4.Request) (*Fare_InformativeBestPricingWithoutPNRResponse_v12_4.Response, *client.ResponseSOAPHeader, error)
140140
FareInformativePricingWithoutPNR(query *Fare_InformativePricingWithoutPNR_v12_4.Request) (*Fare_InformativePricingWithoutPNRReply_v12_4.Response, *client.ResponseSOAPHeader, error)
141141

service/service_test.go

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package service
22

33
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/tmconsulting/amadeus-golang-sdk/configuration"
7+
"github.com/tmconsulting/amadeus-golang-sdk/structs"
48
search "github.com/tmconsulting/amadeus-golang-sdk/structs/fare/masterPricerTravelBoardSearch"
59
"github.com/tmconsulting/amadeus-golang-sdk/structs/pnr/retrieve"
610
"log"
@@ -83,26 +87,71 @@ func TestNewSKD(t *testing.T) {
8387

8488
t.Run("Search test", func(t *testing.T) {
8589

90+
tearUp()
91+
92+
err := configuration.InitConfig()
93+
if err != nil {
94+
t.FailNow()
95+
}
96+
97+
//url = configuration.Config.Amadeus.Connection.URL
98+
//originator = configuration.Config.Amadeus.Connection.Originator
99+
//passwordRaw = configuration.Config.Amadeus.Connection.PasswordRaw
100+
//officeId = "MOWR228FG"
101+
86102
cl := client.New(client.SetURL(url), client.SetUser(originator), client.SetPassword(passwordRaw), client.SetAgent(officeId), client.SetLogger(stdOutLog))
87103

88104
amadeusSDK := New(cl)
89105
//amadeusSDK := New(cl, SetMethodVersion(PNRAddMultiElements, MethodVersion(PNRRetrieveV113)))
90106

91-
request := search.Request{
107+
itinerary := structs.Itinerary{
108+
DepartureLocation: structs.Location{
109+
AirportCode: "SVO",
110+
CityCode: "MOW",
111+
CountryCode: "RU",
112+
Type: "city",
113+
},
114+
ArrivalLocation: structs.Location{
115+
AirportCode: "LED",
116+
CityCode: "LED",
117+
CountryCode: "RU",
118+
Type: "city",
119+
},
120+
}
121+
request := search.SearchRequest{
122+
ClientData: structs.ClientInfo{
123+
OfficeID: "MOWR224PW",
124+
},
125+
BaseClass: []string{
126+
"E",
127+
},
128+
Changes: false,
129+
WithBaggage: true,
130+
TravelType: "OW",
92131
Itineraries: map[int]*search.Itinerary{
93132
1: {
94-
DepartureLocation: "MOW",
95-
ArrivalLocation: "LED",
96-
DepartureDate: time.Now().Add(10 * 24 * time.Hour), // add 10 days
133+
Itinerary: &itinerary,
134+
DepartureDate: structs.FlightDateTime{
135+
Date: time.Now().Add(10 * 24 * time.Hour), // add 10 days
136+
},
137+
DepartureDateTill: structs.FlightDateTimeUniversal{
138+
DateStr: time.Now().Add(11 * 24 * time.Hour).String(), // add 10 days
139+
},
97140
},
98141
},
99142
Currency: "RUB",
100-
Passengers: search.Travellers{ADT: 2, CHD: 1, INF: 1},
143+
Passengers: structs.Travellers{ADT: 1, CHD: 0, INF: 0},
144+
Airlines: []string{
145+
"SU",
146+
},
101147
}
102148

103149
response, _, err := amadeusSDK.FareMasterPricerTravelBoardSearch(&request)
104150
t.Logf("response: %+v\n", response)
105151

152+
aa, _ := json.Marshal(response)
153+
fmt.Println("Search response: ", string(aa))
154+
106155
if !assert.NoError(t, err) {
107156
t.FailNow()
108157
}

structs/airline.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package structs
2+
3+
// Airline structure
4+
type Airline struct {
5+
CodeEng string `json:"code_eng" bson:"codeEng"`
6+
CodeRus string `json:"code_rus,omitempty" bson:"codeRus,omitempty"`
7+
NameEng string `json:"name_eng,omitempty" bson:"nameEng,omitempty"`
8+
NameRus string `json:"name_rus,omitempty" bson:"nameRus,omitempty"`
9+
}
10+
11+
// Aircraft structure
12+
type Aircraft struct {
13+
Code *string `json:"code" db:"code" bson:"code"`
14+
Name map[string]string `json:"name,omitempty" db:"name" bson:"name,omitempty"`
15+
}

structs/baggage.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package structs
2+
3+
// BaggageType structure
4+
type BaggageType struct {
5+
Value int `json:"value"`
6+
Unit string `json:"unit"`
7+
}

structs/clientInfo.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package structs
2+
3+
import (
4+
"encoding/json"
5+
)
6+
7+
// ClientInfo customer info structure
8+
type ClientInfo struct {
9+
OfficeID string `json:"office_id"`
10+
Timezone string `json:"timezone"`
11+
}
12+
13+
// UnmarshalJSON overrides UnmarshalJSON
14+
func (c *ClientInfo) UnmarshalJSON(data []byte) error {
15+
type ClientInfo2 struct {
16+
Var1 string `json:"amadeus_office_id"`
17+
Var2 string `json:"office_id"`
18+
}
19+
var clientInfo ClientInfo2
20+
if err := json.Unmarshal(data, &clientInfo); err != nil {
21+
//logs.Log.WithError(err).Error("Error unmarshal json")
22+
return err
23+
}
24+
var OfficeID = ""
25+
if clientInfo.Var1 != "" {
26+
OfficeID = clientInfo.Var1
27+
} else {
28+
OfficeID = clientInfo.Var2
29+
}
30+
c.OfficeID = OfficeID
31+
return nil
32+
}

structs/errorStructs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package structs
2+
3+
// ErrorReply Error Reply structure
4+
type ErrorReply struct {
5+
Status string `json:"status,omitempty"`
6+
ErrorCode string `json:"code,omitempty"`
7+
Message string `json:"message,omitempty"`
8+
}

0 commit comments

Comments
 (0)