From 16f851b7210b5d9afc600c4cc7cf7d6a98459981 Mon Sep 17 00:00:00 2001 From: Nikhil Vengal Date: Tue, 7 Oct 2025 22:09:41 -0700 Subject: [PATCH] Add api/v1/parks --- app/controllers/api/v1/parks_controller.rb | 5 +++++ config/routes.rb | 5 +++++ test/controllers/api/v1/parks_controller_test.rb | 8 ++++++++ test/fixtures/parks.yml | 4 ++-- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/v1/parks_controller.rb create mode 100644 test/controllers/api/v1/parks_controller_test.rb diff --git a/app/controllers/api/v1/parks_controller.rb b/app/controllers/api/v1/parks_controller.rb new file mode 100644 index 0000000..702e8e8 --- /dev/null +++ b/app/controllers/api/v1/parks_controller.rb @@ -0,0 +1,5 @@ +class Api::V1::ParksController < ApplicationController + def index + render json: Park.all + end +end diff --git a/config/routes.rb b/config/routes.rb index a125ef0..9a7a7f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,9 @@ Rails.application.routes.draw do + namespace :api do + namespace :v1 do + resources :parks, only: %i[index] + end + end # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. diff --git a/test/controllers/api/v1/parks_controller_test.rb b/test/controllers/api/v1/parks_controller_test.rb new file mode 100644 index 0000000..3ddf0ac --- /dev/null +++ b/test/controllers/api/v1/parks_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class Api::V1::ParksControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get api_v1_parks_url + assert_response :success + end +end diff --git a/test/fixtures/parks.yml b/test/fixtures/parks.yml index 3f21fbf..9d93279 100644 --- a/test/fixtures/parks.yml +++ b/test/fixtures/parks.yml @@ -4,10 +4,10 @@ one: code: crla name: Crater Lake National Park states: OR - properties: + properties: {} two: code: olym name: Olympic National Park states: WA - properties: + properties: {}