Fix GET /tasks/:task_id/tags, GET /tasks/:task_id/tags/:id endpts

This commit is contained in:
Luka Murn 2018-10-07 11:10:41 +02:00
parent 98544f00e8
commit 24299ef4c0
4 changed files with 26 additions and 29 deletions

View file

@ -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

View file

@ -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

View 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

View file

@ -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