Add api/v1 base controller
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user