-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
281 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class MarketsController < ApplicationController | ||
def index | ||
@markets = Market.all | ||
if params[:find_within] | ||
search_distance_in_miles = 20 | ||
if params[:position_known] == 'true' | ||
search_center = [params[:current_lat], params[:current_lng]] | ||
@markets = @markets.near(search_center, search_distance_in_miles) | ||
else | ||
search_center = Geocoder::Calculations.geographic_center([[params[:sw_lat], params[:sw_lng]], [params[:ne_lat], params[:ne_lng]]]) | ||
@markets = @markets.within_bounding_box([params[:sw_lat], params[:sw_lng], params[:ne_lat], params[:ne_lng]]) | ||
end | ||
end | ||
render json: @markets | ||
end | ||
|
||
def create | ||
Market.create() | ||
end | ||
|
||
private def location_params | ||
params.require(:location).permit(:name, :address) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Locatable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
geocoded_by :address | ||
after_validation :geocode, if: ->(object){ object.address_changed? } | ||
validates :address, length: {maximum: 100} | ||
|
||
def to_marker(display_html) | ||
if geocoded? | ||
return { | ||
id: self.id, | ||
lat: self.latitude + rand(-0.000050..0.000050), | ||
lng: self.longitude + rand(-0.000050..0.000050), | ||
infowindow: display_html | ||
} | ||
end | ||
end | ||
|
||
def latitude_with_fudge | ||
if (geocoded?) | ||
self.latitude + rand(-0.000050..0.000050) | ||
end | ||
end | ||
|
||
def longitude_with_fudge | ||
if (geocoded?) | ||
self.longitude + rand(-0.000050..0.000050) | ||
end | ||
end | ||
end | ||
|
||
class_methods do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Schedulable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
end | ||
|
||
class_methods do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Market < ActiveRecord::Base | ||
include Locatable | ||
include Schedulable | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class MarketSerializer < ActiveModel::Serializer | ||
attributes :id, :created_at, :updated_at | ||
:address, :distance, :latitiude, :locale, :longitude, :name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Rails.application.routes.draw do | ||
|
||
root 'application#index' | ||
|
||
resources :markets | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class CreateMarkets < ActiveRecord::Migration | ||
def change | ||
create_table :markets do |t| | ||
# Markets | ||
t.string :name | ||
|
||
# Geocoding | ||
t.float :latitude | ||
t.float :longitude | ||
t.string :address | ||
|
||
# Scheduling | ||
t.string :days_of_week | ||
|
||
|
||
# Other | ||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.