-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: display types slot per pokemon
add url to access pokemon details
- Loading branch information
1 parent
b3f8527
commit e59ef2b
Showing
5 changed files
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
class PokemonSerializer < ActiveModel::Serializer | ||
include Rails.application.routes.url_helpers | ||
|
||
attribute :id | ||
attribute :name | ||
attribute :base_experience | ||
attribute :height | ||
attribute :is_default | ||
attribute :order | ||
attribute :weight | ||
attribute :url | ||
|
||
has_many :types do | ||
object.types.map do |type| | ||
TypeSerializer.new(type).serializable_hash.merge( | ||
slot: PokemonType.where(type_id: type.id, pokemon_id: object.id).first.slot | ||
) | ||
end | ||
end | ||
|
||
has_many :types | ||
def url | ||
api_pokemon_show_url(object.id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
class TypeSerializer < ActiveModel::Serializer | ||
attribute :name | ||
attribute :slot | ||
|
||
def slot | ||
object.pokemon_types.slot | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters