Skip to content

Commit c9d4497

Browse files
committed
feat: Refactor N1QL query in Airline model to use dynamic values for destination airport
1 parent 763382e commit c9d4497

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

app/models/hotel.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ def do_something_after_destroy
107107

108108
validate :custom_validation
109109

110-
n1ql :find_by_name_n1ql, 'SELECT * FROM hotels WHERE name = $1'
110+
# n1ql :find_by_name_n1ql, 'SELECT * FROM hotels WHERE name = $1'
111+
n1ql :find_by_name_n1ql, query_fn: proc { |bucket, values, options|
112+
cluster.query('SELECT * FROM hotels WHERE name = $1', values:, options:)
113+
}
111114

112115
def custom_validation
113-
if title.include?('funny')
114-
errors.add(:title, 'cannot be funny')
115-
end
116+
return unless title.include?('funny')
117+
118+
errors.add(:title, 'cannot be funny')
116119
end
117120

118121
def set_timestamps
@@ -122,14 +125,13 @@ def set_timestamps
122125
end
123126

124127
def encrypt_address
125-
self.address = encrypt(self.address) if address_changed?
128+
self.address = encrypt(address) if address_changed?
126129
end
127130

128131
def encrypt(data)
129132
# Implement your encryption logic here
130133
# For example, using a simple XOR encryption
131-
key = "secret_key"
132-
encrypted_data = data.chars.map { |c| (c.ord ^ key.ord).chr }.join
133-
encrypted_data
134+
key = 'secret_key'
135+
data.chars.map { |c| (c.ord ^ key.ord).chr }.join
134136
end
135137
end

config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ class Application < Rails::Application
2424
# config.time_zone = "Central Time (US & Canada)"
2525
# config.eager_load_paths << Rails.root.join("extras")
2626
config.autoloader = :classic
27+
config.autoload_paths += %W[#{config.root}/lib]
2728
end
2829
end

config/initializers/rswag_ui.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Rswag::Ui.configure do |c|
2-
32
# List the Swagger endpoints that you want to be documented through the
43
# swagger-ui. The first parameter is the path (absolute or relative to the UI
54
# host) to the corresponding endpoint and the second is a title that will be
@@ -8,7 +7,7 @@
87
# (under openapi_root) as JSON or YAML endpoints, then the list below should
98
# correspond to the relative paths for those endpoints.
109

11-
c.swagger_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs'
10+
c.openapi_endpoint '/api-docs/v1/swagger.yaml', 'API V1 Docs'
1211

1312
# Add Basic Auth in case your API is private
1413
# c.basic_auth_enabled = true

0 commit comments

Comments
 (0)