diff --git a/app/controllers/api/v1/parks/base_controller.rb b/app/controllers/api/v1/parks/base_controller.rb index f250bb2..2310ca5 100644 --- a/app/controllers/api/v1/parks/base_controller.rb +++ b/app/controllers/api/v1/parks/base_controller.rb @@ -1,5 +1,5 @@ -module Api::V1::Parks - class BaseController < ApplicationController +module Api::V1 + class Parks::BaseController < BaseController before_action :set_park private diff --git a/app/controllers/api/v1/parks_controller.rb b/app/controllers/api/v1/parks_controller.rb index 486d1a9..1934e8c 100644 --- a/app/controllers/api/v1/parks_controller.rb +++ b/app/controllers/api/v1/parks_controller.rb @@ -1,31 +1,24 @@ -class Api::V1::ParksController < ApplicationController - DEFAULT_PAGE_SIZE = 10 - before_action :set_park, only: :show +module Api::V1 + class ParksController < BaseController + before_action :set_park, only: :show - def index - parks = Park.all - if params[:state].present? - parks = parks.where("states like '%' || ? || '%'", params[:state]) + def index + parks = Park.all + if params[:state].present? + parks = parks.where("states like '%' || ? || '%'", params[:state]) + end + render json: parks.limit(per_page).offset((page - 1) * per_page) end - render json: parks.limit(per_page).offset((page - 1) * per_page) - end - def show - render json: @park - end + def show + render json: @park + end - private + private - def per_page - (params[:per_page].presence || DEFAULT_PAGE_SIZE).to_i - end - - def page - (params[:page].presence || 1).to_i - end - - def set_park - @park = Park.find_by(code: params[:code]) - head :not_found unless @park.present? + def set_park + @park = Park.find_by(code: params[:code]) + head :not_found unless @park.present? + end end end