From 98544f00e8c79bf01fe49617320293b9a810a2bd Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 10:20:01 +0200 Subject: [PATCH] Fix GET /tasks/:task_id/users, GET /tasks/:task_id/users/1 endpts --- ..._controller.rb => task_users_controller.rb} | 18 +++++++++--------- .../api/v1/user_my_module_serializer.rb | 13 ------------- config/routes.rb | 6 +++--- 3 files changed, 12 insertions(+), 25 deletions(-) rename app/controllers/api/v1/{user_my_modules_controller.rb => task_users_controller.rb} (70%) delete mode 100644 app/serializers/api/v1/user_my_module_serializer.rb diff --git a/app/controllers/api/v1/user_my_modules_controller.rb b/app/controllers/api/v1/task_users_controller.rb similarity index 70% rename from app/controllers/api/v1/user_my_modules_controller.rb rename to app/controllers/api/v1/task_users_controller.rb index 00c3acdc7..b5d72d826 100644 --- a/app/controllers/api/v1/user_my_modules_controller.rb +++ b/app/controllers/api/v1/task_users_controller.rb @@ -2,24 +2,24 @@ module Api module V1 - class UserMyModulesController < BaseController + class TaskUsersController < BaseController before_action :load_team before_action :load_project before_action :load_experiment before_action :load_task - before_action :load_user_task, only: :show + before_action :load_user, only: :show def index - user_tasks = @my_module.user_my_modules + users = @task.users .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: user_tasks, - each_serializer: UserMyModuleSerializer + render jsonapi: users, + each_serializer: UserSerializer end def show - render jsonapi: @user_task, serializer: UserMyModuleSerializer + render jsonapi: @user, serializer: UserSerializer end private @@ -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_user_task - @user_task = @my_module.user_my_modules.find( + def load_user + @user = @task.users.find( params.require(:id) ) end diff --git a/app/serializers/api/v1/user_my_module_serializer.rb b/app/serializers/api/v1/user_my_module_serializer.rb deleted file mode 100644 index 87edc39ce..000000000 --- a/app/serializers/api/v1/user_my_module_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - class UserMyModuleSerializer < ActiveModel::Serializer - type :user_tasks - attributes :id, :user_id - attribute :my_module_id, key: :task_id - - belongs_to :my_module, serializer: TaskSerializer - end - end -end diff --git a/config/routes.rb b/config/routes.rb index e04963770..abe255714 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -569,9 +569,9 @@ Rails.application.routes.draw do resources :task_inventory_items, only: %i(index show), path: 'items', as: :items - resources :user_my_modules, only: %i(index show), - path: 'user_tasks', - as: :user_tasks + resources :task_users, only: %i(index show), + path: 'users', + as: :users resources :my_module_tags, only: %i(index show), path: 'task_tags', as: :task_tags