From 1159ce519cb6565dbc298bbc404d4b3fb7bb9dfb Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Thu, 13 Sep 2018 09:25:16 +0200 Subject: [PATCH] Review changes --- app/controllers/api/v1/my_module_groups_controller.rb | 5 ++--- app/serializers/api/v1/connection_serializer.rb | 9 +++++++++ app/serializers/api/v1/my_module_serializer.rb | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/my_module_groups_controller.rb b/app/controllers/api/v1/my_module_groups_controller.rb index f134cb307..1250da749 100644 --- a/app/controllers/api/v1/my_module_groups_controller.rb +++ b/app/controllers/api/v1/my_module_groups_controller.rb @@ -6,7 +6,7 @@ module Api before_action :load_team before_action :load_project before_action :load_experiment - before_action :load_task_groups, only: :show + before_action :load_task_group, only: :show def index my_module_groups = @experiment.my_module_groups @@ -42,11 +42,10 @@ module Api ) end - def load_task_groups + def load_task_group @my_module_group = @experiment.my_module_groups.find( params.require(:id) ) - render jsonapi: {}, status: :not_found if @my_module_group.nil? end end end diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index ed899b22a..98f83c7c7 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -5,6 +5,15 @@ 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 + def input_task + MyModule.find(object.input_id) + end + + def output_task + MyModule.find(object.output_id) + end end end end diff --git a/app/serializers/api/v1/my_module_serializer.rb b/app/serializers/api/v1/my_module_serializer.rb index b52af4157..bc0f43779 100644 --- a/app/serializers/api/v1/my_module_serializer.rb +++ b/app/serializers/api/v1/my_module_serializer.rb @@ -4,8 +4,8 @@ module Api module V1 class MyModuleSerializer < ActiveModel::Serializer type :tasks - attributes :id, :name, :due_date, :description, - :my_module_group_id, :nr_of_assigned_samples, :state + attributes :id, :name, :due_date, :description, :state + attribute :my_module_group_id, key: :task_group_id belongs_to :experiment, serializer: ExperimentSerializer end end