mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 03:59:51 +08:00
Fix GET /tasks/:task_id/users, GET /tasks/:task_id/users/1 endpts
This commit is contained in:
parent
94e80edc9b
commit
98544f00e8
3 changed files with 12 additions and 25 deletions
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue