diff --git a/app/serializers/api/v1/card_serializer.rb b/app/serializers/api/v1/card_serializer.rb index c55b9e6..6f3c9b2 100644 --- a/app/serializers/api/v1/card_serializer.rb +++ b/app/serializers/api/v1/card_serializer.rb @@ -1,7 +1,7 @@ class Api::V1::CardSerializer < Api::V1::BaseSerializer - attributes :id, :character, :rarity, :type, :leader_skill, :passive_skill, + attributes :character, :rarity, :type, :leader_skill, :passive_skill, :super_attack, :awaken_type, :dokkan_card, :links, :title, - :gameid + :gameid, :hp_stat, :atk_stat, :def_stat private @@ -14,34 +14,58 @@ class Api::V1::CardSerializer < Api::V1::BaseSerializer end def character - Api::V1::CharacterSerializer.new(object.character) + object.character.attributes.slice('name').values.first end def rarity - Api::V1::RaritySerializer.new(object.rarity) + object.rarity.attributes.slice('name').values.first end def type - Api::V1::TypeSerializer.new(object.type) + object.type.attributes.slice('name').values.first end def leader_skill - Api::V1::LeaderSkillSerializer.new(object.leader_skill) + if object.leader_skill + object.leader_skill.attributes.slice('description').values.first + end end def passive_skill - Api::V1::PassiveSkillSerializer.new(object.passive_skill) + if object.passive_skill + object.passive_skill.attributes.slice('name', 'description') + end end def super_attack - Api::V1::SuperAttackSerializer.new(object.super_attack) + if object.super_attack + object.super_attack.attributes.slice('name', 'description') + end end def awaken_type - Api::V1::AwakenTypeSerializer.new(object.awaken_type) + object.awaken_type.attributes.slice('name').values.first end def dokkan_card - Api::V1::CardSerializer.new(object.dokkan_card) + Api::V1::CardSerializer.new(object.dokkan_card, root: false) + end + + def hp_stat + stat_formatter(object.hp_stat) + end + + def atk_stat + stat_formatter(object.atk_stat) + end + + def def_stat + stat_formatter(object.def_stat) + end + + private + + def stat_formatter(stat) + stat.attributes.slice('min', 'max', 'awaken_min', 'awaken_max') end end diff --git a/app/serializers/api/v1/link_serializer.rb b/app/serializers/api/v1/link_serializer.rb index 9a5a5c6..3ec16a9 100644 --- a/app/serializers/api/v1/link_serializer.rb +++ b/app/serializers/api/v1/link_serializer.rb @@ -1,3 +1,3 @@ class Api::V1::LinkSerializer < Api::V1::BaseSerializer - attributes :id, :name, :description + attributes :name, :description end