From 2d3f5f237736f951f4d9782552b99d210564f333 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Fri, 7 Sep 2018 13:36:55 +0200 Subject: [PATCH 01/12] new routes for endpoints --- config/routes.rb | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index c5526946d..424e00b76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -540,7 +540,7 @@ Rails.application.routes.draw do get 'health', to: 'api#health' get 'status', to: 'api#status' post 'auth/token', to: 'api#authenticate' - if Api.configuration.core_api_v1_preview + #if Api.configuration.core_api_v1_preview namespace :v1 do resources :teams, only: %i(index show) do resources :inventories, @@ -559,7 +559,32 @@ Rails.application.routes.draw do resources :my_modules, only: %i(index show), path: 'tasks', - as: :tasks + as: :tasks do + resources :my_module_repository_rows, only: %i(index show), + path: 'task_inventory_rows', + as: :task_inventory_rows + resources :user_my_modules, only: %i(index show), + path: 'user_tasks', + as: :user_tasks + resources :my_module_tags, only: %i(index show), + path: 'task_tags', + as: :task_tags + resources :protocols, only: %i(index show), + path: 'protocols', + as: :protocols + resources :results, only: %i(index show), + path: 'results', + as: :results + resources :my_module_antecessors, only: %i(index show), + path: 'ancestors', + as: :ancestors + resources :my_modules, only: %i(index show), + path: 'descendants', + as: :descendants + resources :activities, only: %i(index show), + path: 'activities', + as: :activities + end resources :my_module_groups, only: %i(index show), path: 'task_groups', @@ -575,7 +600,7 @@ Rails.application.routes.draw do only: %i(index create show update destroy) end end - end + #end end end end From bad07841daaf0aa5152d546251d6192b1b01c609 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Fri, 7 Sep 2018 15:19:20 +0200 Subject: [PATCH 02/12] Created new controllers and serializers for nested task related attributes --- .../api/v1/activities_controller.rb | 59 +++++++++++++++++++ .../my_module_repository_rows_controller.rb | 59 +++++++++++++++++++ .../api/v1/my_module_tags_controller.rb | 59 +++++++++++++++++++ .../v1/my_modules_antecessors_controller.rb | 0 .../api/v1/protocols_controller.rb | 59 +++++++++++++++++++ app/controllers/api/v1/results_controller.rb | 59 +++++++++++++++++++ .../api/v1/user_my_modules_controller.rb | 59 +++++++++++++++++++ app/serializers/api/v1/activity_serializer.rb | 12 ++++ .../v1/my_module_antecessors_serializer.rb | 0 .../v1/my_module_repository_row_serializer.rb | 12 ++++ .../api/v1/my_module_tag_serializer.rb | 11 ++++ app/serializers/api/v1/protocol_serializer.rb | 15 +++++ app/serializers/api/v1/result_serializer.rb | 14 +++++ .../api/v1/user_my_module_serializer.rb | 12 ++++ 14 files changed, 430 insertions(+) create mode 100644 app/controllers/api/v1/activities_controller.rb create mode 100644 app/controllers/api/v1/my_module_repository_rows_controller.rb create mode 100644 app/controllers/api/v1/my_module_tags_controller.rb create mode 100644 app/controllers/api/v1/my_modules_antecessors_controller.rb create mode 100644 app/controllers/api/v1/protocols_controller.rb create mode 100644 app/controllers/api/v1/results_controller.rb create mode 100644 app/controllers/api/v1/user_my_modules_controller.rb create mode 100644 app/serializers/api/v1/activity_serializer.rb create mode 100644 app/serializers/api/v1/my_module_antecessors_serializer.rb create mode 100644 app/serializers/api/v1/my_module_repository_row_serializer.rb create mode 100644 app/serializers/api/v1/my_module_tag_serializer.rb create mode 100644 app/serializers/api/v1/protocol_serializer.rb create mode 100644 app/serializers/api/v1/result_serializer.rb create mode 100644 app/serializers/api/v1/user_my_module_serializer.rb diff --git a/app/controllers/api/v1/activities_controller.rb b/app/controllers/api/v1/activities_controller.rb new file mode 100644 index 000000000..125c44c86 --- /dev/null +++ b/app/controllers/api/v1/activities_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Api + module V1 + class ActivitiesController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_activity, only: :show + + def index + activities = @my_module.activities + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: activities, + each_serializer: ActivitySerializer + end + + def show + render jsonapi: @activity, serializer: ActivitySerializer + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end + + def load_activity + @activity = @my_module.activities.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @activity.nil? + end + end + end +end diff --git a/app/controllers/api/v1/my_module_repository_rows_controller.rb b/app/controllers/api/v1/my_module_repository_rows_controller.rb new file mode 100644 index 000000000..cdb2317ea --- /dev/null +++ b/app/controllers/api/v1/my_module_repository_rows_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Api + module V1 + class MyModuleRepositoryRowsController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_task_repository_row, only: :show + + def index + repo_rows = @my_module.my_module_repository_rows + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: repo_rows, + each_serializer: MyModuleRepositoryRowSerializer + end + + def show + render jsonapi: @repo_row, serializer: MyModuleRepositoryRowSerializer + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end + + def load_task_repository_row + @repo_row = @my_module.my_module_repository_rows.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @repo_row.nil? + end + end + end +end diff --git a/app/controllers/api/v1/my_module_tags_controller.rb b/app/controllers/api/v1/my_module_tags_controller.rb new file mode 100644 index 000000000..1d2ce6cab --- /dev/null +++ b/app/controllers/api/v1/my_module_tags_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Api + module V1 + class MyModuleTagsController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_task_repository_row, only: :show + + def index + task_tags = @my_module.my_module_tags + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: task_tags, + each_serializer: MyModuleTagSerializer + end + + def show + render jsonapi: @task_tag, serializer: MyModuleTagSerializer + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end + + def load_task_repository_row + @task_tag = @my_module.my_module_tags.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @task_tag.nil? + end + end + end +end diff --git a/app/controllers/api/v1/my_modules_antecessors_controller.rb b/app/controllers/api/v1/my_modules_antecessors_controller.rb new file mode 100644 index 000000000..e69de29bb diff --git a/app/controllers/api/v1/protocols_controller.rb b/app/controllers/api/v1/protocols_controller.rb new file mode 100644 index 000000000..13701832f --- /dev/null +++ b/app/controllers/api/v1/protocols_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Api + module V1 + class ProtocolsController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_protocol, only: :show + + def index + protocols = @my_module.protocols + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: protocols, + each_serializer: ProtocolSerializer + end + + def show + render jsonapi: @protocol, serializer: ProtocolSerializer + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end + + def load_protocol + @protocol = @my_module.protocols.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @protocol.nil? + end + end + end +end diff --git a/app/controllers/api/v1/results_controller.rb b/app/controllers/api/v1/results_controller.rb new file mode 100644 index 000000000..194116a7c --- /dev/null +++ b/app/controllers/api/v1/results_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Api + module V1 + class ResultsController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_result, only: :show + + def index + results = @my_module.results + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: results, + each_serializer: ResultSerializer + end + + def show + render jsonapi: @result, serializer: ResultSerializer + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end + + def load_result + @result = @my_module.results.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @result.nil? + end + end + end +end diff --git a/app/controllers/api/v1/user_my_modules_controller.rb b/app/controllers/api/v1/user_my_modules_controller.rb new file mode 100644 index 000000000..f3a91b9ad --- /dev/null +++ b/app/controllers/api/v1/user_my_modules_controller.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Api + module V1 + class UserMyModulesController < BaseController + before_action :load_team + before_action :load_project + before_action :load_experiment + before_action :load_task + before_action :load_user_task, only: :show + + def index + user_tasks = @my_module.user_my_modules + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + + render jsonapi: user_tasks, + each_serializer: UserMyModuleSerializer + end + + def show + render jsonapi: @user_task, serializer: UserMyModuleSerializer + end + + private + + def load_team + @team = Team.find(params.require(:team_id)) + render jsonapi: {}, status: :forbidden unless can_read_team?(@team) + end + + def load_project + @project = @team.projects.find(params.require(:project_id)) + render jsonapi: {}, status: :forbidden unless can_read_project?( + @project + ) + end + + def load_experiment + @experiment = @project.experiments.find(params.require(:experiment_id)) + render jsonapi: {}, status: :forbidden unless can_read_experiment?( + @experiment + ) + end + + def load_task + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end + + def load_user_task + @user_task = @my_module.user_my_modules.find( + params.require(:id) + ) + render jsonapi: {}, status: :not_found if @user_task.nil? + end + end + end +end diff --git a/app/serializers/api/v1/activity_serializer.rb b/app/serializers/api/v1/activity_serializer.rb new file mode 100644 index 000000000..11dee4dc1 --- /dev/null +++ b/app/serializers/api/v1/activity_serializer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V1 + class ActivitySerializer < ActiveModel::Serializer + type :activities + attributes :id, :my_module_id, :user_id, :type_of, :message, :created_at, + :updated_at, :project_id, :experiment_id + belongs_to :my_module, serializer: MyModuleSerializer + end + end +end diff --git a/app/serializers/api/v1/my_module_antecessors_serializer.rb b/app/serializers/api/v1/my_module_antecessors_serializer.rb new file mode 100644 index 000000000..e69de29bb diff --git a/app/serializers/api/v1/my_module_repository_row_serializer.rb b/app/serializers/api/v1/my_module_repository_row_serializer.rb new file mode 100644 index 000000000..db89f7515 --- /dev/null +++ b/app/serializers/api/v1/my_module_repository_row_serializer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V1 + class MyModuleRepositoryRowSerializer < ActiveModel::Serializer + type :task_inventory_rows + attributes :id, :repository_row_id, :my_module_id, :assigned_by_id, + :created_at, :updated_at + belongs_to :my_module, serializer: MyModuleSerializer + 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 new file mode 100644 index 000000000..d395887e7 --- /dev/null +++ b/app/serializers/api/v1/my_module_tag_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Api + module V1 + class MyModuleTagSerializer < ActiveModel::Serializer + type :task_tags + attributes :id, :my_module_id, :tag_id, :created_by_id + belongs_to :my_module, serializer: MyModuleSerializer + end + end +end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb new file mode 100644 index 000000000..33366de9e --- /dev/null +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Api + module V1 + class ProtocolSerializer < ActiveModel::Serializer + type :protocols + attributes :id, :name, :authors, :description, :added_by_id, + :my_module_id, :team_id, :protocol_type, :parent_id, + :parent_updated_at, :archived_by_id, :archived_on, + :restored_by_id, :restored_on, :created_at, :updated_at, + :published_on, :nr_of_linked_children + belongs_to :my_module, serializer: MyModuleSerializer + end + end +end diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb new file mode 100644 index 000000000..b90f9fa7c --- /dev/null +++ b/app/serializers/api/v1/result_serializer.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Api + module V1 + class ResultSerializer < ActiveModel::Serializer + type :results + attributes :id, :name, :my_module_id, :user_id, :created_at, :updated_at, + :archived, :archived_on, :last_modified_by_id, :archived_by_id, + :restored_by_id, :restored_on + + belongs_to :my_module, serializer: MyModuleSerializer + end + end +end diff --git a/app/serializers/api/v1/user_my_module_serializer.rb b/app/serializers/api/v1/user_my_module_serializer.rb new file mode 100644 index 000000000..cee99d9f3 --- /dev/null +++ b/app/serializers/api/v1/user_my_module_serializer.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V1 + class UserMyModuleSerializer < ActiveModel::Serializer + type :user_tasks + attributes :id, :user_id, :my_module_id, :created_at, + :updated_at, :assigned_by_id + belongs_to :my_module, serializer: MyModuleSerializer + end + end +end From e82af2186efb61be1d340a71880302fc3f1df4d2 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Fri, 7 Sep 2018 15:52:30 +0200 Subject: [PATCH 03/12] Route comment --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index 424e00b76..1df86160d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -581,6 +581,8 @@ Rails.application.routes.draw do resources :my_modules, only: %i(index show), path: 'descendants', as: :descendants + # The above two are just my modules (tasks), so im not sure + # if i should duplicate controllers and serializers resources :activities, only: %i(index show), path: 'activities', as: :activities From 30c4fac2aee63432bffc5fa9f1dd2755b312e190 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Mon, 10 Sep 2018 14:22:27 +0200 Subject: [PATCH 04/12] Added task inputs and outputs functionality --- .../v1/my_modules_antecessors_controller.rb | 0 .../api/v1/my_modules_controller.rb | 36 +++++++++++++++++++ .../v1/my_module_antecessors_serializer.rb | 0 config/routes.rb | 19 +++++----- 4 files changed, 44 insertions(+), 11 deletions(-) delete mode 100644 app/controllers/api/v1/my_modules_antecessors_controller.rb delete mode 100644 app/serializers/api/v1/my_module_antecessors_serializer.rb diff --git a/app/controllers/api/v1/my_modules_antecessors_controller.rb b/app/controllers/api/v1/my_modules_antecessors_controller.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/controllers/api/v1/my_modules_controller.rb b/app/controllers/api/v1/my_modules_controller.rb index 5ec6ffa0c..4f1ebd7fd 100644 --- a/app/controllers/api/v1/my_modules_controller.rb +++ b/app/controllers/api/v1/my_modules_controller.rb @@ -7,6 +7,7 @@ module Api before_action :load_project before_action :load_experiment before_action :load_task, only: :show + before_action :load_task_relative, only: %i(outputs output inputs input) def index tasks = @experiment.my_modules @@ -20,6 +21,32 @@ module Api render jsonapi: @my_module, serializer: MyModuleSerializer end + def outputs + outputs = @my_module.my_modules + .page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) + render jsonapi: outputs, each_serializer: MyModuleSerializer + end + + def output + output = @my_module.my_modules.find(params.require(:id)) + render jsonapi: {}, status: :not_found if output.nil? + render jsonapi: output, serializer: MyModuleSerializer + 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 + end + + def input + input = @my_module.my_module_antecessors.find(params.require(:id)) + render jsonapi: {}, status: :not_found if input.nil? + render jsonapi: input, serializer: MyModuleSerializer + end + private def load_team @@ -45,6 +72,15 @@ module Api @my_module = @experiment.my_modules.find(params.require(:id)) render jsonapi: {}, status: :not_found if @my_module.nil? end + + # Made the method below because its more elegant than changing parameters + # in routes file, and here. It exists because when we call input or output + # for a task, the "id" that used to be task id is now an id for the output + # or input. + def load_task_relative + @my_module = @experiment.my_modules.find(params.require(:task_id)) + render jsonapi: {}, status: :not_found if @my_module.nil? + end end end end diff --git a/app/serializers/api/v1/my_module_antecessors_serializer.rb b/app/serializers/api/v1/my_module_antecessors_serializer.rb deleted file mode 100644 index e69de29bb..000000000 diff --git a/config/routes.rb b/config/routes.rb index 1df86160d..6f43ca63d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -572,17 +572,14 @@ Rails.application.routes.draw do resources :protocols, only: %i(index show), path: 'protocols', as: :protocols - resources :results, only: %i(index show), - path: 'results', - as: :results - resources :my_module_antecessors, only: %i(index show), - path: 'ancestors', - as: :ancestors - resources :my_modules, only: %i(index show), - path: 'descendants', - as: :descendants - # The above two are just my modules (tasks), so im not sure - # if i should duplicate controllers and serializers + get 'inputs', + to: 'my_modules#inputs' + get 'inputs/:id', + to: 'my_modules#input' + get 'outputs', + to: 'my_modules#outputs' + get 'outputs/:id', + to: 'my_modules#output' resources :activities, only: %i(index show), path: 'activities', as: :activities From 837fbaa35f48dabbcf67f331debcedb039649871 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Mon, 10 Sep 2018 15:17:27 +0200 Subject: [PATCH 05/12] Added results endpoint --- app/controllers/api/v1/results_controller.rb | 9 ++++++--- app/serializers/api/v1/result_serializer.rb | 2 +- config/routes.rb | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/results_controller.rb b/app/controllers/api/v1/results_controller.rb index 194116a7c..2d0712fd2 100644 --- a/app/controllers/api/v1/results_controller.rb +++ b/app/controllers/api/v1/results_controller.rb @@ -14,12 +14,15 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: results, - each_serializer: ResultSerializer + render jsonapi: results, include: %w( + result_table result_text result_asset + ), each_serializer: ResultSerializer end def show - render jsonapi: @result, serializer: ResultSerializer + render jsonapi: @result, include: %w( + result_table result_text result_asset + ), serializer: ResultSerializer end private diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index b90f9fa7c..23c3fca3e 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -6,7 +6,7 @@ module Api type :results attributes :id, :name, :my_module_id, :user_id, :created_at, :updated_at, :archived, :archived_on, :last_modified_by_id, :archived_by_id, - :restored_by_id, :restored_on + :restored_by_id, :restored_on, :result_text, :result_table, :result_asset belongs_to :my_module, serializer: MyModuleSerializer end diff --git a/config/routes.rb b/config/routes.rb index 6f43ca63d..58032c0d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -540,7 +540,7 @@ Rails.application.routes.draw do get 'health', to: 'api#health' get 'status', to: 'api#status' post 'auth/token', to: 'api#authenticate' - #if Api.configuration.core_api_v1_preview + if Api.configuration.core_api_v1_preview namespace :v1 do resources :teams, only: %i(index show) do resources :inventories, @@ -572,6 +572,9 @@ Rails.application.routes.draw do resources :protocols, only: %i(index show), path: 'protocols', as: :protocols + resources :results, only: %i(index show), + path: 'results', + as: :results get 'inputs', to: 'my_modules#inputs' get 'inputs/:id', @@ -599,7 +602,7 @@ Rails.application.routes.draw do only: %i(index create show update destroy) end end - #end + end end end end From 6a4801466d7615c3b3be673686c5772e1322f9fc Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Mon, 10 Sep 2018 15:21:45 +0200 Subject: [PATCH 06/12] Fixed serializer types --- app/serializers/api/v1/connection_serializer.rb | 2 +- app/serializers/api/v1/experiment_serializer.rb | 2 +- app/serializers/api/v1/my_module_group_serializer.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/serializers/api/v1/connection_serializer.rb b/app/serializers/api/v1/connection_serializer.rb index da0c2c0b1..ed899b22a 100644 --- a/app/serializers/api/v1/connection_serializer.rb +++ b/app/serializers/api/v1/connection_serializer.rb @@ -3,7 +3,7 @@ module Api module V1 class ConnectionSerializer < ActiveModel::Serializer - type :connection + type :connections attributes :id, :input_id, :output_id end end diff --git a/app/serializers/api/v1/experiment_serializer.rb b/app/serializers/api/v1/experiment_serializer.rb index 0ae510ddc..db9c0dd7e 100644 --- a/app/serializers/api/v1/experiment_serializer.rb +++ b/app/serializers/api/v1/experiment_serializer.rb @@ -3,7 +3,7 @@ module Api module V1 class ExperimentSerializer < ActiveModel::Serializer - type :experiment + type :experiments attributes :id, :name, :description, :project_id, :created_by_id, :archived, :created_at, :updated_at end diff --git a/app/serializers/api/v1/my_module_group_serializer.rb b/app/serializers/api/v1/my_module_group_serializer.rb index 05189b005..0ec8e2dca 100644 --- a/app/serializers/api/v1/my_module_group_serializer.rb +++ b/app/serializers/api/v1/my_module_group_serializer.rb @@ -3,7 +3,7 @@ module Api module V1 class MyModuleGroupSerializer < ActiveModel::Serializer - type :MyModuleGroup + type :task_groups attributes :id, :created_at, :updated_at, :created_by_id, :experiment_id belongs_to :experiment, serializer: ExperimentSerializer end From 87d072537b44c3f326601294f2bbb8e2d135e72c Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Mon, 10 Sep 2018 15:39:50 +0200 Subject: [PATCH 07/12] fixed hound --- app/serializers/api/v1/result_serializer.rb | 3 +- config/routes.rb | 72 ++++++++++----------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index 23c3fca3e..e5cae0ca8 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -6,7 +6,8 @@ module Api type :results attributes :id, :name, :my_module_id, :user_id, :created_at, :updated_at, :archived, :archived_on, :last_modified_by_id, :archived_by_id, - :restored_by_id, :restored_on, :result_text, :result_table, :result_asset + :restored_by_id, :restored_on, :result_text, :result_table, + :result_asset belongs_to :my_module, serializer: MyModuleSerializer end diff --git a/config/routes.rb b/config/routes.rb index 58032c0d1..81a54b31e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -557,44 +557,44 @@ Rails.application.routes.draw do resources :projects, only: %i(index show) do resources :experiments, only: %i(index show) do resources :my_modules, - only: %i(index show), - path: 'tasks', - as: :tasks do - resources :my_module_repository_rows, only: %i(index show), - path: 'task_inventory_rows', - as: :task_inventory_rows - resources :user_my_modules, only: %i(index show), - path: 'user_tasks', - as: :user_tasks - resources :my_module_tags, only: %i(index show), - path: 'task_tags', - as: :task_tags - resources :protocols, only: %i(index show), - path: 'protocols', - as: :protocols - resources :results, only: %i(index show), - path: 'results', - as: :results - get 'inputs', - to: 'my_modules#inputs' - get 'inputs/:id', - to: 'my_modules#input' - get 'outputs', - to: 'my_modules#outputs' - get 'outputs/:id', - to: 'my_modules#output' - resources :activities, only: %i(index show), - path: 'activities', - as: :activities - end + only: %i(index show), + path: 'tasks', + as: :tasks do + resources :my_module_repository_rows, only: %i(index show), + path: 'task_inventory_rows', + as: :task_inventory_rows + resources :user_my_modules, only: %i(index show), + path: 'user_tasks', + as: :user_tasks + resources :my_module_tags, only: %i(index show), + path: 'task_tags', + as: :task_tags + resources :protocols, only: %i(index show), + path: 'protocols', + as: :protocols + resources :results, only: %i(index show), + path: 'results', + as: :results + get 'inputs', + to: 'my_modules#inputs' + get 'inputs/:id', + to: 'my_modules#input' + get 'outputs', + to: 'my_modules#outputs' + get 'outputs/:id', + to: 'my_modules#output' + resources :activities, only: %i(index show), + path: 'activities', + as: :activities + end resources :my_module_groups, - only: %i(index show), - path: 'task_groups', - as: :task_groups + only: %i(index show), + path: 'task_groups', + as: :task_groups resources :connections, - only: %i(index show), - path: 'connections', - as: :connections + only: %i(index show), + path: 'connections', + as: :connections end end resources :users, only: %i(show) do From 0a6ae102cd625bbe660ce000528a7892cce7c1e3 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Mon, 10 Sep 2018 15:53:12 +0200 Subject: [PATCH 08/12] fixes travis again --- config/routes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 81a54b31e..4c3bedc38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -597,10 +597,10 @@ Rails.application.routes.draw do as: :connections end end - resources :users, only: %i(show) do - resources :user_identities, - only: %i(index create show update destroy) - end + end + resources :users, only: %i(show) do + resources :user_identities, + only: %i(index create show update destroy) end end end From c8c0ed62983992546454462a2ccce10f2155a551 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Tue, 11 Sep 2018 10:47:33 +0200 Subject: [PATCH 09/12] standardized serializers by removing specified attributes --- app/serializers/api/v1/activity_serializer.rb | 4 ++-- app/serializers/api/v1/experiment_serializer.rb | 4 ++-- app/serializers/api/v1/my_module_group_serializer.rb | 2 +- .../api/v1/my_module_repository_row_serializer.rb | 4 ++-- app/serializers/api/v1/my_module_tag_serializer.rb | 2 +- app/serializers/api/v1/protocol_serializer.rb | 4 +--- app/serializers/api/v1/result_serializer.rb | 6 ++---- app/serializers/api/v1/user_my_module_serializer.rb | 4 ++-- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/serializers/api/v1/activity_serializer.rb b/app/serializers/api/v1/activity_serializer.rb index 11dee4dc1..70332ce2d 100644 --- a/app/serializers/api/v1/activity_serializer.rb +++ b/app/serializers/api/v1/activity_serializer.rb @@ -4,8 +4,8 @@ module Api module V1 class ActivitySerializer < ActiveModel::Serializer type :activities - attributes :id, :my_module_id, :user_id, :type_of, :message, :created_at, - :updated_at, :project_id, :experiment_id + attributes :id, :my_module_id, :user_id, :type_of, :message, + :project_id, :experiment_id belongs_to :my_module, serializer: MyModuleSerializer end end diff --git a/app/serializers/api/v1/experiment_serializer.rb b/app/serializers/api/v1/experiment_serializer.rb index db9c0dd7e..ae15e44fb 100644 --- a/app/serializers/api/v1/experiment_serializer.rb +++ b/app/serializers/api/v1/experiment_serializer.rb @@ -4,8 +4,8 @@ module Api module V1 class ExperimentSerializer < ActiveModel::Serializer type :experiments - attributes :id, :name, :description, :project_id, :created_by_id, - :archived, :created_at, :updated_at + attributes :id, :name, :description, :created_by_id, :archived + end end end diff --git a/app/serializers/api/v1/my_module_group_serializer.rb b/app/serializers/api/v1/my_module_group_serializer.rb index 0ec8e2dca..4a1d5c46b 100644 --- a/app/serializers/api/v1/my_module_group_serializer.rb +++ b/app/serializers/api/v1/my_module_group_serializer.rb @@ -4,7 +4,7 @@ module Api module V1 class MyModuleGroupSerializer < ActiveModel::Serializer type :task_groups - attributes :id, :created_at, :updated_at, :created_by_id, :experiment_id + attributes :id, :created_by_id, :experiment_id belongs_to :experiment, serializer: ExperimentSerializer 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 db89f7515..abab1d3b5 100644 --- a/app/serializers/api/v1/my_module_repository_row_serializer.rb +++ b/app/serializers/api/v1/my_module_repository_row_serializer.rb @@ -4,8 +4,8 @@ module Api module V1 class MyModuleRepositoryRowSerializer < ActiveModel::Serializer type :task_inventory_rows - attributes :id, :repository_row_id, :my_module_id, :assigned_by_id, - :created_at, :updated_at + attributes :id, :repository_row_id, :my_module_id + belongs_to :my_module, serializer: MyModuleSerializer 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 d395887e7..be94a1641 100644 --- a/app/serializers/api/v1/my_module_tag_serializer.rb +++ b/app/serializers/api/v1/my_module_tag_serializer.rb @@ -4,7 +4,7 @@ module Api module V1 class MyModuleTagSerializer < ActiveModel::Serializer type :task_tags - attributes :id, :my_module_id, :tag_id, :created_by_id + attributes :id, :my_module_id, :tag_id belongs_to :my_module, serializer: MyModuleSerializer end end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 33366de9e..3c4c489ea 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -6,9 +6,7 @@ module Api type :protocols attributes :id, :name, :authors, :description, :added_by_id, :my_module_id, :team_id, :protocol_type, :parent_id, - :parent_updated_at, :archived_by_id, :archived_on, - :restored_by_id, :restored_on, :created_at, :updated_at, - :published_on, :nr_of_linked_children + :nr_of_linked_children belongs_to :my_module, serializer: MyModuleSerializer end end diff --git a/app/serializers/api/v1/result_serializer.rb b/app/serializers/api/v1/result_serializer.rb index e5cae0ca8..0fbe203cd 100644 --- a/app/serializers/api/v1/result_serializer.rb +++ b/app/serializers/api/v1/result_serializer.rb @@ -4,10 +4,8 @@ module Api module V1 class ResultSerializer < ActiveModel::Serializer type :results - attributes :id, :name, :my_module_id, :user_id, :created_at, :updated_at, - :archived, :archived_on, :last_modified_by_id, :archived_by_id, - :restored_by_id, :restored_on, :result_text, :result_table, - :result_asset + attributes :id, :name, :my_module_id, :user_id, :archived, :result_text, + :result_table, :result_asset belongs_to :my_module, serializer: MyModuleSerializer end diff --git a/app/serializers/api/v1/user_my_module_serializer.rb b/app/serializers/api/v1/user_my_module_serializer.rb index cee99d9f3..8425a5d95 100644 --- a/app/serializers/api/v1/user_my_module_serializer.rb +++ b/app/serializers/api/v1/user_my_module_serializer.rb @@ -4,8 +4,8 @@ module Api module V1 class UserMyModuleSerializer < ActiveModel::Serializer type :user_tasks - attributes :id, :user_id, :my_module_id, :created_at, - :updated_at, :assigned_by_id + attributes :id, :user_id, :my_module_id + belongs_to :my_module, serializer: MyModuleSerializer end end From c5300865d6e4e0202c1b97e0556da3570eb6507a Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Tue, 11 Sep 2018 10:49:24 +0200 Subject: [PATCH 10/12] fixed hound --- app/serializers/api/v1/experiment_serializer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/serializers/api/v1/experiment_serializer.rb b/app/serializers/api/v1/experiment_serializer.rb index ae15e44fb..b1ef9023e 100644 --- a/app/serializers/api/v1/experiment_serializer.rb +++ b/app/serializers/api/v1/experiment_serializer.rb @@ -5,7 +5,6 @@ module Api class ExperimentSerializer < ActiveModel::Serializer type :experiments attributes :id, :name, :description, :created_by_id, :archived - end end end From fa54badb9a9ac661a6e8dbfb7378c0863c9389c2 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Tue, 11 Sep 2018 13:06:41 +0200 Subject: [PATCH 11/12] fixed oversight, added paging to connections --- app/controllers/api/v1/connections_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/connections_controller.rb b/app/controllers/api/v1/connections_controller.rb index 740593a32..1ce2111f4 100644 --- a/app/controllers/api/v1/connections_controller.rb +++ b/app/controllers/api/v1/connections_controller.rb @@ -10,6 +10,8 @@ module Api before_action :load_connection, only: :show def index + @connections = @connections.page(params.dig(:page, :number)) + .per(params.dig(:page, :size)) render jsonapi: @connections, each_serializer: ConnectionSerializer end From 98ef3585a3bf15641b8d4e6c4d2cbb0eed0806a3 Mon Sep 17 00:00:00 2001 From: Zanz2 Date: Tue, 11 Sep 2018 15:41:38 +0200 Subject: [PATCH 12/12] removed attributes --- app/serializers/api/v1/experiment_serializer.rb | 2 +- app/serializers/api/v1/my_module_group_serializer.rb | 2 +- app/serializers/api/v1/protocol_serializer.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/serializers/api/v1/experiment_serializer.rb b/app/serializers/api/v1/experiment_serializer.rb index b1ef9023e..bff94ffc1 100644 --- a/app/serializers/api/v1/experiment_serializer.rb +++ b/app/serializers/api/v1/experiment_serializer.rb @@ -4,7 +4,7 @@ module Api module V1 class ExperimentSerializer < ActiveModel::Serializer type :experiments - attributes :id, :name, :description, :created_by_id, :archived + attributes :id, :name, :description, :archived end end end diff --git a/app/serializers/api/v1/my_module_group_serializer.rb b/app/serializers/api/v1/my_module_group_serializer.rb index 4a1d5c46b..06b52e31e 100644 --- a/app/serializers/api/v1/my_module_group_serializer.rb +++ b/app/serializers/api/v1/my_module_group_serializer.rb @@ -4,7 +4,7 @@ module Api module V1 class MyModuleGroupSerializer < ActiveModel::Serializer type :task_groups - attributes :id, :created_by_id, :experiment_id + attributes :id, :experiment_id belongs_to :experiment, serializer: ExperimentSerializer end end diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 3c4c489ea..155ce46ce 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -4,8 +4,8 @@ module Api module V1 class ProtocolSerializer < ActiveModel::Serializer type :protocols - attributes :id, :name, :authors, :description, :added_by_id, - :my_module_id, :team_id, :protocol_type, :parent_id, + attributes :id, :name, :authors, :description, + :my_module_id, :team_id, :protocol_type, :nr_of_linked_children belongs_to :my_module, serializer: MyModuleSerializer end