CRUD API ready
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
class ApplicationController < ActionController::API
|
||||
include Response
|
||||
end
|
||||
|
||||
9
app/controllers/concerns/response.rb
Normal file
9
app/controllers/concerns/response.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module Response
|
||||
def error_response(status)
|
||||
render nothing: true, status: status
|
||||
end
|
||||
|
||||
def json_response(object, status = :ok)
|
||||
render json: object, status: status
|
||||
end
|
||||
end
|
||||
@@ -1,2 +1,22 @@
|
||||
class HomiesController < ApplicationController::API
|
||||
class HomiesController < ApplicationController
|
||||
def index
|
||||
json_response(Homie.all.order(:created_at))
|
||||
end
|
||||
|
||||
def create
|
||||
homie = Homie.new(homie_params)
|
||||
if homie.save
|
||||
json_response(homie)
|
||||
else
|
||||
error_response(:bad_request)
|
||||
end
|
||||
end
|
||||
|
||||
def homie_params
|
||||
params.require(:homie).permit(
|
||||
:name,
|
||||
:importance,
|
||||
:about
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MoneyMovesController < ApplicationController::API
|
||||
def list
|
||||
class MoneyMovesController < ApplicationController
|
||||
def index
|
||||
json_response(MoneyMove.find(:all).order(:created_at))
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class MoneyMovesController < ApplicationController::API
|
||||
end
|
||||
|
||||
def money_move_params
|
||||
params.require(:money_moves).permit(
|
||||
params.require(:money_move).permit(
|
||||
:description,
|
||||
:amount,
|
||||
:from_homie_id,
|
||||
|
||||
Reference in New Issue
Block a user