Skip to content

Commit

Permalink
feature: pokemon#index+show routes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienGiboire committed Oct 13, 2021
1 parent 08e64ae commit b3f8527
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/api/pokemons_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Api::PokemonsController < ApplicationController
def index
render json: Pokemon.all, include: ['types']
end

def show
render json: Pokemon.find(params[:id]), include: ['types']
end
end
11 changes: 11 additions & 0 deletions app/serializers/pokemon_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class PokemonSerializer < ActiveModel::Serializer
attribute :id
attribute :name
attribute :base_experience
attribute :height
attribute :is_default
attribute :order
attribute :weight

has_many :types
end
8 changes: 8 additions & 0 deletions app/serializers/type_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class TypeSerializer < ActiveModel::Serializer
attribute :name
attribute :slot

def slot
object.pokemon_types.slot
end
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

Rails.application.routes.draw do
mount Sidekiq::Web => "/sidekiq"

get '/api/pokemons', to: 'api/pokemons#index'
get '/api/pokemons/:id', to: 'api/pokemons#show'
end

0 comments on commit b3f8527

Please sign in to comment.