Adds def update to activity controller, and unit tests
This commit is contained in:
parent
7249e53c27
commit
26ee834214
3 changed files with 43 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
class Api::V1::ActivitiesController < ApplicationController
|
||||
before_action :set_activity, only: %i[show update destroy]
|
||||
before_action :check_login
|
||||
before_action :check_owner, only: %i[update]
|
||||
|
||||
def index
|
||||
render json: Activity.all
|
||||
|
|
@ -19,6 +20,14 @@ class Api::V1::ActivitiesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @activity.update(activity_params)
|
||||
render json: @product
|
||||
else
|
||||
render json: @product.erros, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
|
|
@ -29,4 +38,8 @@ class Api::V1::ActivitiesController < ApplicationController
|
|||
def set_activity
|
||||
@activity = Activity.find(params[:id])
|
||||
end
|
||||
|
||||
def check_owner
|
||||
head :forbidden unless @activity.author_id == current_user&.id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue