2018-09-11 15:13:17 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ReportSerializer < ActiveModel::Serializer
|
2021-06-03 17:40:01 +08:00
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
2018-09-11 15:13:17 +08:00
|
|
|
type :reports
|
2018-10-10 23:35:09 +08:00
|
|
|
attributes :id, :name, :description
|
2021-06-03 17:40:01 +08:00
|
|
|
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? }
|
2018-10-10 23:35:09 +08:00
|
|
|
belongs_to :user, serializer: UserSerializer
|
|
|
|
belongs_to :project, serializer: ProjectSerializer,
|
|
|
|
unless: -> { instance_options[:hide_project] }
|
2021-06-03 17:40:01 +08:00
|
|
|
|
2021-08-18 16:00:01 +08:00
|
|
|
include TimestampableModel
|
|
|
|
|
2021-06-03 17:40:01 +08:00
|
|
|
def pdf_file_size
|
|
|
|
object.pdf_file.blob.byte_size
|
|
|
|
end
|
|
|
|
|
|
|
|
def pdf_file_url
|
2021-10-22 19:48:06 +08:00
|
|
|
object.pdf_file.url if object.pdf_file.attached?
|
2021-06-03 17:40:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def docx_file_size
|
|
|
|
object.docx_file.blob.byte_size
|
|
|
|
end
|
|
|
|
|
|
|
|
def docx_file_url
|
2021-10-22 19:48:06 +08:00
|
|
|
object.docx_file.url if object.docx_file.attached?
|
2021-06-03 17:40:01 +08:00
|
|
|
end
|
2018-09-11 15:13:17 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|