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
+9 -8
View File
@@ -2,22 +2,23 @@
module MaterialRepr
BASE = { methods: [:content_type],
include: { created_by_user: UserRepr::BASE,
BASE = { only: [:id, :url, :created_at, :updated_at],
methods: [:content_type],
include: { tag: TagRepr::BASE,
created_by_user: UserRepr::BASE,
updated_by_user: UserRepr::BASE } }.freeze
module_function
def base(material)
def base material, host:
material.as_json(BASE).merge(
file: if material.file.attached?
Rails.application.routes.url_helpers.rails_storage_proxy_url(
material.file, only_path: false)
end,
tag: TagRepr.base(material.tag))
material.file, host:)
end)
end
def many(materials)
materials.map { |m| base(m) }
def many materials, host:
materials.map { |m| base(m, host) }
end
end
+1 -1
View File
@@ -3,7 +3,7 @@
module TagRepr
BASE = { only: [:id, :category, :post_count, :created_at, :updated_at],
methods: [:name, :has_wiki] }.freeze
methods: [:name, :has_wiki, :material_id] }.freeze
module_function