Skip to content

Commit fbb8575

Browse files
committed
Refactor controllers to limit the number of records returned in the index action of airlines_controller.rb and airports_controller.rb
1 parent 04ad63e commit fbb8575

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

app/controllers/api/v1/airlines_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def destroy
7676

7777
# GET /api/v1/airlines/list
7878
def index
79-
airlines = Airline.all
79+
airlines = Airline.all.offset(0).limit(10)
8080
render json: airlines.map { |airline| airline.attributes.except('id') }, status: :ok
8181
rescue StandardError => e
8282
render json: { error: e.message }, status: :internal_server_error

app/controllers/api/v1/airports_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def destroy
7575

7676
# GET /api/v1/airports/list
7777
def index
78-
airports = Airport.all
79-
render json: airports.map { |airport| airport.attributes.except('id') }, status: :ok
78+
airports = Airport.pluck(:id, :airportname, :city, :country, :faa, :icao, :tz, :geo)
79+
render json: airports
8080
rescue StandardError => e
8181
render json: { error: e.message }, status: :internal_server_error
8282
end

0 commit comments

Comments
 (0)