Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/models/airline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand Down
11 changes: 5 additions & 6 deletions app/models/airport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/couchbase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
42 changes: 21 additions & 21 deletions spec/requests/api/v1/airlines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,34 @@
let(:offset) { '0' }
let(:expected_airlines) do
[
{
'callsign' => 'SPEEDBIRD',
'country' => 'United Kingdom',
'iata' => 'BA',
'icao' => 'BAW',
'name' => 'British Airways'
},
{
'callsign' => 'AIRFRANS',
'country' => 'France',
'iata' => 'AF',
'icao' => 'AFR',
'name' => 'Air France'
},
{
'callsign' => 'DELTA',
'country' => 'United States',
'iata' => 'DL',
'icao' => 'DAL',
'name' => 'Delta Air Lines'
},
{
'callsign' => 'AMERICAN',
'country' => 'United States',
'iata' => 'AA',
'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',
Expand Down Expand Up @@ -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
Expand Down
Loading