This commit is contained in:
@@ -84,6 +84,7 @@ class TagsController < ApplicationController
|
||||
Tag
|
||||
.joins(:tag_name)
|
||||
.includes(:tag_name, tag_name: :wiki_page)
|
||||
.where(category: [:meme, :character, :material])
|
||||
.where(id: tag_ids)
|
||||
.order('tag_names.name')
|
||||
.distinct
|
||||
@@ -93,7 +94,12 @@ class TagsController < ApplicationController
|
||||
if tags.empty?
|
||||
[]
|
||||
else
|
||||
TagImplication.where(parent_tag_id: tags.map(&:id)).distinct.pluck(:parent_tag_id)
|
||||
TagImplication
|
||||
.joins(:tag)
|
||||
.where(parent_tag_id: tags.map(&:id),
|
||||
tags: { category: [:meme, :character, :material] })
|
||||
.distinct
|
||||
.pluck(:parent_tag_id)
|
||||
end
|
||||
|
||||
render json: tags.map { |tag|
|
||||
@@ -101,6 +107,18 @@ class TagsController < ApplicationController
|
||||
}
|
||||
end
|
||||
|
||||
def materials_by_name
|
||||
name = params[:name].to_s.strip
|
||||
return head :bad_request if name.blank?
|
||||
|
||||
tag = Tag.joins(:tag_name)
|
||||
.includes(:tag_name, tag_name: :wiki_page)
|
||||
.find_by(tag_names: { name: })
|
||||
return :not_found unless tag
|
||||
|
||||
render json: build_tag_children(tag)
|
||||
end
|
||||
|
||||
def autocomplete
|
||||
q = params[:q].to_s.strip.sub(/\Anot:/i, '')
|
||||
|
||||
@@ -210,4 +228,10 @@ class TagsController < ApplicationController
|
||||
|
||||
render json: TagRepr.base(tag)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_tag_children tag
|
||||
TagRepr.base(tag).merge(children: tag.children.map { build_tag_children(_1) })
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user