Fix GET /task_groups endpoints

This commit is contained in:
Luka Murn 2018-10-06 19:53:31 +02:00
parent d235dd7807
commit c9a15db85f
12 changed files with 36 additions and 30 deletions

View file

@ -14,35 +14,35 @@ module Api
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: tasks, each_serializer: MyModuleSerializer
render jsonapi: tasks, each_serializer: TaskSerializer
end
def show
render jsonapi: @my_module, serializer: MyModuleSerializer
render jsonapi: @my_module, serializer: TaskSerializer
end
def outputs
outputs = @my_module.my_modules
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: outputs, each_serializer: MyModuleSerializer
render jsonapi: outputs, each_serializer: TaskSerializer
end
def output
output = @my_module.my_modules.find(params.require(:id))
render jsonapi: output, serializer: MyModuleSerializer
render jsonapi: output, serializer: TaskSerializer
end
def inputs
inputs = @my_module.my_module_antecessors
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
render jsonapi: inputs, each_serializer: MyModuleSerializer
render jsonapi: inputs, each_serializer: TaskSerializer
end
def input
input = @my_module.my_module_antecessors.find(params.require(:id))
render jsonapi: input, serializer: MyModuleSerializer
render jsonapi: input, serializer: TaskSerializer
end
private

View file

@ -2,7 +2,7 @@
module Api
module V1
class MyModuleGroupsController < BaseController
class TaskGroupsController < BaseController
before_action :load_team
before_action :load_project
before_action :load_experiment
@ -12,13 +12,16 @@ module Api
my_module_groups = @experiment.my_module_groups
.page(params.dig(:page, :number))
.per(params.dig(:page, :size))
incl = params[:include] == 'tasks' ? :tasks : nil
render jsonapi: my_module_groups,
each_serializer: MyModuleGroupSerializer
each_serializer: TaskGroupSerializer,
include: incl
end
def show
render jsonapi: @my_module_group, serializer: MyModuleGroupSerializer
render jsonapi: @my_module_group,
serializer: TaskGroupSerializer,
include: :tasks
end
private

View file

@ -6,7 +6,7 @@ module Api
type :activities
attributes :id, :my_module_id, :user_id, :type_of, :message,
:project_id, :experiment_id
belongs_to :my_module, serializer: MyModuleSerializer
belongs_to :my_module, serializer: TaskSerializer
end
end
end

View file

@ -5,8 +5,8 @@ module Api
class ConnectionSerializer < ActiveModel::Serializer
type :connections
attributes :id, :input_id, :output_id
has_one :input_task, serializer: MyModuleSerializer
has_one :output_task, serializer: MyModuleSerializer
has_one :input_task, serializer: TaskSerializer
has_one :output_task, serializer: TaskSerializer
def input_task
MyModule.find(object.input_id)
end

View file

@ -1,11 +0,0 @@
# frozen_string_literal: true
module Api
module V1
class MyModuleGroupSerializer < ActiveModel::Serializer
type :task_groups
attributes :id, :experiment_id
belongs_to :experiment, serializer: ExperimentSerializer
end
end
end

View file

@ -6,7 +6,7 @@ module Api
type :task_inventory_rows
attribute :repository_row_id, key: :inventory_row_id
attribute :my_module_id, key: :task_id
belongs_to :my_module, serializer: MyModuleSerializer
belongs_to :my_module, serializer: TaskSerializer
end
end
end

View file

@ -7,7 +7,7 @@ module Api
attributes :id, :tag_id
attribute :my_module_id, key: :task_id
belongs_to :my_module, serializer: MyModuleSerializer
belongs_to :my_module, serializer: TaskSerializer
end
end
end

View file

@ -9,7 +9,7 @@ module Api
:nr_of_linked_children
attribute :my_module_id, key: :task_id
belongs_to :my_module, serializer: MyModuleSerializer
belongs_to :my_module, serializer: TaskSerializer
end
end
end

View file

@ -7,7 +7,7 @@ module Api
attributes :name, :user_id, :archived
attribute :my_module_id, key: :task_id
belongs_to :my_module, serializer: MyModuleSerializer
belongs_to :my_module, serializer: TaskSerializer
has_one :result_asset, key: :asset,
serializer: ResultAssetSerializer,
class_name: 'ResultAsset',

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
module Api
module V1
class TaskGroupSerializer < ActiveModel::Serializer
type :task_groups
attributes :id
has_many :my_modules, key: :tasks,
serializer: TaskSerializer,
class_name: 'MyModule',
unless: -> { object.my_modules.empty? }
end
end
end

View file

@ -2,7 +2,7 @@
module Api
module V1
class MyModuleSerializer < ActiveModel::Serializer
class TaskSerializer < ActiveModel::Serializer
type :tasks
attributes :id, :name, :due_date, :description, :state
attribute :my_module_group_id, key: :task_group_id

View file

@ -7,7 +7,7 @@ module Api
attributes :id, :user_id
attribute :my_module_id, key: :task_id
belongs_to :my_module, serializer: MyModuleSerializer
belongs_to :my_module, serializer: TaskSerializer
end
end
end