Adds index and show defs, and relatives unit tests
This commit is contained in:
parent
5584e328b1
commit
825c392b37
4 changed files with 65 additions and 0 deletions
22
app/controllers/api/v1/tasks_controller.rb
Normal file
22
app/controllers/api/v1/tasks_controller.rb
Normal 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
|
||||
6
app/serializers/task_serializer.rb
Normal file
6
app/serializers/task_serializer.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue