Return task inputs/outputs as references [SCI-2822]

This commit is contained in:
Oleksii Kriuchykhin 2018-11-28 11:33:00 +01:00
parent 20e2cbf0ca
commit b3a377f949
3 changed files with 15 additions and 17 deletions

View file

@ -9,7 +9,7 @@ module Api
before_action only: :show do
load_task(:id)
end
before_action :load_task_relative, only: %i(inputs outputs activities)
before_action :load_task_relative, only: :activities
def index
tasks = @experiment.my_modules
@ -23,20 +23,6 @@ module Api
render jsonapi: @task, serializer: TaskSerializer
end
def inputs
inputs = @task.my_module_antecessors
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: inputs, each_serializer: TaskSerializer
end
def outputs
outputs = @task.my_modules
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: outputs, each_serializer: TaskSerializer
end
def activities
activities = @task.activities
.page(params.dig(:page, :number))

View file

@ -5,6 +5,20 @@ module Api
class TaskSerializer < ActiveModel::Serializer
type :tasks
attributes :id, :name, :due_date, :description, :state, :archived
has_many :output_tasks, key: :outputs,
serializer: TaskSerializer,
class_name: 'MyModule'
has_many :input_tasks, key: :inputs,
serializer: TaskSerializer,
class_name: 'MyModule'
def output_tasks
object.my_modules
end
def input_tasks
object.my_module_antecessors
end
end
end
end

View file

@ -607,8 +607,6 @@ Rails.application.routes.draw do
as: :tags
resources :protocols, only: %i(index show)
resources :results, only: %i(index create show)
get 'inputs', to: 'tasks#inputs'
get 'outputs', to: 'tasks#outputs'
get 'activities', to: 'tasks#activities'
end
end