Add docx and pdf attributes to API report serializer [SCI-5640]

This commit is contained in:
Oleksii Kriuchykhin 2021-06-03 11:40:01 +02:00
parent 44b4e13fa8
commit 960d6681ff

View file

@ -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