working on update def

This commit is contained in:
Lou 2021-05-12 21:17:46 +02:00
commit ee6916d0f5
2 changed files with 50 additions and 1 deletions

View file

@ -1,5 +1,5 @@
class Api::V1::RecordsController < ApplicationController
before_action :set_record, only: %i[show update destroy]
before_action :set_record, only: %i[show update]
before_action :check_login
def index
@ -10,6 +10,23 @@ class Api::V1::RecordsController < ApplicationController
render json: RecordSerializer.new(@record).serializable_hash.to_json
end
def create
record = current_user.records.build(record_params)
record.task_id = params[:task_id]
if record.save
render json: RecordSerializer.new(record).serializable_hash.to_json, status: :created
else
render json: { errors: record.errors }, status: :unprocessable_entity
end
end
def update
if @record.update(handled_by_id = current_user.id)
render json: RecordSerializer.new(@record).serializable_hash.to_json, status: :ok
else
render json: @task.errors, status: :unprocessable_entity
end
end
private
@ -18,6 +35,10 @@ class Api::V1::RecordsController < ApplicationController
params.require(:record).permit(:duration, :user_id, :task_id, :is_handled, :handled_by_id)
end
# def record_params_update
# params.require(:record).permit(:is_handled, :handled_by_id)
# end
def set_record
@record = Task.find(params[:task_id]).records.find(params[:id])
end