handle adding work for homie
This commit is contained in:
31
app/controllers/work_controller.rb
Normal file
31
app/controllers/work_controller.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
class WorkController < ApplicationController
|
||||||
|
def index
|
||||||
|
if params[:homie_id]
|
||||||
|
work = Work.where(homie_id: params[:homie_id].to_i).all.order(created_at: :desc)
|
||||||
|
else
|
||||||
|
work = Work.all.order(created_at: :desc)
|
||||||
|
end
|
||||||
|
|
||||||
|
json_response work
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
work = Work.new(work_params)
|
||||||
|
|
||||||
|
if work.save
|
||||||
|
json_response ok: true
|
||||||
|
else
|
||||||
|
error_response(:bad_request)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def work_params
|
||||||
|
params.require(:work).permit(
|
||||||
|
:description,
|
||||||
|
:amount,
|
||||||
|
:homie_id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
class Homie < ApplicationRecord
|
class Homie < ApplicationRecord
|
||||||
has_many :money_moves
|
has_many :money_moves
|
||||||
|
has_many :work
|
||||||
belongs_to :chip
|
belongs_to :chip
|
||||||
|
|
||||||
def self.cash(importance)
|
def self.cash(importance)
|
||||||
|
|||||||
3
app/models/work.rb
Normal file
3
app/models/work.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Work < ApplicationRecord
|
||||||
|
belongs_to :homie
|
||||||
|
end
|
||||||
@@ -14,3 +14,7 @@
|
|||||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
# inflect.acronym 'RESTful'
|
# inflect.acronym 'RESTful'
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
ActiveSupport::Inflector.inflections do |inflect|
|
||||||
|
inflect.irregular 'work', 'work'
|
||||||
|
end
|
||||||
@@ -2,6 +2,7 @@ Rails.application.routes.draw do
|
|||||||
constraints format: :json do
|
constraints format: :json do
|
||||||
scope :api do
|
scope :api do
|
||||||
resources :money_moves
|
resources :money_moves
|
||||||
|
resources :work
|
||||||
resources :chips, only: %i[index create destroy]
|
resources :chips, only: %i[index create destroy]
|
||||||
resources :chip_values, only: %i[create update destroy]
|
resources :chip_values, only: %i[create update destroy]
|
||||||
resources :homies, param: :homie_id do
|
resources :homies, param: :homie_id do
|
||||||
|
|||||||
11
db/migrate/20200919023237_create_work.rb
Normal file
11
db/migrate/20200919023237_create_work.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class CreateWork < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :work do |t|
|
||||||
|
t.text :description
|
||||||
|
t.integer :amount
|
||||||
|
t.integer :homie_id, null: false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
22
db/schema.rb
22
db/schema.rb
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_09_11_171657) do
|
ActiveRecord::Schema.define(version: 2020_09_19_023237) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -41,8 +41,6 @@ ActiveRecord::Schema.define(version: 2020_09_11_171657) 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|
|
||||||
@@ -53,6 +51,24 @@ ActiveRecord::Schema.define(version: 2020_09_11_171657) 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
|
||||||
|
|
||||||
|
create_table "work", force: :cascade do |t|
|
||||||
|
t.text "description"
|
||||||
|
t.integer "amount"
|
||||||
|
t.integer "homie_id", null: false
|
||||||
|
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