Add ParksController show action

This commit is contained in:
2025-10-07 23:16:21 -07:00
parent 2e3c6006ae
commit 5dd2814f88

View File

@@ -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