mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-02 05:02:18 +08:00
Add docx and pdf attributes to API report serializer [SCI-5640]
This commit is contained in:
parent
44b4e13fa8
commit
960d6681ff
1 changed files with 22 additions and 0 deletions
|
@ -3,11 +3,33 @@
|
|||
module Api
|
||||
module V1
|
||||
class ReportSerializer < ActiveModel::Serializer
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
type :reports
|
||||
attributes :id, :name, :description
|
||||
attribute :pdf_file_size, if: -> { object.pdf_file.attached? }
|
||||
attribute :pdf_file_url, if: -> { object.pdf_file.attached? }
|
||||
attribute :docx_file_size, if: -> { object.docx_file.attached? }
|
||||
attribute :docx_file_url, if: -> { object.docx_file.attached? }
|
||||
belongs_to :user, serializer: UserSerializer
|
||||
belongs_to :project, serializer: ProjectSerializer,
|
||||
unless: -> { instance_options[:hide_project] }
|
||||
|
||||
def pdf_file_size
|
||||
object.pdf_file.blob.byte_size
|
||||
end
|
||||
|
||||
def pdf_file_url
|
||||
rails_blob_path(object.pdf_file, disposition: 'attachment')
|
||||
end
|
||||
|
||||
def docx_file_size
|
||||
object.docx_file.blob.byte_size
|
||||
end
|
||||
|
||||
def docx_file_url
|
||||
rails_blob_path(object.docx_file, disposition: 'attachment')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue