7b15cb2c5a
#99 #99 #99 #99 #99 #99 #99 #99 #99 #99 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #303
25 lines
654 B
Ruby
25 lines
654 B
Ruby
# frozen_string_literal: true
|
|
|
|
|
|
module MaterialRepr
|
|
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, host:
|
|
material.as_json(BASE).merge(
|
|
file: if material.file.attached?
|
|
Rails.application.routes.url_helpers.rails_storage_proxy_url(
|
|
material.file, host:)
|
|
end)
|
|
end
|
|
|
|
def many materials, host:
|
|
materials.map { |m| base(m, host:) }
|
|
end
|
|
end
|