Skip to content

Commit

Permalink
search complete
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkadyrov committed Sep 27, 2019
1 parent c9b4a60 commit 3a8d88e
Show file tree
Hide file tree
Showing 30 changed files with 3,416 additions and 204 deletions.
126 changes: 126 additions & 0 deletions configuration/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package configuration

import (
"encoding/base64"
"log"
"os"

"github.com/microparts/configuration-golang"
"github.com/microparts/errors-go"
"github.com/microparts/logs-go"
"gopkg.in/yaml.v2"
)

type connectionConfig struct {
URL string `yaml:"url"`
WSAP string `yaml:"wsap"`
Originator string `yaml:"originator"`
Password string `yaml:"password"`
PasswordRaw string
PinCode string `yaml:"pin_code"`
VatURL string `yaml:"vat_url"`
VatSOAPURL string `yaml:"vat_soap_url"`
VatOfficeID string `yaml:"vat_office_id"`
VatSign string `yaml:"vat_sign"`
}

type amadeusConfig struct {
Connection connectionConfig `yaml:"connection"`
MaxRecommendations int `yaml:"max_recommendations"`
}

type httpConfig struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
}

type formatsConfig struct {
Time string `yaml:"time"`
Date string `yaml:"date"`
XMLDate string `yaml:"xml_date"`
}

// CfgType service config structure
type CfgType struct {
Amadeus amadeusConfig `yaml:"amadeus"`
HTTP httpConfig `yaml:"http"`
Formats formatsConfig `yaml:"formats"`
Queue queueConfig `yaml:"queue"`
Log *logs.Config `yaml:"log"`
Settings SettingsConfig `yaml:"settings"`
Notifications NotificationsConfig `yaml:"notifications"`
}

type queueConfig struct {
PubSub PubSubConfig `yaml:"pubsub"`
}

// PubSubConfig PubSub Config
type PubSubConfig struct {
Host string `yaml:"host"`
ProjectID string `yaml:"project_id"`
Topic string `yaml:"topic"`
Subscription string `yaml:"subscription"`
Key string `yaml:"key"`
}

// SettingsConfig Settings Config
type SettingsConfig struct {
FoidRequreAirlines []string `yaml:"foid_require_airlines"`
RemoveDuplicateAirlines bool `yaml:"remove_duplicate_airlines"`
MaxAttemptsCancelVoid int `yaml:"max_attempts_cancel_void"`
MaxAttemptsDocIssuance int `yaml:"max_attempts_doc_issuance"`
MaxAttemptsPNRRET int `yaml:"max_attempts_pnr_ret"`
MaxAttemptsPNRADD int `yaml:"max_attempts_pnr_add"`
IssueExpire int `yaml:"issue_expire"`
BookingRequestsDelay int `yaml:"booking_requests_delay"`
IssueRequestsDelay int `yaml:"issue_requests_delay"`
FareRulesParagraphsToShow []string `yaml:"fare_rules_paragraphs_to_show"`
FareQualifierList []string `yaml:"fare_qualifier_list"`
}

type NotificationsConfig struct {
ErrorMessageEmail string `yaml:"error_message_email"`
MailFrom string `yaml:"mail_from"`
Queue PubSubConfig `yaml:"pubsub"`
}

var (
// Provider is current service
Provider = "amadeus"
)

var Config *CfgType

// InitConfig initialize config data
func InitConfig() error {
configPath := config.GetEnv("CONFIG_PATH", "")
configBytes, err := config.ReadConfigs(configPath)
if errors.HasErrors(err) {
log.Printf("[config] read error: %+v", err)
return err
}

err = yaml.Unmarshal(configBytes, &Config)
if errors.HasErrors(err) {
log.Printf("[config] unmarshal error for bytes: %+v", configBytes)
return err
}
//
// structs.TimeFormat = func() string {
// return Config.Formats.Time
// }
//
// structs.DateFormat = func() string {
// return Config.Formats.Date
// }

if pwdBytes, err := base64.StdEncoding.DecodeString(Config.Amadeus.Connection.Password); err == nil {
Config.Amadeus.Connection.PasswordRaw = string(pwdBytes)
} else {
log.Println("Error decoding password. Is it not encrypted in bass64?")
os.Exit(-1)
}

return nil
}
4 changes: 4 additions & 0 deletions configuration/defaults/formats.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults:
formats:
time: "2006-01-02T15:04:05"
date: "2006-01-02"
4 changes: 4 additions & 0 deletions configuration/defaults/http.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults:
http:
host: "localhost"
port: "8080"
11 changes: 11 additions & 0 deletions configuration/defaults/log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defaults:
log:
level: "error"
format: "json"
sentry:
enable: true
dsn: "https://924c371cd88d44759b1c7d282d1b1105:[email protected]/1364865"
stackTrace:
enable: true
context: 0
skip: 0
10 changes: 10 additions & 0 deletions configuration/defaults/notifications.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defaults:
notifications:
error_message_email: "[email protected]"
mail_from: "[email protected]"
pubsub:
host: "localhost:8085" # for local pub/sup "localhost:8085"
project_id: "tmconsulting24"
topic: "notification-dev"
subscription: "notification-receiver-dev"
key: ""
11 changes: 11 additions & 0 deletions configuration/defaults/queue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defaults:
queue:
kind: "pubsub" # pubsub, redis, ...
pubsub:
host: "localhost:8085" # for local pub/sup "localhost:8085"
project_id: "tmconsulting24"
topic: "provider-logs-dev"
subscription: "provider-logs-receiver-dev"
key: ""
redis:
host: ""
13 changes: 13 additions & 0 deletions configuration/defaults/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defaults:
settings:
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"]
remove_duplicate_airlines: false
max_attempts_cancel_void: 5 # количество раз, которые система пробует отменить бронирование. каждая попытка предваряется sleep(attempt*seconds)
max_attempts_doc_issuance: 5 # количество раз, которые система пробует выписать билет. каждая попытка предваряется sleep(attempt*seconds)
max_attempts_pnr_ret: 5 # количество раз, которые система пробует сделать PNRRET. каждая попытка предваряется sleep(attempt*seconds)
max_attempts_pnr_add: 5 # количество раз, которые система пробует сделать PNRADD. каждая попытка предваряется sleep(attempt*seconds)
issue_expire: 30 # time in minutes, set TK XL time in minutes before departure
booking_requests_delay: 2 # время задержки между запросами букинг
issue_requests_delay: 0 # время задержки между запросами выписки
fare_rules_paragraphs_to_show: ["PE", "CD"] # PE (16)-penalties, CD (19)-Children discounts
fare_qualifier_list: ["P", "U"] # список fareQualifier, с которыми попытаются забронироваться
9 changes: 5 additions & 4 deletions service/10_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
//"github.com/tmconsulting/amadeus-golang-sdk/structs/fare/masterPricerTravelBoardSearch/v14.3/response"
)

func (s *service) FareMasterPricerTravelBoardSearch(query *search.Request) (*search.Response, *client.ResponseSOAPHeader, error) {
func (s *service) FareMasterPricerTravelBoardSearch(query *search.SearchRequest) (*search.SearchResponse, *client.ResponseSOAPHeader, error) {
switch s.mm[FareMasterPricerTravelBoardSearch] {
case FareMasterPricerTravelBoardSearchV143:
query := Fare_MasterPricerTravelBoardSearchRequest_v14_3.MakeRequest(query)
response, header, err := s.sdk.FareMasterPricerTravelBoardSearchV143(query)
request := Fare_MasterPricerTravelBoardSearchRequest_v14_3.MakeRequest(query)
response, header, err := s.sdk.FareMasterPricerTravelBoardSearchV143(request)
if response == nil {
return nil, header, err
}
Expand All @@ -25,7 +25,8 @@ func (s *service) FareMasterPricerTravelBoardSearch(query *search.Request) (*sea
return nil, header, errResponse
}

return response.ToCommon(), header, err
reply, err := response.ToCommon(query)
return reply, header, err
}
return nil, nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type Service interface {
CloseSession() (reply *SecuritySignOut_v04_1.Response, err error)

// Search
FareMasterPricerTravelBoardSearch(query *search.Request) (*search.Response, *client.ResponseSOAPHeader, error)
FareMasterPricerTravelBoardSearch(query *search.SearchRequest) (*search.SearchResponse, *client.ResponseSOAPHeader, error)
FareInformativeBestPricingWithout(query *Fare_InformativeBestPricingWithoutPNRRequest_v12_4.Request) (*Fare_InformativeBestPricingWithoutPNRResponse_v12_4.Response, *client.ResponseSOAPHeader, error)
FareInformativePricingWithoutPNR(query *Fare_InformativePricingWithoutPNR_v12_4.Request) (*Fare_InformativePricingWithoutPNRReply_v12_4.Response, *client.ResponseSOAPHeader, error)

Expand Down
59 changes: 54 additions & 5 deletions service/service_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package service

import (
"encoding/json"
"fmt"
"github.com/tmconsulting/amadeus-golang-sdk/configuration"
"github.com/tmconsulting/amadeus-golang-sdk/structs"
search "github.com/tmconsulting/amadeus-golang-sdk/structs/fare/masterPricerTravelBoardSearch"
"github.com/tmconsulting/amadeus-golang-sdk/structs/pnr/retrieve"
"log"
Expand Down Expand Up @@ -83,26 +87,71 @@ func TestNewSKD(t *testing.T) {

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

tearUp()

err := configuration.InitConfig()
if err != nil {
t.FailNow()
}

//url = configuration.Config.Amadeus.Connection.URL
//originator = configuration.Config.Amadeus.Connection.Originator
//passwordRaw = configuration.Config.Amadeus.Connection.PasswordRaw
//officeId = "MOWR228FG"

cl := client.New(client.SetURL(url), client.SetUser(originator), client.SetPassword(passwordRaw), client.SetAgent(officeId), client.SetLogger(stdOutLog))

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

request := search.Request{
itinerary := structs.Itinerary{
DepartureLocation: structs.Location{
AirportCode: "SVO",
CityCode: "MOW",
CountryCode: "RU",
Type: "city",
},
ArrivalLocation: structs.Location{
AirportCode: "LED",
CityCode: "LED",
CountryCode: "RU",
Type: "city",
},
}
request := search.SearchRequest{
ClientData: structs.ClientInfo{
OfficeID: "MOWR224PW",
},
BaseClass: []string{
"E",
},
Changes: false,
WithBaggage: true,
TravelType: "OW",
Itineraries: map[int]*search.Itinerary{
1: {
DepartureLocation: "MOW",
ArrivalLocation: "LED",
DepartureDate: time.Now().Add(10 * 24 * time.Hour), // add 10 days
Itinerary: &itinerary,
DepartureDate: structs.FlightDateTime{
Date: time.Now().Add(10 * 24 * time.Hour), // add 10 days
},
DepartureDateTill: structs.FlightDateTimeUniversal{
DateStr: time.Now().Add(11 * 24 * time.Hour).String(), // add 10 days
},
},
},
Currency: "RUB",
Passengers: search.Travellers{ADT: 2, CHD: 1, INF: 1},
Passengers: structs.Travellers{ADT: 1, CHD: 0, INF: 0},
Airlines: []string{
"SU",
},
}

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

aa, _ := json.Marshal(response)
fmt.Println("Search response: ", string(aa))

if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
15 changes: 15 additions & 0 deletions structs/airline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package structs

// Airline structure
type Airline struct {
CodeEng string `json:"code_eng" bson:"codeEng"`
CodeRus string `json:"code_rus,omitempty" bson:"codeRus,omitempty"`
NameEng string `json:"name_eng,omitempty" bson:"nameEng,omitempty"`
NameRus string `json:"name_rus,omitempty" bson:"nameRus,omitempty"`
}

// Aircraft structure
type Aircraft struct {
Code *string `json:"code" db:"code" bson:"code"`
Name map[string]string `json:"name,omitempty" db:"name" bson:"name,omitempty"`
}
7 changes: 7 additions & 0 deletions structs/baggage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package structs

// BaggageType structure
type BaggageType struct {
Value int `json:"value"`
Unit string `json:"unit"`
}
32 changes: 32 additions & 0 deletions structs/clientInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package structs

import (
"encoding/json"
)

// ClientInfo customer info structure
type ClientInfo struct {
OfficeID string `json:"office_id"`
Timezone string `json:"timezone"`
}

// UnmarshalJSON overrides UnmarshalJSON
func (c *ClientInfo) UnmarshalJSON(data []byte) error {
type ClientInfo2 struct {
Var1 string `json:"amadeus_office_id"`
Var2 string `json:"office_id"`
}
var clientInfo ClientInfo2
if err := json.Unmarshal(data, &clientInfo); err != nil {
//logs.Log.WithError(err).Error("Error unmarshal json")
return err
}
var OfficeID = ""
if clientInfo.Var1 != "" {
OfficeID = clientInfo.Var1
} else {
OfficeID = clientInfo.Var2
}
c.OfficeID = OfficeID
return nil
}
8 changes: 8 additions & 0 deletions structs/errorStructs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package structs

// ErrorReply Error Reply structure
type ErrorReply struct {
Status string `json:"status,omitempty"`
ErrorCode string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
}
Loading

0 comments on commit 3a8d88e

Please sign in to comment.