2018-09-13 16:37:21 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
class ResultSerializer < ActiveModel::Serializer
|
|
|
|
type :results
|
2023-10-18 16:05:26 +08:00
|
|
|
attributes :name, :archived
|
2018-10-07 18:36:58 +08:00
|
|
|
belongs_to :user, serializer: UserSerializer
|
2023-10-18 16:05:26 +08:00
|
|
|
has_one :result_text, key: :text,
|
|
|
|
serializer: ResultTextSerializer,
|
|
|
|
class_name: 'ResultText' do |serializer|
|
|
|
|
serializer.object.result_texts.first
|
|
|
|
end
|
|
|
|
has_one :result_table, key: :table,
|
|
|
|
serializer: ResultTableSerializer,
|
|
|
|
class_name: 'ResultTable' do |serializer|
|
|
|
|
serializer.object.result_tables.first
|
|
|
|
end
|
|
|
|
has_one :result_asset, key: :file,
|
|
|
|
serializer: ResultAssetSerializer,
|
|
|
|
class_name: 'ResultAsset' do |serializer|
|
|
|
|
serializer.object.result_assets.first
|
|
|
|
end
|
2021-08-18 16:00:01 +08:00
|
|
|
has_many :result_comments, key: :comments, serializer: CommentSerializer
|
2023-08-16 16:37:44 +08:00
|
|
|
has_many :result_orderable_elements, key: :result_elements, serializer: ResultOrderableElementSerializer
|
2021-08-18 16:00:01 +08:00
|
|
|
|
|
|
|
include TimestampableModel
|
2018-09-13 16:37:21 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|