Skip to content

Commit

Permalink
Implement user update
Browse files Browse the repository at this point in the history
  • Loading branch information
xlpero committed Mar 6, 2019
1 parent ca5e782 commit 1f1d504
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,25 @@ def create
end

def update
render json: {}, status: 501
user_id = params[:id]
user = User.find_by_id(user_id)
# TBD: check user
if user
user.update_attributes(permitted_params)
render json: {user: user}, status: 200
else
render json: {}, status: 404
end
rescue => error
render json: {}, status: 500
end

def delete
render json: {}, status: 501
end

private
def permitted_params
params.require(:user).permit([:managing_group_id, :pickup_location_id])
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get 'users' => 'users#index'
get 'users/:id' => 'users#show', :constraints => { :id => /[0-9]+/ }
get 'users/:xkonto' => 'users#show_by_xkonto', :constraints => { :xkonto => /[A-Za-z]+/ }
put 'users/:id' => 'users#update', :constraints => { :id => /[0-9]+/ }

get 'statuses' => 'statuses#index'
get 'statuses/:id' => 'statuses#show', :constraints => { :id => /[0-9]+/ }
Expand Down

0 comments on commit 1f1d504

Please sign in to comment.