Homies and money moves

This commit is contained in:
Senad Uka
2019-06-20 22:47:39 +02:00
parent 48300b722c
commit 877f0425d0
17 changed files with 150 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
class HomiesController < ApplicationController::API
end

View File

@@ -0,0 +1,23 @@
class MoneyMovesController < ApplicationController::API
def list
json_response(MoneyMove.find(:all).order(:created_at))
end
def create
money_move = MoneyMove.new(money_move_params)
if money_move.save
json_response(money_move)
else
error_response(:bad_request)
end
end
def money_move_params
params.require(:money_moves).permit(
:description,
:amount,
:from_homie_id,
:to_homie_id
)
end
end

View File

View File

@@ -0,0 +1,5 @@
module Response
def json_response(object, status = :ok)
render json: object, status: status
end
end

4
app/models/homie.rb Normal file
View File

@@ -0,0 +1,4 @@
class Homie < ApplicationRecord
has_many :money_moves_from, class_name: 'MoneyMove', column: :from_homie_id
has_many :money_moves_to, class_name: 'MoneyMove', column: :to_homie_id
end

4
app/models/money_move.rb Normal file
View File

@@ -0,0 +1,4 @@
class MoneyMove < ApplicationRecord
belongs_to :from_homie, class_name: 'Homie'
belongs_to :to_homie, class_name: 'Homie'
end