diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index d147e63c2..a948dfb4f 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -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)) diff --git a/app/serializers/api/v1/task_serializer.rb b/app/serializers/api/v1/task_serializer.rb index ba5461fd2..20660805c 100644 --- a/app/serializers/api/v1/task_serializer.rb +++ b/app/serializers/api/v1/task_serializer.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 42df5777e..12b526589 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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