Adds index and show defs, and relatives unit tests

This commit is contained in:
Lou 2021-05-10 16:39:48 +02:00
commit 825c392b37
4 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,22 @@
class Api::V1::TasksController < ApplicationController
before_action :set_task, only: %i[show update destroy]
before_action :check_login
def index
render json: TaskSerializer.new(Task.all).serializable_hash.to_json
end
def show
render json: TaskSerializer.new(@task).serializable_hash.to_json
end
private
def task_params
params.require(:task).permit(:name, :description, :user_id, :activity_id)
end
def set_task
@task = Task.find(params[:id])
end
end

View file

@ -0,0 +1,6 @@
class TaskSerializer
include JSONAPI::Serializer
attributes :name, :description, :user_id, :activity_id
cache_options store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: 1.hour
end