Skip to content

Commit

Permalink
Add Static Retail Locations
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenyeargin committed Apr 1, 2024
1 parent bd69501 commit a162440
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 15 deletions.
22 changes: 22 additions & 0 deletions app/controllers/retail_locations_controller.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions app/models/retail_location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

##
# Retail Location Model
class RetailLocation < ApplicationRecord
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions db/migrate/20240401195630_create_retail_locations.rb
Original file line number Diff line number Diff line change
@@ -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
44 changes: 30 additions & 14 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/controllers/default_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
27 changes: 27 additions & 0 deletions test/controllers/retail_locations_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions test/fixtures/retail_locations.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions test/models/retail_location_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'test_helper'

class RetailLocationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit a162440

Please sign in to comment.