added delivery costs to total / added ribica logo just for fun / added validation check when confirming delivery

This commit is contained in:
Senad Uka
2015-03-13 07:04:44 +01:00
parent e3abc09891
commit 648dee4636
17 changed files with 208 additions and 31 deletions

View File

@@ -0,0 +1,5 @@
get '/place/:postal_code' do
Place.by_code_or_default(params["postal_code"]).to_json
end

View 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

View File

@@ -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
View 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