This commit is contained in:
2026-04-07 00:45:40 +09:00
parent c0d52077b9
commit ff4b0eecf5
12 changed files with 55 additions and 63 deletions
@@ -18,7 +18,7 @@ class MaterialsController < ApplicationController
count = q.count
materials = q.order(created_at: :desc, id: :desc).limit(limit).offset(offset)
render json: { materials: MaterialRepr.many(materials), count: count }
render json: { materials: MaterialRepr.many(materials, host: request.base_url), count: count }
end
def show
@@ -29,7 +29,9 @@ class MaterialsController < ApplicationController
.find_by(id: params[:id])
return head :not_found unless material
render json: MaterialRepr.base(material)
wiki_page_body = material.tag.tag_name.wiki_page&.current_revision&.body
render json: MaterialRepr.base(material, host: request.base_url).merge(wiki_page_body:)
end
def create
@@ -50,7 +52,7 @@ class MaterialsController < ApplicationController
material.file.attach(file)
if material.save
render json: MaterialRepr.base(material), status: :created
render json: MaterialRepr.base(material, host: request.base_url), status: :created
else
render json: { errors: material.errors.full_messages }, status: :unprocessable_entity
end
@@ -80,7 +82,7 @@ class MaterialsController < ApplicationController
end
if material.save
render json: MaterialRepr.base(material)
render json: MaterialRepr.base(material, host: request.base_url)
else
render json: { errors: material.errors.full_messages }, status: :unprocessable_entity
end
+5 -5
View File
@@ -33,7 +33,7 @@ class TagsController < ApplicationController
else
Tag.joins(:tag_name)
end
.includes(:tag_name, tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page, :materials)
q = q.where(posts: { id: post_id }) if post_id.present?
q = q.where('tag_names.name LIKE ?', "%#{ name }%") if name
@@ -83,7 +83,7 @@ class TagsController < ApplicationController
tags =
Tag
.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page, :materials)
.where(category: [:meme, :character, :material])
.where(id: tag_ids)
.order('tag_names.name')
@@ -128,7 +128,7 @@ class TagsController < ApplicationController
end
base = Tag.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page, :materials)
base = base.where('tags.post_count > 0') if present_only
canonical_hit =
@@ -153,7 +153,7 @@ class TagsController < ApplicationController
def show
tag = Tag.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page, :materials)
.find_by(id: params[:id])
if tag
render json: TagRepr.base(tag)
@@ -167,7 +167,7 @@ class TagsController < ApplicationController
return head :bad_request if name.blank?
tag = Tag.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.includes(:tag_name, tag_name: :wiki_page, :materials)
.find_by(tag_names: { name: })
if tag
render json: TagRepr.base(tag)