mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-11 23:54:43 +08:00
Fix GET /tasks/:task_id/tags, GET /tasks/:task_id/tags/:id endpts
This commit is contained in:
parent
98544f00e8
commit
24299ef4c0
4 changed files with 26 additions and 29 deletions
|
@ -2,24 +2,24 @@
|
|||
|
||||
module Api
|
||||
module V1
|
||||
class MyModuleTagsController < BaseController
|
||||
class TaskTagsController < BaseController
|
||||
before_action :load_team
|
||||
before_action :load_project
|
||||
before_action :load_experiment
|
||||
before_action :load_task
|
||||
before_action :load_task_tag, only: :show
|
||||
before_action :load_tag, only: :show
|
||||
|
||||
def index
|
||||
task_tags = @my_module.my_module_tags
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
tags = @task.tags
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
|
||||
render jsonapi: task_tags,
|
||||
each_serializer: MyModuleTagSerializer
|
||||
render jsonapi: tags,
|
||||
each_serializer: TagSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @task_tag, serializer: MyModuleTagSerializer
|
||||
render jsonapi: @tag, serializer: TagSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -44,15 +44,15 @@ module Api
|
|||
end
|
||||
|
||||
def load_task
|
||||
@my_module = @experiment.my_modules.find(params.require(:task_id))
|
||||
render jsonapi: {}, status: :not_found if @my_module.nil?
|
||||
@task = @experiment.my_modules.find(params.require(:task_id))
|
||||
render jsonapi: {}, status: :not_found if @task.nil?
|
||||
end
|
||||
|
||||
def load_task_tag
|
||||
@task_tag = @my_module.my_module_tags.find(
|
||||
def load_tag
|
||||
@tag = @task.tags.find(
|
||||
params.require(:id)
|
||||
)
|
||||
render jsonapi: {}, status: :not_found if @task_tag.nil?
|
||||
render jsonapi: {}, status: :not_found if @tag.nil?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class MyModuleTagSerializer < ActiveModel::Serializer
|
||||
type :task_tags
|
||||
attributes :id, :tag_id
|
||||
attribute :my_module_id, key: :task_id
|
||||
|
||||
belongs_to :my_module, serializer: TaskSerializer
|
||||
end
|
||||
end
|
||||
end
|
10
app/serializers/api/v1/tag_serializer.rb
Normal file
10
app/serializers/api/v1/tag_serializer.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V1
|
||||
class TagSerializer < ActiveModel::Serializer
|
||||
type :tags
|
||||
attributes :id, :name, :color
|
||||
end
|
||||
end
|
||||
end
|
|
@ -572,9 +572,9 @@ Rails.application.routes.draw do
|
|||
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
|
||||
resources :task_tags, only: %i(index show),
|
||||
path: 'tags',
|
||||
as: :tags
|
||||
resources :protocols, only: %i(index show),
|
||||
path: 'protocols',
|
||||
as: :protocols
|
||||
|
|
Loading…
Add table
Reference in a new issue