Add ParksController show action
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class Api::V1::ParksController < ApplicationController
|
class Api::V1::ParksController < ApplicationController
|
||||||
DEFAULT_PAGE_SIZE = 10
|
DEFAULT_PAGE_SIZE = 10
|
||||||
|
before_action :set_park, only: :show
|
||||||
|
|
||||||
def index
|
def index
|
||||||
parks = Park.all
|
parks = Park.all
|
||||||
@@ -9,6 +10,10 @@ class Api::V1::ParksController < ApplicationController
|
|||||||
render json: parks.limit(per_page).offset((page - 1) * per_page)
|
render json: parks.limit(per_page).offset((page - 1) * per_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
render json: @park
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def per_page
|
def per_page
|
||||||
@@ -18,4 +23,9 @@ class Api::V1::ParksController < ApplicationController
|
|||||||
def page
|
def page
|
||||||
(params[:page].presence || 1).to_i
|
(params[:page].presence || 1).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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