added delivery costs to total / added ribica logo just for fun / added validation check when confirming delivery
This commit is contained in:
5
front-api/controllers/place.rb
Normal file
5
front-api/controllers/place.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
get '/place/:postal_code' do
|
||||
Place.by_code_or_default(params["postal_code"]).to_json
|
||||
end
|
||||
11
front-api/db/migrate/20150312073820_create_places.rb
Normal file
11
front-api/db/migrate/20150312073820_create_places.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class CreatePlaces < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :places do |t|
|
||||
t.string :postal_code
|
||||
t.decimal :delivery_price
|
||||
t.string :name
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150222055517) do
|
||||
ActiveRecord::Schema.define(version: 20150312073820) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -100,6 +100,14 @@ ActiveRecord::Schema.define(version: 20150222055517) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "places", force: :cascade do |t|
|
||||
t.string "postal_code"
|
||||
t.decimal "delivery_price"
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "sections", force: :cascade do |t|
|
||||
t.string "name"
|
||||
end
|
||||
|
||||
11
front-api/models/place.rb
Normal file
11
front-api/models/place.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Place < ActiveRecord::Base
|
||||
|
||||
def self.by_code_or_default(code)
|
||||
# removes garbage and converts whitespace prefixed codes correctly - like " 71000" -> 71000
|
||||
valid_code = code.to_i.to_s
|
||||
place = Place.where(postal_code: valid_code).first
|
||||
place ||= Place.where("postal_code is null or postal_code = ''").first
|
||||
return place
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user