From cd88d21a264a0159cbb14efc1ad2daff6b24db71 Mon Sep 17 00:00:00 2001 From: Bilal Date: Tue, 6 Oct 2020 14:17:18 +0300 Subject: [PATCH] show onboarding page when currency is not set --- app/controllers/chips_controller.rb | 25 ++++++++++++++++- app/controllers/homies_controller.rb | 3 +- .../original_gangstas_controller.rb | 28 +++++++++++++++++++ app/models/homie.rb | 1 - app/models/original_gangsta.rb | 3 ++ config/initializers/inflections.rb | 1 + config/routes.rb | 1 + ...708_remove_default_chip_ref_from_homies.rb | 5 ++++ ...20201006120951_create_original_gangstas.rb | 13 +++++++++ db/schema.rb | 14 ++++++++-- 10 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 app/controllers/original_gangstas_controller.rb create mode 100644 app/models/original_gangsta.rb create mode 100644 db/migrate/20201006120708_remove_default_chip_ref_from_homies.rb create mode 100644 db/migrate/20201006120951_create_original_gangstas.rb diff --git a/app/controllers/chips_controller.rb b/app/controllers/chips_controller.rb index b19e27a..950d937 100644 --- a/app/controllers/chips_controller.rb +++ b/app/controllers/chips_controller.rb @@ -1,6 +1,29 @@ class ChipsController < ApplicationController def index - json_response Chip.where(enabled: true).order(:name).to_json(include: :base_chip_values) + all_chips = [ + { + id: 1, + name: 'US Dollar', + symbol: '$', + code: 'USD', + prefixed: true + }, + { + id: 2, + name: 'Bosnian Convertible Mark', + symbol: 'KM', + code: 'BAM', + prefixed: false + }, + { + id: 3, + name: 'Euro', + symbol: '€', + code: 'EUR', + prefixed: false + } + ] + json_response all_chips end def create diff --git a/app/controllers/homies_controller.rb b/app/controllers/homies_controller.rb index f93d5e9..4d2da8a 100644 --- a/app/controllers/homies_controller.rb +++ b/app/controllers/homies_controller.rb @@ -46,8 +46,7 @@ class HomiesController < ApplicationController params.require(:homie).permit( :name, :importance, - :about, - :chip_id + :about ) end end diff --git a/app/controllers/original_gangstas_controller.rb b/app/controllers/original_gangstas_controller.rb new file mode 100644 index 0000000..2d5debe --- /dev/null +++ b/app/controllers/original_gangstas_controller.rb @@ -0,0 +1,28 @@ +class OriginalGangstasController < ApplicationController + def show + if OriginalGangsta.count.zero? + OriginalGangsta.create.save + end + + json_response OriginalGangsta.first + end + + def update + if original_gangsta_params[:chip_scale].to_i.positive? + OriginalGangsta.update(original_gangsta_params) + json_response onboarded: true + else + error_response :bad_request + end + end + + private + + def original_gangsta_params + params.require(:original_gangsta).permit :chip_name, + :chip_code, + :chip_symbol, + :chip_scale, + :chip_prefixed + end +end diff --git a/app/models/homie.rb b/app/models/homie.rb index be5ef9d..65e5271 100644 --- a/app/models/homie.rb +++ b/app/models/homie.rb @@ -1,7 +1,6 @@ class Homie < ApplicationRecord has_many :money_moves has_many :work - belongs_to :chip def self.info(importance) cash_totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount) diff --git a/app/models/original_gangsta.rb b/app/models/original_gangsta.rb new file mode 100644 index 0000000..a579514 --- /dev/null +++ b/app/models/original_gangsta.rb @@ -0,0 +1,3 @@ +class OriginalGangsta < ApplicationRecord + +end \ No newline at end of file diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ab4f265..9f8e25d 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -17,4 +17,5 @@ ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'work', 'work' + inflect.irregular 'gangsta', 'gangstas' end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index dbd5365..6ebc143 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ Rails.application.routes.draw do constraints format: :json do scope :api do + resources :original_gangstas, only: [:show, :update] resources :money_moves resources :work resources :chips, only: %i[index create destroy] diff --git a/db/migrate/20201006120708_remove_default_chip_ref_from_homies.rb b/db/migrate/20201006120708_remove_default_chip_ref_from_homies.rb new file mode 100644 index 0000000..bfa8b96 --- /dev/null +++ b/db/migrate/20201006120708_remove_default_chip_ref_from_homies.rb @@ -0,0 +1,5 @@ +class RemoveDefaultChipRefFromHomies < ActiveRecord::Migration[5.2] + def change + remove_reference :homies, :chip + end +end diff --git a/db/migrate/20201006120951_create_original_gangstas.rb b/db/migrate/20201006120951_create_original_gangstas.rb new file mode 100644 index 0000000..12f3016 --- /dev/null +++ b/db/migrate/20201006120951_create_original_gangstas.rb @@ -0,0 +1,13 @@ +class CreateOriginalGangstas < ActiveRecord::Migration[5.2] + def change + create_table :original_gangstas do |t| + t.text :chip_name + t.text :chip_code + t.text :chip_symbol + t.boolean :chip_prefixed + t.integer :chip_scale + + t.timestamps + end + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 902c3f0..e1a270a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_10_06_103421) do +ActiveRecord::Schema.define(version: 2020_10_06_120951) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,8 +41,6 @@ ActiveRecord::Schema.define(version: 2020_10_06_103421) do t.text "about" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.bigint "chip_id" - t.index ["chip_id"], name: "index_homies_on_chip_id" end create_table "money_moves", force: :cascade do |t| @@ -53,6 +51,16 @@ ActiveRecord::Schema.define(version: 2020_10_06_103421) do t.datetime "updated_at", null: false end + create_table "original_gangstas", force: :cascade do |t| + t.text "chip_name" + t.text "chip_code" + t.text "chip_symbol" + t.boolean "chip_prefixed" + t.integer "chip_scale" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "work", force: :cascade do |t| t.text "description" t.integer "amount"