diff --git a/app/controllers/retail_locations_controller.rb b/app/controllers/retail_locations_controller.rb new file mode 100644 index 0000000..d5f53d8 --- /dev/null +++ b/app/controllers/retail_locations_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +## +# Realtime Controller +class RetailLocationsController < ApplicationController + before_action :set_retail_location, only: [:show] + + # GET /retail_locations + def index + render json: paginate_results(RetailLocation.all) + end + + def show + render json: @retail_location + end + + # Use callbacks to share common setup or constraints between actions. + def set_retail_location + @retail_location = RetailLocation.find_by(location_code: params[:location_code]) + raise ActionController::RoutingError, 'Not Found' if @retail_location.nil? + end +end diff --git a/app/models/retail_location.rb b/app/models/retail_location.rb new file mode 100644 index 0000000..f44d62b --- /dev/null +++ b/app/models/retail_location.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +## +# Retail Location Model +class RetailLocation < ApplicationRecord +end diff --git a/config/routes.rb b/config/routes.rb index 73cca1b..9a93c2d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,4 +56,7 @@ get '/realtime/alerts', to: 'realtime#alerts', as: 'realtime_alerts' get '/realtime/vehicle_positions', to: 'realtime#vehicle_positions', as: 'realtime_vehicle_positions' get '/realtime/trip_updates', to: 'realtime#trip_updates', as: 'realtime_trip_updates' + + get '/retail_locations', to: 'retail_locations#index', as: 'retail_locations' + get '/retail_locations/:location_code', to: 'retail_locations#show', as: 'retail_location' end diff --git a/db/migrate/20240401195630_create_retail_locations.rb b/db/migrate/20240401195630_create_retail_locations.rb new file mode 100644 index 0000000..d5b13cf --- /dev/null +++ b/db/migrate/20240401195630_create_retail_locations.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +## +# Create Retail Locations +class CreateRetailLocations < ActiveRecord::Migration[7.0] + def change + create_table :retail_locations do |t| + t.string 'location_code', unique: true, null: false + t.string 'name' + t.string 'address' + t.string 'city' + t.string 'state' + t.string 'zip' + t.boolean 'is_active', default: false, null: false + t.boolean 'can_buy_media', default: false, null: false + t.boolean 'can_reload_media', default: false, null: false + t.decimal 'latitude', precision: 10, scale: 6, null: false + t.decimal 'longitude', precision: 10, scale: 6, null: false + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 88d60c7..d16db4c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,8 +10,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_08_19_161345) do - create_table "agencies", charset: "utf8mb4", force: :cascade do |t| +ActiveRecord::Schema[7.0].define(version: 2024_04_01_195630) do + create_table "agencies", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "agency_gid" t.string "agency_name", null: false t.string "agency_url", null: false @@ -25,7 +25,7 @@ t.index ["agency_gid"], name: "index_agencies_on_agency_gid", unique: true end - create_table "calendar_dates", charset: "utf8mb4", force: :cascade do |t| + create_table "calendar_dates", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "service_gid", null: false t.integer "calendar_id", null: false t.date "date", null: false @@ -35,7 +35,7 @@ t.index ["service_gid", "date"], name: "index_calendar_dates_on_service_gid_and_date", unique: true end - create_table "calendars", charset: "utf8mb4", force: :cascade do |t| + create_table "calendars", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "service_gid", null: false t.boolean "monday", null: false t.boolean "tuesday", null: false @@ -51,7 +51,7 @@ t.index ["service_gid"], name: "index_calendars_on_service_gid", unique: true end - create_table "fare_attributes", charset: "utf8mb4", force: :cascade do |t| + create_table "fare_attributes", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "fare_gid", null: false t.decimal "price", precision: 10, null: false t.string "currency_type", null: false @@ -63,7 +63,7 @@ t.index ["fare_gid"], name: "index_fare_attributes_on_fare_gid", unique: true end - create_table "fare_rules", charset: "utf8mb4", force: :cascade do |t| + create_table "fare_rules", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "fare_gid", null: false t.string "route_gid" t.integer "route_id" @@ -74,7 +74,7 @@ t.datetime "updated_at", null: false end - create_table "feed_infos", charset: "utf8mb4", force: :cascade do |t| + create_table "feed_infos", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "feed_publisher_name", null: false t.string "feed_publisher_url", null: false t.string "feed_lang", null: false @@ -85,7 +85,7 @@ t.datetime "updated_at", null: false end - create_table "frequencies", charset: "utf8mb4", force: :cascade do |t| + create_table "frequencies", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "trip_gid", null: false t.integer "trip_id" t.string "start_time", null: false @@ -97,7 +97,23 @@ t.index ["trip_gid", "start_time", "end_time"], name: "index_frequencies_on_trip_gid_and_start_time_and_end_time", unique: true end - create_table "routes", charset: "utf8mb4", force: :cascade do |t| + create_table "retail_locations", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.string "location_code", null: false + t.string "name" + t.string "address" + t.string "city" + t.string "state" + t.string "zip" + t.boolean "is_active", default: false, null: false + t.boolean "can_buy_media", default: false, null: false + t.boolean "can_reload_media", default: false, null: false + t.decimal "latitude", precision: 10, scale: 6, null: false + t.decimal "longitude", precision: 10, scale: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "routes", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "route_gid", null: false t.string "agency_gid" t.integer "agency_id" @@ -114,7 +130,7 @@ t.index ["route_gid"], name: "index_routes_on_route_gid", unique: true end - create_table "shapes", charset: "utf8mb4", force: :cascade do |t| + create_table "shapes", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "shape_gid", null: false t.text "shape_points", size: :long, null: false t.datetime "created_at", null: false @@ -122,7 +138,7 @@ t.index ["shape_gid"], name: "index_shapes_on_shape_gid", unique: true end - create_table "stop_times", charset: "utf8mb4", force: :cascade do |t| + create_table "stop_times", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "trip_gid", null: false t.integer "trip_id" t.string "arrival_time", null: false @@ -142,7 +158,7 @@ t.index ["trip_gid", "stop_sequence"], name: "index_stop_times_on_trip_gid_and_stop_sequence", unique: true end - create_table "stops", charset: "utf8mb4", force: :cascade do |t| + create_table "stops", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "stop_gid", null: false t.string "stop_code" t.string "stop_name", null: false @@ -161,7 +177,7 @@ t.index ["stop_gid"], name: "index_stops_on_stop_gid", unique: true end - create_table "transfers", charset: "utf8mb4", force: :cascade do |t| + create_table "transfers", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "from_stop_gid", null: false t.integer "from_stop_id" t.string "to_stop_gid", null: false @@ -173,7 +189,7 @@ t.index ["from_stop_gid", "to_stop_gid"], name: "index_transfers_on_from_stop_gid_and_to_stop_gid", unique: true end - create_table "trips", charset: "utf8mb4", force: :cascade do |t| + create_table "trips", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "route_gid", null: false t.integer "route_id" t.string "service_gid", null: false diff --git a/test/controllers/default_controller_test.rb b/test/controllers/default_controller_test.rb index 401c7e0..99252af 100644 --- a/test/controllers/default_controller_test.rb +++ b/test/controllers/default_controller_test.rb @@ -7,7 +7,7 @@ class DefaultControllerTest < ActionDispatch::IntegrationTest get root_url assert_response :success json_response = response.parsed_body - assert_equal 42, json_response.length + assert_equal 44, json_response.length assert_equal '/', json_response[0] assert_equal '/agencies.json', json_response[1] assert_equal '/agencies/:agency_gid.json', json_response[2] diff --git a/test/controllers/retail_locations_controller_test.rb b/test/controllers/retail_locations_controller_test.rb new file mode 100644 index 0000000..25690a3 --- /dev/null +++ b/test/controllers/retail_locations_controller_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'test_helper' + +class RetailLocationsControllerTest < ActionDispatch::IntegrationTest + setup do + @retail_location = retail_locations(:RetailLocation1).location_code + end + + test 'should get index' do + get retail_locations_url, as: :json + assert_response :success + json_response = response.parsed_body + assert_equal 2, json_response['total'] + assert_equal 2, json_response['data'].length + assert_equal '170', json_response['data'][1]['location_code'] + assert_equal 'CVS Pharmacy', json_response['data'][1]['name'] + end + + test 'should show retail_location' do + get retail_location_url(@retail_location), as: :json + assert_response :success + json_response = response.parsed_body + assert_equal '170', json_response['location_code'] + assert_equal 'CVS Pharmacy', json_response['name'] + end +end diff --git a/test/fixtures/retail_locations.yml b/test/fixtures/retail_locations.yml new file mode 100644 index 0000000..6fa7204 --- /dev/null +++ b/test/fixtures/retail_locations.yml @@ -0,0 +1,26 @@ +--- +RetailLocation1: + location_code: 170 + name: CVS Pharmacy + address: 4201 Clarksville Highway + city: Nashville + state: TN + zip: "37218" + is_active: 1 + can_buy_media: 1 + can_reload_media: 1 + latitude: 36.216513 + longitude: -86.837775 + +RetailLocation2: + location_code: 858 + name: Dollar General + address: 4201 CLARKSVILLE PIKE + city: Nashville + state: TN + zip: "37218" + is_active: 1 + can_buy_media: 0 + can_reload_media: 1 + latitude: 36.21901 + longitude: -86.837471 diff --git a/test/models/retail_location_test.rb b/test/models/retail_location_test.rb new file mode 100644 index 0000000..66d49fd --- /dev/null +++ b/test/models/retail_location_test.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'test_helper' + +class RetailLocationTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end