Fix GET /tasks/:tid/protocols, GET /tasks/:tid/protocols/:id endpts

This commit is contained in:
Luka Murn 2018-10-07 11:29:56 +02:00
parent 24299ef4c0
commit 239b974fa0
4 changed files with 22 additions and 12 deletions

View file

@ -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

View 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

View file

@ -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

View file

@ -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