mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-01 18:25:20 +08:00
Fix GET /tasks/:tid/protocols, GET /tasks/:tid/protocols/:id endpts
This commit is contained in:
parent
24299ef4c0
commit
239b974fa0
4 changed files with 22 additions and 12 deletions
|
@ -10,7 +10,7 @@ module Api
|
|||
before_action :load_protocol, only: :show
|
||||
|
||||
def index
|
||||
protocols = @my_module.protocols
|
||||
protocols = @task.protocols
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
|
@ -44,11 +44,11 @@ module Api
|
|||
end
|
||||
|
||||
def load_task
|
||||
@my_module = @experiment.my_modules.find(params.require(:task_id))
|
||||
@task = @experiment.my_modules.find(params.require(:task_id))
|
||||
end
|
||||
|
||||
def load_protocol
|
||||
@protocol = @my_module.protocols.find(
|
||||
@protocol = @task.protocols.find(
|
||||
params.require(:id)
|
||||
)
|
||||
end
|
||||
|
|
10
app/serializers/api/v1/protocol_keyword_serializer.rb
Normal file
10
app/serializers/api/v1/protocol_keyword_serializer.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class ProtocolKeywordSerializer < ActiveModel::Serializer
|
||||
type :protocol_keywords
|
||||
attributes :id, :name
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,12 +4,14 @@ module Api
|
|||
module V1
|
||||
class ProtocolSerializer < ActiveModel::Serializer
|
||||
type :protocols
|
||||
attributes :id, :name, :authors, :description,
|
||||
:team_id, :protocol_type,
|
||||
:nr_of_linked_children
|
||||
attribute :my_module_id, key: :task_id
|
||||
|
||||
belongs_to :my_module, serializer: TaskSerializer
|
||||
attributes :id, :name, :authors, :description, :protocol_type
|
||||
has_many :protocol_keywords,
|
||||
key: :keywords,
|
||||
serializer: ProtocolKeywordSerializer,
|
||||
class_name: 'ProtocolKeyword',
|
||||
unless: -> { object.protocol_keywords.empty? }
|
||||
belongs_to :parent, serializer: ProtocolSerializer,
|
||||
if: -> { object.parent.present? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -575,9 +575,7 @@ Rails.application.routes.draw do
|
|||
resources :task_tags, only: %i(index show),
|
||||
path: 'tags',
|
||||
as: :tags
|
||||
resources :protocols, only: %i(index show),
|
||||
path: 'protocols',
|
||||
as: :protocols
|
||||
resources :protocols, only: %i(index show)
|
||||
resources :results, only: %i(index create show),
|
||||
path: 'results',
|
||||
as: :results
|
||||
|
|
Loading…
Reference in a new issue