mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-30 07:58:28 +08:00
Fix GET /task_groups endpoints
This commit is contained in:
parent
d235dd7807
commit
c9a15db85f
12 changed files with 36 additions and 30 deletions
|
|
@ -14,35 +14,35 @@ module Api
|
||||||
.page(params.dig(:page, :number))
|
.page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
|
|
||||||
render jsonapi: tasks, each_serializer: MyModuleSerializer
|
render jsonapi: tasks, each_serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render jsonapi: @my_module, serializer: MyModuleSerializer
|
render jsonapi: @my_module, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def outputs
|
def outputs
|
||||||
outputs = @my_module.my_modules
|
outputs = @my_module.my_modules
|
||||||
.page(params.dig(:page, :number))
|
.page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
render jsonapi: outputs, each_serializer: MyModuleSerializer
|
render jsonapi: outputs, each_serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def output
|
def output
|
||||||
output = @my_module.my_modules.find(params.require(:id))
|
output = @my_module.my_modules.find(params.require(:id))
|
||||||
render jsonapi: output, serializer: MyModuleSerializer
|
render jsonapi: output, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def inputs
|
def inputs
|
||||||
inputs = @my_module.my_module_antecessors
|
inputs = @my_module.my_module_antecessors
|
||||||
.page(params.dig(:page, :number))
|
.page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
render jsonapi: inputs, each_serializer: MyModuleSerializer
|
render jsonapi: inputs, each_serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def input
|
def input
|
||||||
input = @my_module.my_module_antecessors.find(params.require(:id))
|
input = @my_module.my_module_antecessors.find(params.require(:id))
|
||||||
render jsonapi: input, serializer: MyModuleSerializer
|
render jsonapi: input, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class MyModuleGroupsController < BaseController
|
class TaskGroupsController < BaseController
|
||||||
before_action :load_team
|
before_action :load_team
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :load_experiment
|
before_action :load_experiment
|
||||||
|
|
@ -12,13 +12,16 @@ module Api
|
||||||
my_module_groups = @experiment.my_module_groups
|
my_module_groups = @experiment.my_module_groups
|
||||||
.page(params.dig(:page, :number))
|
.page(params.dig(:page, :number))
|
||||||
.per(params.dig(:page, :size))
|
.per(params.dig(:page, :size))
|
||||||
|
incl = params[:include] == 'tasks' ? :tasks : nil
|
||||||
render jsonapi: my_module_groups,
|
render jsonapi: my_module_groups,
|
||||||
each_serializer: MyModuleGroupSerializer
|
each_serializer: TaskGroupSerializer,
|
||||||
|
include: incl
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render jsonapi: @my_module_group, serializer: MyModuleGroupSerializer
|
render jsonapi: @my_module_group,
|
||||||
|
serializer: TaskGroupSerializer,
|
||||||
|
include: :tasks
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -6,7 +6,7 @@ module Api
|
||||||
type :activities
|
type :activities
|
||||||
attributes :id, :my_module_id, :user_id, :type_of, :message,
|
attributes :id, :my_module_id, :user_id, :type_of, :message,
|
||||||
:project_id, :experiment_id
|
:project_id, :experiment_id
|
||||||
belongs_to :my_module, serializer: MyModuleSerializer
|
belongs_to :my_module, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ module Api
|
||||||
class ConnectionSerializer < ActiveModel::Serializer
|
class ConnectionSerializer < ActiveModel::Serializer
|
||||||
type :connections
|
type :connections
|
||||||
attributes :id, :input_id, :output_id
|
attributes :id, :input_id, :output_id
|
||||||
has_one :input_task, serializer: MyModuleSerializer
|
has_one :input_task, serializer: TaskSerializer
|
||||||
has_one :output_task, serializer: MyModuleSerializer
|
has_one :output_task, serializer: TaskSerializer
|
||||||
def input_task
|
def input_task
|
||||||
MyModule.find(object.input_id)
|
MyModule.find(object.input_id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -6,7 +6,7 @@ module Api
|
||||||
type :task_inventory_rows
|
type :task_inventory_rows
|
||||||
attribute :repository_row_id, key: :inventory_row_id
|
attribute :repository_row_id, key: :inventory_row_id
|
||||||
attribute :my_module_id, key: :task_id
|
attribute :my_module_id, key: :task_id
|
||||||
belongs_to :my_module, serializer: MyModuleSerializer
|
belongs_to :my_module, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ module Api
|
||||||
attributes :id, :tag_id
|
attributes :id, :tag_id
|
||||||
attribute :my_module_id, key: :task_id
|
attribute :my_module_id, key: :task_id
|
||||||
|
|
||||||
belongs_to :my_module, serializer: MyModuleSerializer
|
belongs_to :my_module, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ module Api
|
||||||
:nr_of_linked_children
|
:nr_of_linked_children
|
||||||
attribute :my_module_id, key: :task_id
|
attribute :my_module_id, key: :task_id
|
||||||
|
|
||||||
belongs_to :my_module, serializer: MyModuleSerializer
|
belongs_to :my_module, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ module Api
|
||||||
attributes :name, :user_id, :archived
|
attributes :name, :user_id, :archived
|
||||||
attribute :my_module_id, key: :task_id
|
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,
|
has_one :result_asset, key: :asset,
|
||||||
serializer: ResultAssetSerializer,
|
serializer: ResultAssetSerializer,
|
||||||
class_name: 'ResultAsset',
|
class_name: 'ResultAsset',
|
||||||
|
|
|
||||||
14
app/serializers/api/v1/task_group_serializer.rb
Normal file
14
app/serializers/api/v1/task_group_serializer.rb
Normal 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
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
module Api
|
module Api
|
||||||
module V1
|
module V1
|
||||||
class MyModuleSerializer < ActiveModel::Serializer
|
class TaskSerializer < ActiveModel::Serializer
|
||||||
type :tasks
|
type :tasks
|
||||||
attributes :id, :name, :due_date, :description, :state
|
attributes :id, :name, :due_date, :description, :state
|
||||||
attribute :my_module_group_id, key: :task_group_id
|
attribute :my_module_group_id, key: :task_group_id
|
||||||
|
|
@ -7,7 +7,7 @@ module Api
|
||||||
attributes :id, :user_id
|
attributes :id, :user_id
|
||||||
attribute :my_module_id, key: :task_id
|
attribute :my_module_id, key: :task_id
|
||||||
|
|
||||||
belongs_to :my_module, serializer: MyModuleSerializer
|
belongs_to :my_module, serializer: TaskSerializer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue