diff --git a/app/models/airline.rb b/app/models/airline.rb index c1da9e5..cb98983 100644 --- a/app/models/airline.rb +++ b/app/models/airline.rb @@ -28,9 +28,9 @@ def self.all(country = nil, limit = 10, offset = 0) collection_name = 'airline' query = country ? "SELECT * FROM `#{bucket_name}`.`#{scope_name}`.`#{collection_name}` WHERE country = $country LIMIT $limit OFFSET $offset" : "SELECT * FROM `#{bucket_name}`.`#{scope_name}`.`#{collection_name}` LIMIT $limit OFFSET $offset" - options = Couchbase::Cluster::QueryOptions.new - options.named_parameters(country ? { 'country' => country, 'limit' => limit.to_i, - 'offset' => offset.to_i } : { 'limit' => limit.to_i, 'offset' => offset.to_i }) + params = { 'limit' => limit.to_i, 'offset' => offset.to_i } + params['country'] = country if country + options = Couchbase::Options::Query.new(named_parameters: params) result = COUCHBASE_CLUSTER.query(query, options) result.rows.map { |row| new(row.fetch('airline', {})) }.to_a @@ -52,11 +52,12 @@ def self.to_airport(destination_airport_code, limit = 10, offset = 0) WHERE route.destinationairport = $airport) AS subquery JOIN `#{bucket_name}`.`#{scope_name}`.`#{airline_collection_name}` AS air ON META(air).id = subquery.airlineId + ORDER BY air.name ASC LIMIT $limit OFFSET $offset " - options = Couchbase::Cluster::QueryOptions.new - options.named_parameters({ 'airport' => destination_airport_code, 'limit' => limit.to_i, 'offset' => offset.to_i }) + options = Couchbase::Options::Query.new(named_parameters: { 'airport' => destination_airport_code, 'limit' => limit.to_i, + 'offset' => offset.to_i }) result = COUCHBASE_CLUSTER.query(query, options) result.rows.map { |row| new(row) } diff --git a/app/models/airport.rb b/app/models/airport.rb index 6908c3f..2f6d0f2 100644 --- a/app/models/airport.rb +++ b/app/models/airport.rb @@ -110,12 +110,11 @@ def self.direct_connections(destination_airport_code, limit = 10, offset = 0) LIMIT $limit OFFSET $offset " - options = Couchbase::Cluster::QueryOptions.new - options.named_parameters({ - 'destinationAirportCode' => destination_airport_code, - 'limit' => limit.to_i, - 'offset' => offset.to_i - }) + options = Couchbase::Options::Query.new(named_parameters: { + 'destinationAirportCode' => destination_airport_code, + 'limit' => limit.to_i, + 'offset' => offset.to_i + }) result = COUCHBASE_CLUSTER.query(query, options) result.rows.map { |row| row['destinationairport'] } diff --git a/config/initializers/couchbase.rb b/config/initializers/couchbase.rb index fc48502..c417349 100644 --- a/config/initializers/couchbase.rb +++ b/config/initializers/couchbase.rb @@ -41,7 +41,7 @@ def set_couchbase_constants_to_nil if ENV['CI'] # Use environment variables from GitHub Secrets with retry logic connect_with_retry do - options = Couchbase::Cluster::ClusterOptions.new + options = Couchbase::Options::Cluster.new options.authenticate(DB_USERNAME, DB_PASSWORD) COUCHBASE_CLUSTER = Couchbase::Cluster.connect(DB_CONN_STR, options) end @@ -61,7 +61,7 @@ def set_couchbase_constants_to_nil db_conn_str = ENV.fetch('DB_CONN_STR', DEFAULT_DB_CONN_STR) # Connect to the Couchbase cluster - options = Couchbase::Cluster::ClusterOptions.new + options = Couchbase::Options::Cluster.new options.authenticate(db_username, db_password) COUCHBASE_CLUSTER = Couchbase::Cluster.connect(db_conn_str, options) end diff --git a/spec/requests/api/v1/airlines_spec.rb b/spec/requests/api/v1/airlines_spec.rb index dd84ca1..7910a34 100644 --- a/spec/requests/api/v1/airlines_spec.rb +++ b/spec/requests/api/v1/airlines_spec.rb @@ -192,13 +192,6 @@ let(:offset) { '0' } let(:expected_airlines) do [ - { - 'callsign' => 'SPEEDBIRD', - 'country' => 'United Kingdom', - 'iata' => 'BA', - 'icao' => 'BAW', - 'name' => 'British Airways' - }, { 'callsign' => 'AIRFRANS', 'country' => 'France', @@ -206,13 +199,6 @@ 'icao' => 'AFR', 'name' => 'Air France' }, - { - 'callsign' => 'DELTA', - 'country' => 'United States', - 'iata' => 'DL', - 'icao' => 'DAL', - 'name' => 'Delta Air Lines' - }, { 'callsign' => 'AMERICAN', 'country' => 'United States', @@ -220,6 +206,20 @@ 'icao' => 'AAL', 'name' => 'American Airlines' }, + { + 'callsign' => 'SPEEDBIRD', + 'country' => 'United Kingdom', + 'iata' => 'BA', + 'icao' => 'BAW', + 'name' => 'British Airways' + }, + { + 'callsign' => 'DELTA', + 'country' => 'United States', + 'iata' => 'DL', + 'icao' => 'DAL', + 'name' => 'Delta Air Lines' + }, { 'callsign' => 'HAWAIIAN', 'country' => 'United States', @@ -248,19 +248,19 @@ 'icao' => 'SCX', 'name' => 'Sun Country Airlines' }, - { - 'callsign' => 'UNITED', - 'country' => 'United States', - 'iata' => 'UA', - 'icao' => 'UAL', - 'name' => 'United Airlines' - }, { 'callsign' => 'U S AIR', 'country' => 'United States', 'iata' => 'US', 'icao' => 'USA', 'name' => 'US Airways' + }, + { + 'callsign' => 'UNITED', + 'country' => 'United States', + 'iata' => 'UA', + 'icao' => 'UAL', + 'name' => 'United Airlines' } ] end