handle onboarding and chip selection for Og
This commit is contained in:
@@ -1,6 +1,29 @@
|
|||||||
class ChipsController < ApplicationController
|
class ChipsController < ApplicationController
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|||||||
28
app/controllers/ogs_controller.rb
Normal file
28
app/controllers/ogs_controller.rb
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
class OgsController < ApplicationController
|
||||||
|
def show
|
||||||
|
if Og.count.zero?
|
||||||
|
Og.create.save
|
||||||
|
end
|
||||||
|
|
||||||
|
json_response Og.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if og_params[:chip_scale].to_i.positive?
|
||||||
|
Og.update(og_params)
|
||||||
|
json_response onboarded: true
|
||||||
|
else
|
||||||
|
error_response :bad_request
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def og_params
|
||||||
|
params.require(:og).permit :chip_name,
|
||||||
|
:chip_code,
|
||||||
|
:chip_symbol,
|
||||||
|
:chip_scale,
|
||||||
|
:chip_prefixed
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/models/og.rb
Normal file
3
app/models/og.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Og < ApplicationRecord
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
constraints format: :json do
|
constraints format: :json do
|
||||||
scope :api do
|
scope :api do
|
||||||
|
resource :og, only: [:show, :update]
|
||||||
resources :money_moves
|
resources :money_moves
|
||||||
resources :work
|
resources :work
|
||||||
resources :chips, only: %i[index create destroy]
|
resources :chips, only: %i[index create destroy]
|
||||||
|
|||||||
13
db/migrate/20200918032033_create_ogs.rb
Normal file
13
db/migrate/20200918032033_create_ogs.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class CreateOgs < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :ogs 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
|
||||||
12
db/schema.rb
12
db/schema.rb
@@ -41,8 +41,6 @@ ActiveRecord::Schema.define(version: 2020_09_19_023237) do
|
|||||||
t.text "about"
|
t.text "about"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.bigint "chip_id"
|
|
||||||
t.index ["chip_id"], name: "index_homies_on_chip_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "money_moves", force: :cascade do |t|
|
create_table "money_moves", force: :cascade do |t|
|
||||||
@@ -61,6 +59,16 @@ ActiveRecord::Schema.define(version: 2020_09_19_023237) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "ogs", 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
|
||||||
|
|
||||||
add_foreign_key "chip_values", "chips", column: "base_chip_id"
|
add_foreign_key "chip_values", "chips", column: "base_chip_id"
|
||||||
add_foreign_key "chip_values", "chips", column: "secondary_chip_id"
|
add_foreign_key "chip_values", "chips", column: "secondary_chip_id"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user