diff --git a/app/controllers/api/v1/my_modules_controller.rb b/app/controllers/api/v1/my_modules_controller.rb index 37a2b757d..7a9e3e41a 100644 --- a/app/controllers/api/v1/my_modules_controller.rb +++ b/app/controllers/api/v1/my_modules_controller.rb @@ -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 diff --git a/app/controllers/api/v1/my_module_groups_controller.rb b/app/controllers/api/v1/task_groups_controller.rb similarity index 80% rename from app/controllers/api/v1/my_module_groups_controller.rb rename to app/controllers/api/v1/task_groups_controller.rb index 1250da749..f586c2664 100644 --- a/app/controllers/api/v1/my_module_groups_controller.rb +++ b/app/controllers/api/v1/task_groups_controller.rb @@ -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 diff --git a/app/serializers/api/v1/activity_serializer.rb b/app/serializers/api/v1/activity_serializer.rb index 70332ce2d..28910b7f5 100644 --- a/app/serializers/api/v1/activity_serializer.rb +++ b/app/serializers/api/v1/activity_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index 98f83c7c7..d75c41d18 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/my_module_group_serializer.rb b/app/serializers/api/v1/my_module_group_serializer.rb deleted file mode 100644 index 06b52e31e..000000000 --- a/app/serializers/api/v1/my_module_group_serializer.rb +++ /dev/null @@ -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 diff --git a/app/serializers/api/v1/my_module_repository_row_serializer.rb b/app/serializers/api/v1/my_module_repository_row_serializer.rb index 1133b6263..4b543d012 100644 --- a/app/serializers/api/v1/my_module_repository_row_serializer.rb +++ b/app/serializers/api/v1/my_module_repository_row_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/my_module_tag_serializer.rb b/app/serializers/api/v1/my_module_tag_serializer.rb index 7f8e4a2e6..a35c39865 100644 --- a/app/serializers/api/v1/my_module_tag_serializer.rb +++ b/app/serializers/api/v1/my_module_tag_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 6efafeddc..9f255b377 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index 84aeb1408..5e990f1cb 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -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', diff --git a/app/serializers/api/v1/task_group_serializer.rb b/app/serializers/api/v1/task_group_serializer.rb new file mode 100644 index 000000000..2b7579e8f --- /dev/null +++ b/app/serializers/api/v1/task_group_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/my_module_serializer.rb b/app/serializers/api/v1/task_serializer.rb similarity index 83% rename from app/serializers/api/v1/my_module_serializer.rb rename to app/serializers/api/v1/task_serializer.rb index bc0f43779..8e2aa9cf0 100644 --- a/app/serializers/api/v1/my_module_serializer.rb +++ b/app/serializers/api/v1/task_serializer.rb @@ -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 diff --git a/app/serializers/api/v1/user_my_module_serializer.rb b/app/serializers/api/v1/user_my_module_serializer.rb index 6474b8316..87edc39ce 100644 --- a/app/serializers/api/v1/user_my_module_serializer.rb +++ b/app/serializers/api/v1/user_my_module_serializer.rb @@ -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