Homies and money moves
This commit is contained in:
2
app/controllers/homies_controller.rb
Normal file
2
app/controllers/homies_controller.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class HomiesController < ApplicationController::API
|
||||
end
|
||||
23
app/controllers/money_moves_controller.rb
Normal file
23
app/controllers/money_moves_controller.rb
Normal 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
|
||||
0
app/models/concerns/error_response.rb
Normal file
0
app/models/concerns/error_response.rb
Normal file
5
app/models/concerns/json_response.rb
Normal file
5
app/models/concerns/json_response.rb
Normal 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
4
app/models/homie.rb
Normal 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
4
app/models/money_move.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class MoneyMove < ApplicationRecord
|
||||
belongs_to :from_homie, class_name: 'Homie'
|
||||
belongs_to :to_homie, class_name: 'Homie'
|
||||
end
|
||||
Reference in New Issue
Block a user