Skip to content

Commit

Permalink
Add approve and dicline action to reservations_controller #7
Browse files Browse the repository at this point in the history
  • Loading branch information
25 macamp committed Sep 7, 2019
1 parent feb69b0 commit a55ef9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/controllers/api/v1/reservations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ def create
end
end

def approve
reservation = Reservation.find(params[:id])
if current_user.id == reservation.room.user_id
reservation.Approved!
render json: { is_success: true }, status: :ok
else
render json: { error: 'No Permission', is_success: false }, status: 404
end
end

def dicline
reservation = Reservation.find(params[:id])
if current_user.id == reservation.room.user_id
reservation.Dicline!
render json: { is_success: true }, status: :ok
else
render json: { error: 'No Permission', is_success: false }, status: 404
end
end

private

def reservation_params
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
namespace :v1 do
resources :rooms, only: %i[index create destroy] do
resources :photos, only: %i[create destroy]
resources :reservations, only: %i[create]
resources :reservations, only: %i[create] do
member do
patch 'approve', to: 'reservations#approve'
patch 'dicline', to: 'reservations#dicline'
end
end
end

post 'signup', to: 'users#create'
Expand Down

0 comments on commit a55ef9f

Please sign in to comment.